├── .gitignore ├── CHANGES.md ├── LICENSE ├── README.md ├── build.gradle ├── buildSrc ├── build.gradle └── settings.gradle ├── circle.yml ├── example-lib ├── .gitignore ├── build.gradle └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── gfx │ │ └── example │ │ └── lib │ │ └── LibraryTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── github │ └── gfx │ └── example │ └── lib │ ├── LibFoo.java │ └── p │ └── LibBar.java ├── example ├── build.gradle └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── gfx │ │ └── android │ │ └── example │ │ ├── AssertTest.java │ │ └── MainActivityTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── gfx │ │ └── android │ │ └── example │ │ ├── Bar.java │ │ ├── Foo.java │ │ ├── MainActivity.java │ │ └── p │ │ └── Baz.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── metadata.gradle ├── plugin ├── build.gradle └── src │ └── main │ ├── groovy │ └── com │ │ └── github │ │ └── gfx │ │ └── android │ │ └── powerassert │ │ ├── Empower.groovy │ │ ├── PowerAssertPlugin.groovy │ │ └── TargetLinesFetcher.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ └── com.github.gfx.android.powerassert.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .idea/* 4 | .DS_Store 5 | build/ 6 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # The revision history of android-power-assert-plugin 2 | 3 | ## v1.5.0 - 2015/12/21 4 | 5 | * Build with Android Gradle Plugin 1.5.0 6 | * Fix crashes when dependencies include `assert` 7 | 8 | ## v0.12.0 - 2014-07-01 08:01:48+0900 9 | 10 | * Build with Android Gradle Plugin 0.12.+ 11 | * Fix line numbers in assertion messages 12 | 13 | ## v0.11.0 - 2014-06-08 08:01:42+0900 14 | 15 | * Build with Android Gradle Plugin 0.11.+ 16 | * No code change from v0.10.8 17 | 18 | ## v0.10.8 - 2014-06-08 07:51:49+0900 19 | 20 | * This is the last version that supports Android Gradle Plugin 0.10.+ 21 | * Fix build errors by specifying the minor version of Android Gradle Plugin 22 | * No code change from v0.10.7 23 | 24 | ## v0.10.7 - 2014-06-03 08:06:13+0900 25 | 26 | * Fix a compilation error in abstract methods 27 | 28 | ## v0.10.6 - 2014-05-22 22:46:02+0900 29 | 30 | * Fix a runtime NPE in injected code (#8) 31 | * Fix a compilation error in library projects (#9) 32 | 33 | ## v0.10.5 - 2014-05-22 08:26:40+0900 34 | 35 | * Fix compilation errors 36 | 37 | ## v0.10.4 - 2014-05-18 20:11:17+0900 38 | 39 | * No feature changes 40 | * Revise logging; POWERASSERT_VERBOSE=1 is recommended in CI 41 | in order to show how this plugin spend time 42 | 43 | ## v0.10.3 - 2014-05-13 09:11:19+0900 44 | 45 | * Fix a lot of compilation problems 46 | 47 | ## v0.10.2 - 2014-05-11 23:01:17+0900 48 | 49 | * Embed source lines in assertion messages 50 | * Support `android-library` modules 51 | 52 | ## v0.10.1 - 2014-05-10 18:10:29+0900 53 | 54 | * Fix IllegalAccessError in androidTest 55 | 56 | ## v0.10.0 - 2014-05-10 12:00:00+0900 57 | 58 | * Initial Release 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 FUJI Goro (gfx) . 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Power Assert for Android [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.gfx.android.powerassert/plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.gfx.android.powerassert/plugin) [![Circle CI](https://circleci.com/gh/gfx/android-power-assert-plugin.svg?style=svg&branch=master)](https://circleci.com/gh/gfx/android-power-assert-plugin) 2 | 3 | **Power Assert** is a language extension which adds extra information when assertions fail. 4 | This feature has been invented in Groovy and being spread around other programming languages, 5 | and is becoming a fundamental feature for debugging and testing, especially in unit tests: you 6 | no longer need to learn a bunch of test matchers such as 7 | [assertEquals()](http://developer.android.com/reference/junit/framework/Assert.html). 8 | 9 | This is a Gradle plugin to provide Android with power asserts by modifying Java class files 10 | in compilation phases. To use power assert, all you have to do is to depend on 11 | `android-power-assert-plugin` and apply `android-power-assert` plugin in `build.gradle`, 12 | which automatically enables `assert` statements unless you makes `release` build. Thus you can use 13 | [assert statements](http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html) 14 | both in applications and unit tests. 15 | 16 | # Usage 17 | 18 | This plugin uses `assert` statements in Java by applying this plugin in `build.gradle`. 19 | 20 | ```groovy 21 | // in the root build.gradle 22 | buildscript { 23 | repositories { 24 | mavenCentral() // or jcenter() 25 | } 26 | dependencies { 27 | classpath 'com.android.tools.build:gradle:1.5.2' 28 | classpath 'com.github.gfx.android.powerassert:plugin:1.5.2' 29 | } 30 | } 31 | ``` 32 | 33 | ```groovy 34 | // in a build.gradle of a module 35 | apply plugin: 'android' 36 | apply plugin: 'com.github.gfx.android.powerassert' 37 | ``` 38 | 39 | Then, use `assert` in your program: 40 | 41 | ```java 42 | // in example's MainActivity.java 43 | void onButton2Click() { 44 | assert findViewById(android.R.id.list).getVisibility() == View.VISIBLE; 45 | } 46 | ``` 47 | 48 | This shows the following output when `findViewById()` returns null: 49 | 50 | ``` 51 | java.lang.NullPointerException: 52 | 25: void onButton2Click() { 53 | 26> assert findViewById(android.R.id.list).getVisibility() == View.VISIBLE; 54 | 26: } 55 | com.github.gfx.powerassert.example.MainActivity.findViewById()= 56 | (...stacktrace...) 57 | ``` 58 | 59 | # Logging 60 | 61 | `POWERASSERT_VERBOSE=1` shows debug logs including how the plugin spends time in bytecode modification. 62 | 63 | `POWERASSERT_VERBOSE=2` shows all the extra source code so it might be useful to debug this plugin. 64 | 65 | # Compatibility 66 | 67 | The minor version of this plugin should match with the minor version of Android Gradle Plugin. 68 | 69 | That is, android-power-assert-plugin v0.10.x is compatible with Android Gradle Plugin v0.10.x, 70 | as well as android-power-assert-plugin v1.1.x is compatible with Android Gradle Plugin v1.1.x. 71 | 72 | # Author And License 73 | 74 | Copyright 2014, FUJI Goro (gfx) . All rights reserved. 75 | 76 | This library may be copied only under the terms of the MIT License. 77 | 78 | # See Also 79 | 80 | - [Groovy 1.7 Power Assert (Posted on December 11, 2009)](https://dontmindthelanguage.wordpress.com/2009/12/11/groovy-1-7-power-assert/) 81 | - [Power Assert in JavaScript](https://github.com/power-assert-js/power-assert) 82 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: './metadata.gradle' 3 | 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | task('uploadArchives') { 19 | description = "upload artifacts '${GROUP_ID}:${ARTIFACT_ID}:${VERSION}'" 20 | } 21 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | jcenter() 3 | } 4 | 5 | dependencies { 6 | compile project(':plugin') 7 | } 8 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':plugin' 2 | project(':plugin').projectDir = new File('../plugin') 3 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | java: 3 | version: oraclejdk8 4 | environment: 5 | GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx1560m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false' 6 | JAVA_OPTS: '-Xmx1560m -XX:+HeapDumpOnOutOfMemoryError' 7 | dependencies: 8 | pre: 9 | - sudo service postgresql stop 10 | - sudo service mongodb stop 11 | - sudo service memcached stop 12 | - sudo service mysql stop 13 | - sudo service couchdb stop 14 | - sudo service rabbitmq-server stop 15 | - sudo service zookeeper stop 16 | - echo y | android -s update sdk -u -a -t "tools" 17 | - echo y | android -s update sdk -u -a -t "platform-tools" 18 | - echo y | android -s update sdk -u -a -t "extra-android-m2repository" 19 | - mkdir -p "$ANDROID_HOME"/licenses 20 | - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME"/licenses/android-sdk-license 21 | test: 22 | override: 23 | - TERM=dumb ./gradlew check 24 | -------------------------------------------------------------------------------- /example-lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /example-lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.gfx.android.powerassert' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "24.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | compileOptions { 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | targetCompatibility JavaVersion.VERSION_1_7 17 | } 18 | } 19 | 20 | dependencies { 21 | compile 'com.android.support:appcompat-v7:24.2.1' 22 | } 23 | -------------------------------------------------------------------------------- /example-lib/src/androidTest/java/com/github/gfx/example/lib/LibraryTest.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.example.lib; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | import com.github.gfx.example.lib.p.LibBar; 6 | 7 | @SuppressWarnings("Assert") 8 | public class LibraryTest extends AndroidTestCase { 9 | public void testAssertInLibs() throws Exception { 10 | try { 11 | LibFoo.f(false); 12 | fail("not reached"); 13 | } catch (AssertionError e) { 14 | assert e.getMessage().contains("expr"); 15 | } 16 | } 17 | 18 | public void testAssertInTests() throws Exception { 19 | try { 20 | assert false : "foo"; 21 | fail("not reached"); 22 | } catch (AssertionError e) { 23 | assertTrue(e.getMessage().contains("foo")); 24 | } 25 | } 26 | 27 | public void testAssertInAnotherPackage() throws Exception { 28 | try { 29 | LibBar.f(false); 30 | fail("not reached"); 31 | } catch (AssertionError e) { 32 | assert e.getMessage().contains("expr"); 33 | } 34 | } 35 | 36 | public void testAssertInAnotherClassInAnotherPackage() throws Exception { 37 | try { 38 | assert new LibBar().g(false); 39 | fail("not reached"); 40 | } catch (AssertionError e) { 41 | assertTrue(e.getMessage().contains("LibBar")); 42 | } 43 | } 44 | 45 | public void testRefToObjectInLibrary() throws Exception { 46 | try { 47 | assert LibFoo.g("bar"); 48 | } 49 | catch (AssertionError e) { 50 | assert e.getMessage().contains("LibFoo"); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example-lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /example-lib/src/main/java/com/github/gfx/example/lib/LibFoo.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.example.lib; 2 | 3 | public class LibFoo { 4 | public static void f(boolean expr) { 5 | assert expr; 6 | } 7 | 8 | public static boolean g(String s) { 9 | assert s != null; 10 | return s.contains("foo"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example-lib/src/main/java/com/github/gfx/example/lib/p/LibBar.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.example.lib.p; 2 | 3 | public class LibBar { 4 | public static void f(boolean expr) { 5 | assert false; 6 | } 7 | 8 | public boolean g(boolean expr) { 9 | return expr; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.github.gfx.android.powerassert' 3 | 4 | //com.github.gfx.powerassert.PowerAssertPlugin.setEmpower(false) 5 | 6 | android { 7 | compileSdkVersion 24 8 | buildToolsVersion "24.0.3" 9 | 10 | defaultConfig { 11 | minSdkVersion 15 12 | targetSdkVersion 23 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | 17 | compileOptions { 18 | sourceCompatibility JavaVersion.VERSION_1_7 19 | targetCompatibility JavaVersion.VERSION_1_7 20 | } 21 | 22 | productFlavors { 23 | free {} 24 | premium {} 25 | } 26 | } 27 | 28 | 29 | dependencies { 30 | compile 'com.jakewharton:butterknife:7.0.0' 31 | compile 'com.android.support:appcompat-v7:24.2.1' 32 | } 33 | -------------------------------------------------------------------------------- /example/src/androidTest/java/com/github/gfx/android/example/AssertTest.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example; 2 | 3 | import android.test.AndroidTestCase; 4 | 5 | import com.github.gfx.android.example.p.Baz; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class AssertTest extends AndroidTestCase { 11 | public void testAssert() throws Exception { 12 | try { 13 | int num = 42 + hashCode(); 14 | assert num == 20; 15 | fail("not reached"); 16 | } catch (AssertionError e) { 17 | assertTrue(e.getMessage().contains("num")); 18 | assertTrue(e.getMessage().contains("42")); 19 | } 20 | } 21 | 22 | public void testAssertEnabledInAppClasses() throws Exception { 23 | try { 24 | Foo.f(false); 25 | fail("not reached"); 26 | } catch (AssertionError e) { 27 | assertTrue(e.getMessage().contains("false")); 28 | } 29 | } 30 | 31 | public void testAssertEnabledInAppClasses_causedIllegalAccessError() throws Exception { 32 | try { 33 | Foo.g(false); 34 | fail("not reached"); 35 | } catch (AssertionError e) { 36 | assertTrue(e.getMessage().contains("false")); 37 | } 38 | } 39 | 40 | public void testAssertWithMessage() throws Exception { 41 | try { 42 | assert false : "assert message here"; 43 | fail("not reached"); 44 | } catch (AssertionError e) { 45 | assertTrue(e.getMessage().contains("assert message here")); 46 | } 47 | } 48 | 49 | public void testLocalVariables() throws Exception { 50 | { 51 | String foo = "bar"; 52 | assertNotNull(foo); 53 | } 54 | 55 | try { 56 | assert false; 57 | fail("not reached"); 58 | } catch (AssertionError e) { 59 | assertFalse(e.getMessage().contains("foo")); 60 | assertFalse(e.getMessage().contains("bar")); 61 | } 62 | } 63 | 64 | class KV { 65 | K key; 66 | V value; 67 | 68 | KV(K key, V value) { 69 | this.key = key; 70 | this.value = value; 71 | } 72 | 73 | 74 | public K getKey() { 75 | return key; 76 | } 77 | 78 | public V getValue() { 79 | return value; 80 | } 81 | } 82 | 83 | class HasKV { 84 | KV entry; 85 | 86 | HasKV(KV entry) { 87 | this.entry = entry; 88 | } 89 | } 90 | 91 | public void testFieldAccess() throws Exception { 92 | try { 93 | HasKV second = new HasKV(new KV<>("foo\n", "bar\n")); 94 | 95 | assert second.entry.key.equals("foo\n"); 96 | assert second.entry.value.equals("zzz"); 97 | fail("not reached"); 98 | } catch (AssertionError e) { 99 | assert e.getMessage().contains("value=\"bar\\n\""); 100 | } 101 | } 102 | 103 | public void testNPE() throws Exception { 104 | try { 105 | HasKV second = new HasKV(null); 106 | 107 | assert second.entry.key.equals("foo"); 108 | fail("not reached"); 109 | } catch (RuntimeException e) { 110 | assert e.getMessage().contains("AssertTest$HasKV.entry="); 111 | } 112 | } 113 | 114 | public void testMethodCall() throws Exception { 115 | try { 116 | HasKV second = new HasKV(new KV<>("foo\n", "bar\n")); 117 | 118 | assert second.entry.getKey().equals("foo\n"); 119 | assert second.entry.getValue().equals("zzz"); 120 | fail("not reached"); 121 | } catch (AssertionError e) { 122 | assert e.getMessage().contains("getValue()=\"bar\\n\""); 123 | } 124 | } 125 | 126 | public void testTargetSource() throws Exception { 127 | try { 128 | assert false : "Hello, world!"; 129 | fail("not reached"); 130 | } catch (AssertionError e) { 131 | assert e.getMessage().contains("assert false : \"Hello, world!\";"); 132 | } 133 | } 134 | 135 | public void testIntArrayVariables() throws Exception { 136 | try { 137 | int[] array = {10, 20, 30}; 138 | assert array.length == 0; 139 | fail("not reached"); 140 | } catch (AssertionError e) { 141 | assert e.getMessage().contains("10"); 142 | assert e.getMessage().contains("20"); 143 | assert e.getMessage().contains("30"); 144 | } 145 | } 146 | 147 | public void testStringArrayVariables() throws Exception { 148 | try { 149 | String[] array = {"10", "20", "30"}; 150 | assert array.length == 0; 151 | fail("not reached"); 152 | } catch (AssertionError e) { 153 | assert e.getMessage().contains("10"); 154 | assert e.getMessage().contains("20"); 155 | assert e.getMessage().contains("30"); 156 | } 157 | } 158 | 159 | public void testAssertInAnotherPackage() throws Exception { 160 | try { 161 | Baz.f(false); 162 | fail("not reached"); 163 | } catch (AssertionError e) { 164 | assert e.getMessage().contains("expr"); 165 | } 166 | } 167 | 168 | public void testAssertInAnotherClassInAnotherPackage() throws Exception { 169 | try { 170 | assert new Baz().g(false); 171 | fail("not reached"); 172 | } catch (AssertionError e) { 173 | assert e.getMessage().contains("Baz"); 174 | } 175 | } 176 | 177 | 178 | public void testWithAnonClass() throws Exception { 179 | final int value = 42 + this.hashCode(); 180 | 181 | Runnable runnable = new Runnable() { 182 | @Override 183 | public void run() { 184 | assert value == 0; 185 | } 186 | }; 187 | 188 | try { 189 | runnable.run(); 190 | } catch (AssertionError e) { 191 | assertTrue(e.getMessage().contains("value")); 192 | } 193 | } 194 | 195 | public void testNullObject() throws Exception { 196 | List list = getSomething(); 197 | assert list.get(0) == null; 198 | } 199 | 200 | private List getSomething() { 201 | List list = new ArrayList<>(); 202 | list.add(null); 203 | return list; 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /example/src/androidTest/java/com/github/gfx/android/example/MainActivityTest.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example; 2 | 3 | import android.content.Intent; 4 | import android.test.ActivityUnitTestCase; 5 | 6 | public class MainActivityTest extends ActivityUnitTestCase { 7 | public MainActivityTest() { 8 | super(MainActivity.class); 9 | } 10 | 11 | @Override 12 | public void setUp() throws Exception { 13 | super.setUp(); 14 | 15 | Intent intent = new Intent(getInstrumentation().getContext(), MainActivity.class); 16 | startActivity(intent, null, null); 17 | } 18 | 19 | public void testButton1Click() throws Exception { 20 | try { 21 | getActivity().onButton1Click(); 22 | fail("not reached"); 23 | } catch (AssertionError e) { 24 | assert e.getMessage().contains("assert"); 25 | } 26 | } 27 | 28 | public void testButton2Click() throws Exception { 29 | try { 30 | getActivity().onButton2Click(); 31 | assert false : "not reached"; 32 | fail("not reached"); 33 | } catch (NullPointerException e) { 34 | assert e.getMessage().contains("assert"); 35 | } 36 | } 37 | 38 | public void testButton3Click() throws Exception { 39 | try { 40 | getActivity().onButton3Click(); 41 | fail("not reached"); 42 | } catch (AssertionError e) { 43 | assert e.getMessage().contains("assert"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/src/main/java/com/github/gfx/android/example/Bar.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example; 2 | 3 | public abstract class Bar { 4 | public boolean value; 5 | 6 | public Bar(boolean value) { 7 | this.value = value; 8 | } 9 | 10 | abstract void f(); 11 | 12 | void g() { 13 | assert false; 14 | } 15 | } -------------------------------------------------------------------------------- /example/src/main/java/com/github/gfx/android/example/Foo.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example; 2 | 3 | public class Foo { 4 | private boolean bar = false; 5 | 6 | private static Foo instance = new Foo(false); 7 | 8 | public Foo(boolean value) { 9 | this.bar = value; 10 | } 11 | 12 | public static void f(boolean expr) { 13 | assert expr : "expects expr to be true"; 14 | } 15 | 16 | public static void g(boolean expr) { 17 | assert instance.bar; 18 | } 19 | } -------------------------------------------------------------------------------- /example/src/main/java/com/github/gfx/android/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.LayoutInflater; 6 | 7 | import butterknife.ButterKnife; 8 | import butterknife.OnClick; 9 | 10 | public class MainActivity extends Activity { 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main); 15 | 16 | ButterKnife.bind(this); 17 | } 18 | 19 | @OnClick(R.id.button1) 20 | void onButton1Click() { 21 | Foo.f(false); 22 | } 23 | 24 | @OnClick(R.id.button2) 25 | void onButton2Click() { 26 | assert findViewById(R.id.never).isFocused(); 27 | } 28 | 29 | @OnClick(R.id.button3) 30 | void onButton3Click() { 31 | assert new Function() { 32 | @Override 33 | public Boolean call(LayoutInflater arg) { 34 | return arg.getContext() == null; 35 | } 36 | }.call(getLayoutInflater()) : "complex assertions"; 37 | } 38 | 39 | interface Function { 40 | ResultT call(ArgT arg); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/src/main/java/com/github/gfx/android/example/p/Baz.java: -------------------------------------------------------------------------------- 1 | package com.github.gfx.android.example.p; 2 | 3 | public class Baz { 4 | public static void f(boolean expr) { 5 | assert expr; 6 | } 7 | 8 | public boolean g(boolean expr) { 9 | return expr; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfx/android-power-assert-plugin/1970ac89a0e36bf0337c4ec86c2065019afc0eec/example/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfx/android-power-assert-plugin/1970ac89a0e36bf0337c4ec86c2065019afc0eec/example/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfx/android-power-assert-plugin/1970ac89a0e36bf0337c4ec86c2065019afc0eec/example/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gfx/android-power-assert-plugin/1970ac89a0e36bf0337c4ec86c2065019afc0eec/example/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 18 | 19 |