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); }
@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); }
@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); }
@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); }
@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); }
@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); }
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); }
public static FreudAnalyser doNotThrowAnyExceptions( final AnalysedObjectIterator<ClassFile> iterator) { return Freud.iterateOver(ClassFileMethod.class) .assertThat(no(containsInstructions(Opcode.ATHROW))) .within(iterator); }
public static FreudAnalyser doNotUseBigDecimalEquals( final AnalysedObjectIterator<ClassFile> iterator) { return Freud.iterateOver(ClassFileMethod.class) .assertThat(no(hasMethodInvocation(BigDecimal.class, "equals", Object.class))) .within(iterator); }