TiagoMSSantos/MobileRT

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

Summary

Maintainability
A
2 hrs
Test Coverage

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

    @Override
    protected List<FrameworkMethod> computeTestMethods() {
        logger.info("Sorting tests execution order.");
        final List<FrameworkMethod> originalTestsOrder = super.computeTestMethods();
        final List<FrameworkMethod> orderedTests = new ArrayList<>(originalTestsOrder);
Severity: Minor
Found in app/src/androidTest/java/puscas/mobilertapp/OrderRunner.java - About 1 hr to fix

    Method getTestRules has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        @Override
        protected List<TestRule> getTestRules(final Object testTarget) {
            final List<TestRule> testRules = super.getTestRules(testTarget);
            if (this.hasFlakyTestAnnotation) {
                final String testClassName = testTarget.getClass().getSimpleName();
    Severity: Minor
    Found in app/src/androidTest/java/puscas/mobilertapp/OrderRunner.java - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this method.
    Open

                return order;
    Severity: Major
    Found in app/src/androidTest/java/puscas/mobilertapp/OrderRunner.java - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return orderedTests;
      Severity: Major
      Found in app/src/androidTest/java/puscas/mobilertapp/OrderRunner.java - About 30 mins to fix

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

                    logger.warning("Ignoring '" + testTimeoutRuleName + "' test rule for the test '" + testClassName + "' because it is marked as a flaky one.");

        Passing message arguments that require further evaluation into a Guava com.google.common.base.Preconditions check can result in a performance penalty. That's because whether or not they're needed, each argument must be resolved before the method is actually called.

        Similarly, passing concatenated strings into a logging method can also incur a needless performance hit because the concatenation will be performed every time the method is called, whether or not the log level is low enough to show the message.

        Instead, you should structure your code to pass static or pre-computed values into Preconditions conditions check and logging calls.

        Specifically, the built-in string formatting should be used instead of string concatenation, and if the message is the result of a method call, then Preconditions should be skipped altogether, and the relevant exception should be conditionally thrown instead.

        Noncompliant Code Example

        logger.log(Level.DEBUG, "Something went wrong: " + message);  // Noncompliant; string concatenation performed even when log level too high to show DEBUG messages
        
        logger.fine("An exception occurred with message: " + message); // Noncompliant
        
        LOG.error("Unable to open file " + csvPath, e);  // Noncompliant
        
        Preconditions.checkState(a > 0, "Arg must be positive, but got " + a);  // Noncompliant. String concatenation performed even when a > 0
        
        Preconditions.checkState(condition, formatMessage());  // Noncompliant. formatMessage() invoked regardless of condition
        
        Preconditions.checkState(condition, "message: %s", formatMessage());  // Noncompliant
        

        Compliant Solution

        logger.log(Level.SEVERE, "Something went wrong: {0} ", message);  // String formatting only applied if needed
        
        logger.fine("An exception occurred with message: {}", message);  // SLF4J, Log4j
        
        logger.log(Level.SEVERE, () -> "Something went wrong: " + message); // since Java 8, we can use Supplier , which will be evaluated lazily
        
        LOG.error("Unable to open file {0}", csvPath, e);
        
        if (LOG.isDebugEnabled() {
          LOG.debug("Unable to open file " + csvPath, e);  // this is compliant, because it will not evaluate if log level is above debug.
        }
        
        Preconditions.checkState(arg > 0, "Arg must be positive, but got %d", a);  // String formatting only applied if needed
        
        if (!condition) {
          throw new IllegalStateException(formatMessage());  // formatMessage() only invoked conditionally
        }
        
        if (!condition) {
          throw new IllegalStateException("message: " + formatMessage());
        }
        

        Exceptions

        catch blocks are ignored, because the performance penalty is unimportant on exceptional paths (catch block should not be a part of standard program flow). Getters are ignored as well as methods called on annotations which can be considered as getters. This rule accounts for explicit test-level testing with SLF4J methods isXXXEnabled and ignores the bodies of such if statements.

        Wrong lexicographical order for 'java.util.ArrayList' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import java.util.ArrayList;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Extra separation in import group before 'javax.annotation.Nullable'
        Open

        import javax.annotation.Nullable;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

                    logger.warning("Ignoring '" + testTimeoutRuleName + "' test rule for the test '" + testClassName + "' because it is marked as a flaky one.");

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

             * @return {@code 0} if they are equal, {@code -1} if the 1st test should be executed first, or {@code 1} if the 2nd test should be executed first.

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Extra separation in import group before 'java.util.ArrayList'
        Open

        import java.util.ArrayList;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Wrong lexicographical order for 'java.util.List' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import java.util.List;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Wrong lexicographical order for 'java.util.logging.Logger' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import java.util.logging.Logger;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Wrong lexicographical order for 'java.util.Collections' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import java.util.Collections;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Extra separation in import group before 'org.junit.Test'
        Open

        import org.junit.Test;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Wrong lexicographical order for 'javax.annotation.Nullable' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import javax.annotation.Nullable;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

             * Helper method which compares 2 {@link Test tests} based if they have the {@link FlakyTest} annotation.

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            private int compareFlakyTests(@Nullable final FlakyTest test1, @Nullable final FlakyTest test2) {

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        Wrong lexicographical order for 'java.util.Arrays' import. Should be before 'org.junit.runners.model.Statement'.
        Open

        import java.util.Arrays;

        Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * This implementation ignores errors from tests that are marked as {@link FlakyTest flaky} with the annotation.

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

            * <p>

        Checks the Javadoc paragraph.

        Checks that:

        • There is one blank line between each of two paragraphs.
        • Each paragraph but the first has <p> immediately before the first word, withno space after.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

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

                logger.info("Original test execution order: " + Arrays.toString(originalTestsOrder.toArray()));

        Checks for long lines.

        Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

        This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

        There are no issues that match your filters.

        Category
        Status