Skip to content

Commit

Permalink
Add test cases for the change.
Browse files Browse the repository at this point in the history
  • Loading branch information
hotchemi committed Dec 2, 2018
1 parent 2c011d8 commit 8a0fa29
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package permissions.dispatcher.processor.exception

class SpecialPermissionsWithNeverAskAgainException : RuntimeException("@NeverAskAgain annotated method never being called with WRITE_SETTINGS or SYSTEM_ALERT_WINDOW permission.")
class SpecialPermissionsWithNeverAskAgainException : RuntimeException("'@NeverAskAgain' annotated method never being called with 'WRITE_SETTINGS' or 'SYSTEM_ALERT_WINDOW' permission.")
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public class ProcessorTestSuite extends TestSuite {
assertJavaSource(Source.needsPermissionMethodOverloadFragment);
}

@Test public void systemAlertWindowWithOnNeverAskAgain() {
expectRuntimeException("'@NeverAskAgain' annotated method never being called with 'WRITE_SETTINGS' or 'SYSTEM_ALERT_WINDOW' permission.");
assertJavaSource(Source.systemAlertWindowWithOnNeverAskAgain);
}

@Test public void writeSettingsWithOnNeverAskAgain() {
expectRuntimeException("'@NeverAskAgain' annotated method never being called with 'WRITE_SETTINGS' or 'SYSTEM_ALERT_WINDOW' permission.");
assertJavaSource(Source.writeSettingsWithOnNeverAskAgain);
}

@Test public void methodOverloadWithoutNeedsPermission() {
assertJavaSource(Source.methodOverloadWithoutNeedsPermission);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6001,6 +6001,90 @@ protected String[] getExpectSource() {
}
};

public static final BaseTest systemAlertWindowWithOnNeverAskAgain = new BaseTest() {
@Override
protected String getName() {
return "MyFragment";
}

@Override
protected String[] getActualSource() {
return new String[]{
"package test;",
"import android.Manifest;",
"import androidx.fragment.app.Fragment;",
"import permissions.dispatcher.NeedsPermission;",
"import permissions.dispatcher.OnNeverAskAgain;",
"import permissions.dispatcher.OnPermissionDenied;",
"import permissions.dispatcher.OnShowRationale;",
"import permissions.dispatcher.PermissionRequest;",
"import permissions.dispatcher.RuntimePermissions;",
"@RuntimePermissions",
"public class MyFragment extends Fragment {",
" @NeedsPermission(Manifest.permission.SYSTEM_ALERT_WINDOW)",
" void systemAlertWindow() {",
" }",
" @OnShowRationale(Manifest.permission.SYSTEM_ALERT_WINDOW)",
" void systemAlertWindowOnShowRationale(PermissionRequest request) {",
" }",
" @OnNeverAskAgain(Manifest.permission.SYSTEM_ALERT_WINDOW)",
" void systemAlertWindowOnNeverAskAgain() {",
" }",
" @OnPermissionDenied(Manifest.permission.SYSTEM_ALERT_WINDOW)",
" void systemAlertWindowOnPermissionDenied() {",
" }",
"}"
};
}

@Override
protected String[] getExpectSource() {
return EMPTY_SOURCE;
}
};

public static final BaseTest writeSettingsWithOnNeverAskAgain = new BaseTest() {
@Override
protected String getName() {
return "MyFragment";
}

@Override
protected String[] getActualSource() {
return new String[]{
"package test;",
"import android.Manifest;",
"import androidx.fragment.app.Fragment;",
"import permissions.dispatcher.NeedsPermission;",
"import permissions.dispatcher.OnNeverAskAgain;",
"import permissions.dispatcher.OnPermissionDenied;",
"import permissions.dispatcher.OnShowRationale;",
"import permissions.dispatcher.PermissionRequest;",
"import permissions.dispatcher.RuntimePermissions;",
"@RuntimePermissions",
"public class MyFragment extends Fragment {",
" @NeedsPermission(Manifest.permission.WRITE_SETTINGS)",
" void writeSettings() {",
" }",
" @OnShowRationale(Manifest.permission.WRITE_SETTINGS)",
" void writeSettingOnShowRationale(PermissionRequest request) {",
" }",
" @OnNeverAskAgain(Manifest.permission.WRITE_SETTINGS)",
" void writeSettingOnNeverAskAgain() {",
" }",
" @OnPermissionDenied(Manifest.permission.WRITE_SETTINGS)",
" void writeSettingOnPermissionDenied() {",
" }",
"}"
};
}

@Override
protected String[] getExpectSource() {
return EMPTY_SOURCE;
}
};

public static final BaseTest methodOverloadWithoutNeedsPermission = new BaseTest() {
@Override
protected String getName() {
Expand Down

0 comments on commit 8a0fa29

Please sign in to comment.