TiagoMSSantos/MobileRT

View on GitHub
app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java

Summary

Maintainability
C
1 day
Test Coverage

Showing 99 of 99 total issues

File AbstractTest.java has 369 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package puscas.mobilertapp;
 
import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
Severity: Minor
Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 4 hrs to fix

    Method executeShellCommand has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    private static void executeShellCommand(final String shellCommand) {
    try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    final ParcelFileDescriptor parcelFileDescriptor = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(shellCommand);
    parcelFileDescriptor.checkError();
    Severity: Minor
    Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 1 hr to fix

    Method executeShellCommand has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    private static void executeShellCommand(final String shellCommand) {
    try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    final ParcelFileDescriptor parcelFileDescriptor = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(shellCommand);
    parcelFileDescriptor.checkError();
    Severity: Minor
    Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 1 hr to fix

      Method setUp has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      @Before
      @CallSuper
      public void setUp() {
      final String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
      logger.info(methodName + ": " + this.testName.getMethodName());
      Severity: Minor
      Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 1 hr to fix

        Method grantPermissions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        private static void grantPermissions() {
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
        Espresso.onIdle();
        logger.info("Granting permissions to the MainActivity to be able to read files from an external storage.");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        Severity: Minor
        Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 1 hr to fix

          Method setUpAll has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          @BeforeClass
          @CallSuper
          public static void setUpAll() {
          final String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
          logger.info(methodName);
          Severity: Minor
          Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 1 hr to fix

            Method assertRenderScene has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            protected void assertRenderScene(final Scene scene,
            final Shader shader,
            final Accelerator accelerator,
            final int spp,
            final int spl,
            Severity: Major
            Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 50 mins to fix

              Method isActivityRunning has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              @SuppressWarnings({"deprecation"})
              private static boolean isActivityRunning(@NonNull final Activity activity) {
              // Note that 'Activity#isDestroyed' only exists on Android API 17+.
              // More info: https://developer.android.com/reference/android/app/Activity#isDestroyed()
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
              Severity: Minor
              Found in app/src/androidTest/java/puscas/mobilertapp/AbstractTest.java - About 45 mins to fix

              Use the built-in formatting to construct this argument.
              Open

              logger.info(methodName + " finished");

              Use the built-in formatting to construct this argument.
              Open

              logger.info(methodName + ": Finishing the Activity.");

              Use the built-in formatting to construct this argument.
              Open

              logger.info(methodName + ": Will wait for the Activity triggered by the test to finish. Max timeout in secs: " + timeToWaitSecs);

              Remove this unused private "dismissANRSystemDialog" method.
              Open

              private static void dismissANRSystemDialog() {

              Make the enclosing method "static" or remove this set.
              Open

              oneTestFailed = true;

              Define and throw a dedicated exception instead of using a generic one.
              Open

              throw new RuntimeException("Permission '" + permission + "' NOT granted to the app: " + context.getPackageName());

              Define and throw a dedicated exception instead of using a generic one.
              Open

              throw new RuntimeException(ex);

              Define and throw a dedicated exception instead of using a generic one.
              Open

              throw new RuntimeException(ex);

              Wrong lexicographical order for 'java.io.IOException' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.io.IOException;

              Wrong lexicographical order for 'java.util.Deque' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.Deque;

              Wrong lexicographical order for 'java.util.concurrent.TimeoutException' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.concurrent.TimeoutException;

              Line is longer than 100 characters (found 134).
              Open

              waitForPermission(InstrumentationRegistry.getInstrumentation().getContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE);

              Line is longer than 100 characters (found 107).
              Open

              protected void mockFileManagerReply(final boolean externalSdcard, @NonNull final String... filesPath) {

              Line is longer than 100 characters (found 105).
              Open

              // Temporarily store the assertion that verifies if the application received the expected Intent.

              Wrong lexicographical order for 'java.io.File' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.io.File;

              Line is longer than 100 characters (found 117).
              Open

              logger.info(this.testName.getMethodName() + ": Resetting Intents that were missing from previous test.");

              Line is longer than 100 characters (found 115).
              Open

              final ActivityScenario<MainActivity> newActivityScenario = ActivityScenario.launch(MainActivity.class);

              Line is longer than 100 characters (found 128).
              Open

              logger.info(methodName + ": Activity finished: " + !isActivityRunning(activity) + " (" + currentTimeSecs + "secs)");

              Line is longer than 100 characters (found 161).
              Open

              // Necessary for the tests and MobileRT to be able to read any file from SD Card on Android 11+, by having the permission: 'MANAGE_EXTERNAL_STORAGE'.

              Line is longer than 100 characters (found 102).
              Open

              * @param expectedSameValues Whether the {@link Bitmap} should have have only one color.

              Extra separation in import group before 'androidx.annotation.CallSuper'
              Open

              import androidx.annotation.CallSuper;

              Wrong lexicographical order for 'java.util.Objects' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.Objects;

              Line is longer than 100 characters (found 133).
              Open

              InstrumentationRegistry.getInstrumentation().getContext().getPackageName(), Manifest.permission.READ_EXTERNAL_STORAGE

              Line continuation have incorrect indentation level, expected level should be 4.
              Open

              * tested application. This is done to avoid duplicated code.

              Wrong lexicographical order for 'java.util.ArrayDeque' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.ArrayDeque;

              Wrong lexicographical order for 'java.util.Collections' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.Collections;

              Line is longer than 100 characters (found 137).
              Open

              public static final ActivityScenarioRule<MainActivity> mainActivityActivityTestRule = new ActivityScenarioRule<>(MainActivity.class);

              Line is longer than 100 characters (found 140).
              Open

              waitForPermission(InstrumentationRegistry.getInstrumentation().getTargetContext(), Manifest.permission.MANAGE_EXTERNAL_STORAGE);

              Line is longer than 100 characters (found 126).
              Open

              throw new RuntimeException("Permission '" + permission + "' NOT granted to the app: " + context.getPackageName());

              Extra separation in import group before 'java.io.BufferedReader'
              Open

              import java.io.BufferedReader;

              Extra separation in import group before 'puscas.mobilertapp.constants.Accelerator'
              Open

              import puscas.mobilertapp.constants.Accelerator;

              Line is longer than 100 characters (found 143).
              Open

              if (taskRunning.baseActivity != null && Objects.equals(activity.getPackageName(), taskRunning.baseActivity.getPackageName())) {

              Line is longer than 100 characters (found 132).
              Open

              * @param showRenderWhenPressingButton Whether to show the {@link Constants#RENDER} text in the render button after pressing it.

              Line is longer than 100 characters (found 165).
              Open

              final ClipData clipData = new ClipData(new ClipDescription("Scene", new String[]{"*" + ConstantsUI.FILE_SEPARATOR + "*"}), new ClipData.Item(firstFile));

              Abbreviation in name 'dismissANRSystemDialog' must contain no more than '2' consecutive capital letters.
              Open

              private static void dismissANRSystemDialog() {

              Line is longer than 100 characters (found 138).
              Open

              waitForPermission(InstrumentationRegistry.getInstrumentation().getTargetContext(), Manifest.permission.READ_EXTERNAL_STORAGE);

              Line is longer than 100 characters (found 109).
              Open

              private static void waitForPermission(@NonNull final Context context, @NonNull final String permission) {

              Line is longer than 100 characters (found 155).
              Open

              final Intent resultIntent = MainActivity.createIntentToLoadFiles(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName());

              Line is longer than 100 characters (found 109).
              Open

              throw new FailureException("Command '" + shellCommand + "' failed with: " + outputError);

              Line is longer than 100 characters (found 128).
              Open

              logger.info(this.testName.getMethodName() + ": " + methodName + " validating '" + intentsToVerify.size() + "' Intents");

              Line is longer than 100 characters (found 122).
              Open

              final ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);

              Line is longer than 100 characters (found 163).
              Open

              final ParcelFileDescriptor parcelFileDescriptor = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(shellCommand);

              Wrong lexicographical order for 'java.util.List' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.List;

              Wrong lexicographical order for 'java.util.concurrent.TimeUnit' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.concurrent.TimeUnit;

              Wrong lexicographical order for 'java.util.logging.Logger' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.util.logging.Logger;

              Line is longer than 100 characters (found 172).
              Open

              InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand("pm grant puscas.mobilertapp.test android.permission.READ_EXTERNAL_STORAGE");

              Line is longer than 100 characters (found 118).
              Open

              UtilsPickerT.changePickerValue(ConstantsUI.PICKER_ACCELERATOR, R.id.pickerAccelerator, accelerator.ordinal());

              Line is longer than 100 characters (found 105).
              Open

              UtilsContextT.waitUntil(this.testName.getMethodName(), activity, Constants.STOP, State.BUSY);

              Line is longer than 100 characters (found 114).
              Open

              final Uri firstFile = Uri.fromFile(new File(storagePath + ConstantsUI.FILE_SEPARATOR + filesPath[0]));

              Line is longer than 100 characters (found 101).
              Open

              Intents.intended(IntentMatchers.filterEquals(expectedIntent), VerificationModes.times(1))

              Line is longer than 100 characters (found 126).
              Open

              logger.warning(this.testName.getMethodName() + ": The MainActivity didn't start as expected. Forcing a restart.");

              Line is longer than 100 characters (found 167).
              Open

              InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand("pm grant puscas.mobilertapp android.permission.READ_EXTERNAL_STORAGE");

              Line continuation have incorrect indentation level, expected level should be 4.
              Open

              * call it in the {@link #tearDown()} method after every test. This {@link Runnable} verifies

              Line is longer than 100 characters (found 114).
              Open

              resultIntent.setData(Uri.fromFile(new File(storagePath + ConstantsUI.FILE_SEPARATOR + filesPath[0])));

              Wrong lexicographical order for 'java.io.BufferedReader' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.io.BufferedReader;

              Line is longer than 100 characters (found 141).
              Open

              logger.info(methodName + ": Will wait for the Activity triggered by the test to finish. Max timeout in secs: " + timeToWaitSecs);

              Line is longer than 100 characters (found 139).
              Open

              InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName(), Manifest.permission.READ_EXTERNAL_STORAGE

              Line is longer than 100 characters (found 132).
              Open

              waitForPermission(InstrumentationRegistry.getInstrumentation().getContext(), Manifest.permission.READ_EXTERNAL_STORAGE);

              Line is longer than 100 characters (found 141).
              Open

              while (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED && currentTimeMs < timeToWaitMs) {

              Line is longer than 100 characters (found 106).
              Open

              if (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED) {

              Line is longer than 100 characters (found 112).
              Open

              * Click on device to dismiss any "Application Not Responding" (ANR) system dialog that might have appeared.

              Line is longer than 100 characters (found 105).
              Open

              final String errorMessage = testName.getMethodName() + ": " + exception.getMessage();

              Line is longer than 100 characters (found 106).
              Open

              InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();

              Line continuation have incorrect indentation level, expected level should be 4.
              Open

              * whether the expected mocked {@link Intent} used by this method was really received by the

              Line is longer than 100 characters (found 114).
              Open

              final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

              Wrong lexicographical order for 'java.io.InputStreamReader' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.io.InputStreamReader;

              Line is longer than 100 characters (found 108).
              Open

              protected void skipped(final AssumptionViolatedException exception, final Description description) {

              'private' modifier out of order with the JLS suggestions.
              Open

              final private Deque<Runnable> closeActions = new ArrayDeque<>();

              Line is longer than 100 characters (found 121).
              Open

              final int numCores = UtilsContext.getNumOfCores(InstrumentationRegistry.getInstrumentation().getTargetContext());

              <p> tag should be placed immediately before the first word, with no space after.</p>
              Open

              * <p>

              Line is longer than 100 characters (found 122).
              Open

              final List<ActivityManager.RunningTaskInfo> tasksRunning = activityManager.getRunningTasks(Integer.MAX_VALUE);

              Line is longer than 100 characters (found 105).
              Open

              ? UtilsContext.getSdCardPath(InstrumentationRegistry.getInstrumentation().getTargetContext())

              Line is longer than 100 characters (found 115).
              Open

              : UtilsContext.getInternalStoragePath(InstrumentationRegistry.getInstrumentation().getTargetContext());

              Line is longer than 100 characters (found 137).
              Open

              clipData.addItem(new ClipData.Item(Uri.fromFile(new File(storagePath + ConstantsUI.FILE_SEPARATOR + filesPath[index]))));

              Line is longer than 100 characters (found 123).
              Open

              final Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultIntent);

              Line is longer than 100 characters (found 123).
              Open

              final BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));

              Wrong lexicographical order for 'java.nio.file.FileSystem' import. Should be before 'org.junit.runner.Description'.
              Open

              import java.nio.file.FileSystem;

              <p> tag should be preceded with an empty line.</p>
              Open

              * <p>

              Line is longer than 100 characters (found 130).
              Open

              Matchers.anyOf(IntentMatchers.hasAction(Intent.ACTION_GET_CONTENT), IntentMatchers.hasAction(Intent.ACTION_MAIN)),

              Line is longer than 100 characters (found 152).
              Open

              Matchers.allOf(IntentMatchers.hasCategories(Collections.singleton(Intent.CATEGORY_LAUNCHER)), IntentMatchers.hasAction(Intent.ACTION_MAIN)),

              Line is longer than 100 characters (found 107).
              Open

              logger.info("Permission '" + permission + "' granted to the app: " + context.getPackageName());

              Line is longer than 100 characters (found 119).
              Open

              UtilsContextT.waitUntil(this.testName.getMethodName(), activity, Constants.RENDER, State.IDLE, State.FINISHED);

              Extra separation in import group before 'org.hamcrest.Matchers'
              Open

              import org.hamcrest.Matchers;

              Line is longer than 100 characters (found 101).
              Open

              mainActivityActivityTestRule.getScenario().onActivity(newActivity -> activity = newActivity);

              Line is longer than 100 characters (found 115).
              Open

              logger.info("Granting permissions to the MainActivity to be able to read files from an external storage.");

              Line is longer than 100 characters (found 103).
              Open

              UtilsPickerT.changePickerValue(ConstantsUI.PICKER_SHADER, R.id.pickerShader, shader.ordinal());

              Line is longer than 100 characters (found 157).
              Open

              final Intent expectedIntent = MainActivity.createIntentToLoadFiles(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName());

              Extra separation in import group before 'com.google.common.base.Preconditions'
              Open

              import com.google.common.base.Preconditions;

              Line is longer than 100 characters (found 129).
              Open

              logger.info("Waiting for the permission '" + permission + "' to be granted to the app: " + context.getPackageName());

              Line is longer than 100 characters (found 103).
              Open

              UtilsPickerT.changePickerValue(ConstantsUI.PICKER_SAMPLES_PIXEL, R.id.pickerSamplesPixel, spp);

              Line is longer than 100 characters (found 103).
              Open

              UtilsPickerT.changePickerValue(ConstantsUI.PICKER_SAMPLES_LIGHT, R.id.pickerSamplesLight, spl);
              Category
              Status