@Override public String getTestClassName() { return testContext.getTestClassName(); }
@Override public String getTestClassName() { return testContext.getTestClassName(); }
@Override public String getTestClassName() { return testContext.getTestClassName(); }
@Override public String getTestClassName() { return testContext.getTestClassName(); }
@Override public void wiring() { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); String cutClassName = cutDescriptor.getTypeName(); Collection<ParameterDescriptor> fieldDescriptors = testContext.getParamaterDescriptors().values(); fieldDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Class under test '{}' defined in '{}' has a collaborator " + "type '{}' but test class '{}' does not define a field of " + "type '{}' annotated with @Fake. Null values will be used.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); }
@Override public void wiring() { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); String cutClassName = cutDescriptor.getTypeName(); Collection<ParameterDescriptor> fieldDescriptors = testContext.getParamaterDescriptors().values(); fieldDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Improper wiring detected. Class under test '{}' defined " + "in '{}' declars constructor argument of type '{}' but '{}' " + "does not define a field of type '{}' annotated with @Fake.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); }
@Override public void wiring() { doPrivileged((PrivilegedAction<Object>) () -> { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); Collection<ParameterDescriptor> paramDescriptors = testContext.getParamaterDescriptors().values(); if (cutDescriptor != null) { String cutClassName = cutDescriptor.getTypeName(); paramDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Class under test '{}' defined in '{}' has a collaborator " + "of type '{}' but test class '{}' does not define a field of " + "type '{}' annotated with @Fake, @Real, or @Inject. The real " + "instance of the collaborator will be used.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); } return null; }); }
@Override public void wiring() { doPrivileged((PrivilegedAction<Object>) () -> { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); Collection<ParameterDescriptor> paramDescriptors = testContext.getParamaterDescriptors().values(); if (cutDescriptor != null) { String cutClassName = cutDescriptor.getTypeName(); paramDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Improper wiring detected. Class under test '{}' defined " + "in '{}' declars constructor argument of type '{}' but '{}' " + "does not define a field of type '{}' annotated with @Fake or @Real.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); } return null; }); }
@Override public void wiring() { doPrivileged((PrivilegedAction<Object>) () -> { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); Collection<ParameterDescriptor> paramDescriptors = testContext.getParamaterDescriptors().values(); if (cutDescriptor != null) { String cutClassName = cutDescriptor.getTypeName(); paramDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Improper wiring detected. Class under test '{}' defined " + "in '{}' declars constructor argument of type '{}' but '{}' " + "does not define a field of type '{}' annotated with @Fake or @Real.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); } return null; }); }
@Override public void wiring() { doPrivileged((PrivilegedAction<Object>) () -> { CutDescriptor cutDescriptor = testContext.getCutDescriptor(); String testClassName = testContext.getTestClassName(); Collection<ParameterDescriptor> paramDescriptors = testContext.getParamaterDescriptors().values(); if (cutDescriptor != null) { String cutClassName = cutDescriptor.getTypeName(); paramDescriptors.parallelStream().forEach(p -> { Optional instance = p.getInstance(); if (!instance.isPresent()) { String paramTypeName = p.getTypeName(); logger.warn("Class under test '{}' defined in '{}' has a collaborator " + "of type '{}' but test class '{}' does not define a field of " + "type '{}' annotated with @Fake, @Real, or @Inject. The real " + "instance of the collaborator will be used.", cutClassName, testClassName, paramTypeName, testClassName, paramTypeName); } }); } return null; }); }
public EmbeddedServletContainerFactory getEmbeddedServletContainerFactory( @SuperCall Callable<EmbeddedServletContainerFactory> zuper, @This Object object) throws Exception { EmbeddedServletContainerFactory containerFactory = zuper.call(); ConfigurableEmbeddedServletContainer configurableServletContainer = (ConfigurableEmbeddedServletContainer) containerFactory; configurableServletContainer.setPort(0); SpringBootDescriptor descriptor = getDescriptor(object); descriptor.setContainerFactory(containerFactory); descriptor.setConfigurableServletContainer(configurableServletContainer); TestContext testContext = descriptor.getTestContext(); testContext.getConfigMethod(ConfigurableEmbeddedServletContainer.class) .map(m -> m.getMethod()) .ifPresent(m -> { AccessController.doPrivileged((PrivilegedAction<Object>) () -> { try { m.setAccessible(true); m.invoke(testContext.getTestInstance(), configurableServletContainer); } catch (Exception e) { checkState(false, "Call to config method '%s' in test class '%s' failed.", m.getName(), testContext.getTestClassName()); throw Throwables.propagate(e); } return null; }); }); return containerFactory; }
Parameter parameter = paramDescriptor.getParameter(); String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();
@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 ); }); }
Parameter parameter = paramDescriptor.getParameter(); String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();
Parameter parameter = paramDescriptor.getParameter(); String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();
Parameter parameter = paramDescriptor.getParameter(); String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();
Parameter parameter = paramDescriptor.getParameter(); String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();
@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 ); }); }
String fieldTypeName = descriptor.getTypeName(); String cutTypeName = context.getCutDescriptor().getTypeName(); String testClassName = context.getTestClassName();
String testClassName = context.getTestClassName(); Type fieldType = descriptor.getGenericType(); String fieldTypeName = descriptor.getTypeName();