@Override public void configuration() { String testClassName = testContext.getTestClassName(); Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values(); CutDescriptor cutDescriptor = testContext.getCutDescriptor(); checkState(testContext.getConstructorCount() == 1, "Class under test '%s' has '%d' constructors. Please insure that " + "the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testContext.getConstructorCount()); fieldDescriptors.parallelStream().forEach(p -> { Class<?> fieldType = p.getType(); String fieldName = p.getName(); String fieldTypeName = p.getTypeName(); checkState(!isFinal(fieldType.getModifiers()), "Field '%s' in test class '%s' can not be mocked because '%s'" + " is a final class.", fieldName, testClassName, fieldTypeName); checkState(!p.hasAnyAnnotation(Real.class, Inject.class), "Field '%s' in test class '%s' is not annotated with @Fake. " + "Note that @Real and @Inject annotations not supported for " + "unit tests. Please use @Fake instead.", fieldName, fieldTypeName ); }); }
@Override public void configuration() { String testClassName = testContext.getTestClassName(); Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values(); CutDescriptor cutDescriptor = testContext.getCutDescriptor(); checkState(cutDescriptor != null, "Test class '%s' does not define a field annotated with @Cut class.", testClassName); checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount()); fieldDescriptors.parallelStream().forEach(p -> { Class<?> fieldType = p.getType(); String fieldName = p.getName(); String fieldTypeName = p.getTypeName(); checkState(!isFinal(fieldType.getModifiers()), "Field '%s' in test class '%s' can not be faked because '%s'" + " is a final class.", fieldName, testClassName, fieldTypeName); checkState(!p.hasAnyAnnotation(Real.class, Inject.class), "Field '%s' in test class '%s' is annotated with @Real or @Inject. " + "@Real and @Inject annotations are not supported for unit tests. " + "Please use @Fake instead.", fieldName, testClassName ); }); }
checkState(testContext.getConstructorCount() == 1, "Class under test '%s' has '%d' constructors. Please insure that " + "the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testContext.getConstructorCount());
checkState(testContext.getConstructorCount() == 1, "Class under test '%s' has '%d' constructors. Please insure that " + "the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testContext.getConstructorCount());
checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount());
checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount());