Skip to content

Commit

Permalink
Merge pull request #237 from hotchemi/fix_test
Browse files Browse the repository at this point in the history
Fix compile error and polish layout.
  • Loading branch information
hotchemi committed Dec 13, 2016
2 parents 2a3694f + 09096c4 commit 71ee440
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
Expand Up @@ -6,11 +6,11 @@

public abstract class BaseLintDetectorTest extends LintDetectorTest {

protected static final String PACKAGE = "package permissions.dispatcher;\n";
static final String PACKAGE = "package permissions.dispatcher;\n";

protected static final String SOURCE_PATH = "src/permissions/dispatcher/";
static final String SOURCE_PATH = "src/permissions/dispatcher/";

protected String getOnNeedsPermission() {
String getOnNeedsPermission() {
@Language("JAVA") String onNeedsPermission = ""
+ PACKAGE
+ "import java.lang.annotation.ElementType;\n"
Expand All @@ -26,7 +26,7 @@ protected String getOnNeedsPermission() {
return onNeedsPermission;
}

protected String getOnRationaleAnnotation() {
String getOnRationaleAnnotation() {
@Language("JAVA") String onShow = ""
+ PACKAGE
+ "import java.lang.annotation.ElementType;\n"
Expand All @@ -40,4 +40,9 @@ protected String getOnRationaleAnnotation() {
+ "}";
return onShow;
}

@Override
protected boolean allowCompilationErrors() {
return true;
}
}
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.ImmutableList;

import com.android.tools.lint.checks.infrastructure.LintDetectorTest;
import com.android.tools.lint.detector.api.Detector;
import com.android.tools.lint.detector.api.Issue;

Expand All @@ -12,11 +11,10 @@
import java.util.Collections;
import java.util.List;

public class CallNeedsPermissionDetectorTest extends LintDetectorTest {
public class CallNeedsPermissionDetectorTest extends BaseLintDetectorTest {

private static final String NO_WARNINGS = "No warnings.";


@Override
protected Detector getDetector() {
return new CallNeedsPermissionDetector();
Expand Down Expand Up @@ -60,7 +58,7 @@ public void testCallNeedsPermissionMethod() throws Exception {
+ "~~~~~~~~~~~~\n"
+ "1 errors, 0 warnings\n";

assertEquals(result, error.toString());
assertEquals(result, error);
}

@Test
Expand All @@ -83,8 +81,8 @@ public void testCallNeedsPermissionMethodNoError() throws Exception {
+ "}";

String result = lintProject(
java("src/com/example/Foo.java", foo.toString()),
java("src/com/example/Baz.java", baz.toString()));
java("src/com/example/Foo.java", foo),
java("src/com/example/Baz.java", baz));

assertEquals(result, NO_WARNINGS);
}
Expand Down
Expand Up @@ -10,9 +10,6 @@

import java.util.List;

/**
* @author Henry Addo
*/
public class CallOnRequestPermissionsResultDetectorTest extends BaseLintDetectorTest {

@Override
Expand All @@ -23,7 +20,6 @@ protected Detector getDetector() {
@Override
protected List<Issue> getIssues() {
return ImmutableList.of(CallOnRequestPermissionsResultDetector.ISSUE);

}

@Test
Expand Down Expand Up @@ -73,11 +69,11 @@ public void testCallOnRequestPermissionsResultDetectorNoError() throws Exception
@Test
public void testCallOnRequestPermissionsResultDetector() throws Exception {

String runtimePerms = getRuntimePermission();
@Language("JAVA") String runtimePerms = getRuntimePermission();

String onNeeds = getOnNeedsPermission();
@Language("JAVA") String onNeeds = getOnNeedsPermission();

String onShow = getOnRationaleAnnotation();
@Language("JAVA") String onShow = getOnRationaleAnnotation();

@Language("JAVA") String foo = ""
+ "package permissions.dispatcher;\n"
Expand All @@ -94,8 +90,7 @@ public void testCallOnRequestPermissionsResultDetector() throws Exception {
+ "}";

String result = lintProject(
java(SOURCE_PATH + "RuntimePermissions.java",
runtimePerms.toString()),
java(SOURCE_PATH + "RuntimePermissions.java", runtimePerms),
java(SOURCE_PATH + "NeedsPermission.java", onNeeds),
java(SOURCE_PATH + "OnShowRationale.java", onShow),
java(SOURCE_PATH + "Foo.java", foo));
Expand Down
Expand Up @@ -24,8 +24,8 @@ protected List<Issue> getIssues() {

@Test
public void testNoNeedsPermissionAnnotationNoErrors() throws Exception {
String onNeeds = getOnNeedsPermission();
String onShow = getOnRationaleAnnotation();
@Language("JAVA") String onNeeds = getOnNeedsPermission();
@Language("JAVA") String onShow = getOnRationaleAnnotation();
@Language("JAVA") String foo = ""
+ PACKAGE
+ "public class Foo {\n"
Expand All @@ -48,7 +48,7 @@ public void testNoNeedsPermissionAnnotationNoErrors() throws Exception {
@Test
public void testNoNeedsPermissionAnnotation() throws Exception {

String onShow = getOnRationaleAnnotation();
@Language("JAVA") String onShow = getOnRationaleAnnotation();

@Language("JAVA") String foo = ""
+ PACKAGE
Expand Down

0 comments on commit 71ee440

Please sign in to comment.