/** @return a test for the find all method, if available and requested (may return null) */ private MethodMetadataBuilder getFindAllMethodTest( final MemberTypeAdditions findAllMethod, final MemberTypeAdditions countMethod) { if (!annotationValues.isFindAll() || findAllMethod == null || countMethod == null) { // User does not want this method, or core dependencies are missing return null; } // Prepare method signature JavaSymbolName methodName = new JavaSymbolName("test" + StringUtils.capitalize(findAllMethod.getMethodName())); if (governorHasMethod(methodName)) { return null; } builder.getImportRegistrationResolver().addImport(LIST); List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); annotations.add(new AnnotationMetadataBuilder(TEST)); final String entityName = annotationValues.getEntity().getSimpleTypeName(); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine( "Assert.assertNotNull(\"Data on demand for '" + entityName + "' failed to initialize correctly\", dod." + dataOnDemandMetadata.getRandomPersistentEntityMethod().getMethodName().getSymbolName() + "());"); bodyBuilder.appendFormalLine("long count = " + countMethod.getMethodCall() + ";"); bodyBuilder.appendFormalLine( "Assert.assertTrue(\"Too expensive to perform a find all test for '" + entityName + "', as there are \" + count + \" entries; set the findAllMaximum to exceed this value or set findAll=false on the integration test annotation to disable the test\", count < " + annotationValues.getFindAllMaximum() + ");"); bodyBuilder.appendFormalLine( "List<" + entityName + "> result = " + findAllMethod.getMethodCall() + ";"); bodyBuilder.appendFormalLine( "Assert.assertNotNull(\"Find all method for '" + entityName + "' illegally returned null\", result);"); bodyBuilder.appendFormalLine( "Assert.assertTrue(\"Find all method for '" + entityName + "' failed to return any data\", result.size() > 0);"); findAllMethod.copyAdditionsTo(builder, governorTypeDetails); countMethod.copyAdditionsTo(builder, governorTypeDetails); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, bodyBuilder); methodBuilder.setAnnotations(annotations); return methodBuilder; }