GCX-HCI / ThirtyInch

a MVP library for Android favoring a stateful Presenter
Apache License 2.0
1.03k stars 101 forks source link

Use assertJ everywhere #121

Closed StefMa closed 7 years ago

StefMa commented 7 years ago

Currently we have "hundreds" of different "test matchers".

Each test look different. Which is bad.

We should use assertJ everywhere and get rid of the other matcher libs. To prevent using Hamcrest in the future it would be great if we can exclude it from... Don't know which dependency has hamcrest as dependency. But we have to found out it and exclude it form them if possible.

passsy commented 7 years ago

This is a very good task for Hacktoberfest! I'm not sure if we can exclude it. You can get the dependnecies tree with ./gradlew :thirtyinch:dependnecies

lunaticmonk commented 7 years ago

@StefMa We just need to replace 'assertEquals' and 'assertThat' by 'assertJ' right? Or anything else needs to be done?

StefMa commented 7 years ago

Exactly. But assertJ isn't a method 🙃. From both, hamcrest and assertJ, the matches are assertThat

vpondala commented 7 years ago

I am working on this.

StefMa commented 7 years ago

128 has merged and we are now using assertJ everywhere.

But it hasn't removed hamcrest as dependency.

It is still open which dependency brings hamcrest build in.

passsy commented 7 years ago
+--- junit:junit:4.12
|    \--- org.hamcrest:hamcrest-core:1.3
./gradlew :thirtyinch:dependencies _debugUnitTestCompile - ## Internal use, do not manually configure ## +--- com.android.support:appcompat-v7:26.0.0 | +--- com.android.support:support-annotations:26.0.0 | +--- com.android.support:support-v4:26.0.0 | | +--- com.android.support:support-compat:26.0.0 | | | \--- com.android.support:support-annotations:26.0.0 | | +--- com.android.support:support-media-compat:26.0.0 | | | +--- com.android.support:support-annotations:26.0.0 | | | \--- com.android.support:support-compat:26.0.0 (*) | | +--- com.android.support:support-core-utils:26.0.0 | | | +--- com.android.support:support-annotations:26.0.0 | | | \--- com.android.support:support-compat:26.0.0 (*) | | +--- com.android.support:support-core-ui:26.0.0 | | | +--- com.android.support:support-annotations:26.0.0 | | | \--- com.android.support:support-compat:26.0.0 (*) | | \--- com.android.support:support-fragment:26.0.0 | | +--- com.android.support:support-compat:26.0.0 (*) | | +--- com.android.support:support-core-ui:26.0.0 (*) | | \--- com.android.support:support-core-utils:26.0.0 (*) | +--- com.android.support:support-vector-drawable:26.0.0 | | +--- com.android.support:support-annotations:26.0.0 | | \--- com.android.support:support-compat:26.0.0 (*) | \--- com.android.support:animated-vector-drawable:26.0.0 | +--- com.android.support:support-vector-drawable:26.0.0 (*) | \--- com.android.support:support-core-ui:26.0.0 (*) +--- junit:junit:4.12 | \--- org.hamcrest:hamcrest-core:1.3 +--- org.mockito:mockito-core:2.10.0 | +--- net.bytebuddy:byte-buddy:1.7.4 | +--- net.bytebuddy:byte-buddy-agent:1.7.4 | \--- org.objenesis:objenesis:2.6 \--- org.assertj:assertj-core:2.8.0
passsy commented 7 years ago

I tried to remove it

    testCompile ("junit:junit:$junitVersion") {
        exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }

Results in

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 26 more

It's not possible. https://github.com/junit-team/junit4/issues/165