class file for java.nio.file.Path not found
Asked Answered
C

2

8

I'm using org.assertj:assertj-core:3.6.2 to test my android project. According offical ducoment, I should use java 8 with assertj 3.x.

Here is my test class, I'm trying to verify when the click performed the code can start expected activity.

import android.content.Intent;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class LoginActivityTest {

    @Test
    public void testBtnLogin(){
        LoginActivity loginActivity = Robolectric.setupActivity(LoginActivity.class);

        loginActivity.findViewById(R.id.btnLogin)
                .performClick();

        Intent expectedIntent = new Intent(loginActivity,MainActivity.class);
        ShadowActivity shadowActivity = Shadows.shadowOf(loginActivity);
        Intent actualIntent = shadowActivity.getNextStartedActivity();
        Assertions.assertThat(actualIntent).isEqualTo(expectedIntent);
    }
}

But when I run test, I got this error:

:app:compileDebugUnitTestJavaWithJavac (Thread[Daemon worker,5,main]) started.
:app:compileDebugUnitTestJavaWithJavac
file or directory '/home/workspace/android/AndroidLib/app/src/testDebug/java', not found
Executing task ':app:compileDebugUnitTestJavaWithJavac' (up-to-date check took 0.006 secs) due to:
  Output file /home/workspace/android/AndroidLib/app/build/intermediates/classes/test/debug/com/cavalry/androidlib/sample/ui/activity/LoginActivityTest.class has been removed.
All input files are considered out-of-date for incremental task ':app:compileDebugUnitTestJavaWithJavac'.
Compiling with source level 1.7 and target level 1.7.
file or directory '/home/workspace/android/AndroidLib/app/src/testDebug/java', not found
Compiling with JDK Java compiler API.

/home/workspace/android/AndroidLib/app/src/test/java/com/cavalry/androidlib/sample/ui/activity/LoginActivityTest.java:43: error: cannot access Path
        Assertions.assertThat(actualIntent).isEqualTo(expectedIntent);
                  ^
  class file for java.nio.file.Path not found
1 error

:app:compileDebugUnitTestJavaWithJavac FAILED
:app:compileDebugUnitTestJavaWithJavac (Thread[Daemon worker,5,main]) completed. Took 0.556 secs.

I searched on google and found it might cause by the wrong version of java( I'm really really not sure about that).

Here is some information about my java config:

$ java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

$ javac -version
javac 1.8.0_112


$ update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /home/java/jdk1.8.0_112/bin/java                 300       manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

And in project structure, I alse set JDK to jdk1.8.0_112 enter image description here

If it was caused by the version of java, what should I do? If not, then what should I do ?

Cantor answered 22/1, 2017 at 5:45 Comment(2)
On Android use this static import : import static org.assertj.core.api.Java6Assertions.*; joel-costigliola.github.io/assertj/…Olden
This is a compilation error. It didn't happen when you ran the test.Alisonalissa
A
4

ejohansson is right, it might not be super visible but org.assertj.core.api.Java6Assertions is mentioned in http://joel-costigliola.github.io/assertj/assertj-core.html, I'll try to make it clearer in the future (https://github.com/joel-costigliola/assertj/issues/63).

Documentation has been updated, hopefully it will be easier for android developers to find the correct assertions entry point: http://joel-costigliola.github.io/assertj/assertj-core.html#android

Acarid answered 22/1, 2017 at 20:30 Comment(1)
Oh, It's my fault, I didn't read over the One minute starting guide, Thank you !Cantor
P
0

With Android Studio, it's probably a good idea to exclude org.assertj.core.api.Assertions from auto-import, so it doesn't happen in the future, after you forget about it:

  1. Remove the static import for a moment.
  2. Hit F2 to navigate to the problematic assert.
  3. Hit Alt+Enter to show the list of available intention actions.
  4. Highlight the entry for Assertions (org.assertj.core.api) and hit .
  5. Select Exclude 'org.assertj.core.api.Assertions' from auto-import on the list that just popped up.
Peon answered 21/7, 2017 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.