[infer][eradicate] Fix eradicate tests for field not initialized

Summary:
This test was actually testing: "at least one Field not initialized error is found" where we actualy want to test "exactly one Field not initialized error is found". The case of @Inject was also missing from the tests.
master
jrm 9 years ago
parent 2468139fb7
commit 9e5cee2444

@ -0,0 +1,7 @@
prebuilt_jar(
name = 'jsr-330',
binary_jar = 'javax.inject.jar',
visibility = [
'PUBLIC',
],
)

Binary file not shown.

@ -4,6 +4,7 @@ dependencies = [
'//infer/annotations:annotations',
'//infer/lib/java/android:android',
'//dependencies/java/jsr-305:jsr-305',
'//dependencies/java/jsr-330:jsr-330',
]
java_library(

@ -11,15 +11,19 @@ package codetoanalyze.java.eradicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
public class FieldNotInitialized {
@Nullable
String x;
String y;
@Nonnull
String z; // Means: assume it's initialized to nonnull value somewhere else.
String a;
@Nullable String b;
@Nonnull String c; // Means: assume it will be initialized to a nonnull value somewhere else.
@Inject String d; // Means: assume it will be initialized via dependency injection
// Eradicate should only report one initialization error
FieldNotInitialized() {}
FieldNotInitialized() {
}
}

@ -10,7 +10,7 @@
package endtoend.java.eradicate;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import static utils.matchers.ResultContainsNumberOfErrorsInMethod.containsNumberOfErrors;
import org.junit.BeforeClass;
import org.junit.Test;
@ -39,16 +39,14 @@ public class FieldNotInitializedTest {
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"<init>",
};
assertThat(
"Results should contain " + FIELD_NOT_INITIALIZED,
inferResults,
containsExactly(
containsNumberOfErrors(
FIELD_NOT_INITIALIZED,
SOURCE_FILE,
methods));
"<init>",
1));
}
}

Loading…
Cancel
Save