Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error and polish layout. #237

Merged
merged 1 commit into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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;
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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