예제 #1
0
 public static FreudAnalyser specificMethodsShouldNotHaveBranchLogic(
     final AnalysedObjectIterator<ClassFile> iterator) {
   return Freud.iterateOver(ClassFileMethod.class)
       .assertThat(
           no(methodName().is(equalTo("criticalPath")))
               .or(
                   no(
                       containsInstructions(
                           Opcode.IFEQ,
                           Opcode.IFLT,
                           Opcode.IFLE,
                           Opcode.IFNE,
                           Opcode.IFGT,
                           Opcode.IFGE,
                           Opcode.IFNULL,
                           Opcode.IFNONNULL,
                           Opcode.IF_ICMPEQ,
                           Opcode.IF_ICMPGE,
                           Opcode.IF_ICMPGT,
                           Opcode.IF_ICMPLE,
                           Opcode.IF_ICMPLT,
                           Opcode.IF_ICMPNE,
                           Opcode.IF_ACMPEQ,
                           Opcode.IF_ACMPNE,
                           Opcode.TABLESWITCH,
                           Opcode.LOOKUPSWITCH,
                           Opcode.GOTO,
                           Opcode.GOTO_W,
                           Opcode.JSR,
                           Opcode.JSR_W))))
       .within(iterator);
 }
예제 #2
0
  @Test
  public void noStringBuffer() throws Exception {
    FreudAnalyser analyser =
        Freud.iterateOver(ClassFileMethod.class)
            .assertThat(no(hasMethodInvocation(StringBuffer.class, "<init>")))
            .within(classFiles);

    AnalysisListener listener = new AssertionErrorAnalysisListener();
    analyser.analyse(listener);
  }
예제 #3
0
  @Test
  public void noDateUtil() throws Exception {
    FreudAnalyser analyser =
        Freud.iterateOver(ImportDeclaration.class)
            .assertThat(no(importDeclaration().matches("java.util.Date")))
            .within(javaSources);

    AnalysisListener assertionListener = new AssertionErrorAnalysisListener();
    analyser.analyse(assertionListener);
  }
예제 #4
0
  @Test
  public void lessThan250Lines() throws Exception {
    FreudAnalyser analyser =
        Freud.iterateOver(CodeBlock.class)
            .assertThat(codeBlockLines().lessThanOrEqualTo(250))
            .within(javaSources);

    AnalysisListener listener = new AssertionErrorAnalysisListener();
    analyser.analyse(listener);
  }
예제 #5
0
  @Test
  public void noSystemGC() throws Exception {
    FreudAnalyser analyser =
        Freud.iterateOver(CodeBlock.class)
            .assertThat(no(CodeBlockDsl.hasMethodCall("System.gc")))
            .within(javaSources);

    AnalysisListener listener = new AssertionErrorAnalysisListener();
    analyser.analyse(listener);
  }
예제 #6
0
  @Test
  public void packageDeclaration() throws Exception {
    FreudAnalyser analyser =
        Freud.iterateOver(PackageDeclaration.class)
            .assertThat(
                PackageDeclarationDsl.packageDeclaration().matches("com.github.freudExamples.*"))
            .within(javaSources);

    AnalysisListener listener = new AssertionErrorAnalysisListener();
    analyser.analyse(listener);
  }
예제 #7
0
 public static FreudAnalyser doNotUseBigDecimalToString(
     final AnalysedObjectIterator<ClassFile> iterator) {
   return Freud.iterateOver(ClassFileMethod.class)
       .assertThat(
           no(hasMethodInvocation(BigDecimal.class, "toString"))
               .and(
                   no(
                       methodInvokedWithParams(
                           StringBuilder.class, "append", a(BigDecimal.class)))))
       .within(iterator);
 }
예제 #8
0
 public static FreudAnalyser doNotThrowAnyExceptions(
     final AnalysedObjectIterator<ClassFile> iterator) {
   return Freud.iterateOver(ClassFileMethod.class)
       .assertThat(no(containsInstructions(Opcode.ATHROW)))
       .within(iterator);
 }
예제 #9
0
 public static FreudAnalyser doNotUseBigDecimalEquals(
     final AnalysedObjectIterator<ClassFile> iterator) {
   return Freud.iterateOver(ClassFileMethod.class)
       .assertThat(no(hasMethodInvocation(BigDecimal.class, "equals", Object.class)))
       .within(iterator);
 }