Convert JUnit assertions to AssertJ to match spring-javaformat checkstyle rules
This commit is contained in:
@@ -3,10 +3,7 @@
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
<module name="com.puppycrawl.tools.checkstyle.Checker">
|
||||
<module name="io.spring.javaformat.checkstyle.SpringChecks" >
|
||||
<!-- Exclude some rules that require assertJ-->
|
||||
<property name="excludes" value="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck" />
|
||||
</module>
|
||||
<module name="io.spring.javaformat.checkstyle.SpringChecks" />
|
||||
|
||||
<!-- Enable @SuppressWarnings -->
|
||||
<module name="TreeWalker">
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -57,6 +57,12 @@
|
||||
<version>1.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.22.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
@@ -26,8 +26,7 @@ import com.google.inject.name.Names;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public abstract class AbstractCompleteWiringTests {
|
||||
|
||||
@@ -44,58 +43,58 @@ public abstract class AbstractCompleteWiringTests {
|
||||
public void injectInstance() {
|
||||
Bar bar = new Bar();
|
||||
this.injector.injectMembers(bar);
|
||||
assertNotNull(bar.service);
|
||||
assertThat(bar.service).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void memberInjector() {
|
||||
Bar bar = new Bar();
|
||||
this.injector.getMembersInjector(Bar.class).injectMembers(bar);
|
||||
assertNotNull(bar.service);
|
||||
assertThat(bar.service).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInstanceUnbound() {
|
||||
assertNotNull(this.injector.getInstance(Foo.class));
|
||||
assertThat(this.injector.getInstance(Foo.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInstanceBound() {
|
||||
assertNotNull(this.injector.getInstance(Service.class));
|
||||
assertThat(this.injector.getInstance(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInstanceBoundWithNoInterface() {
|
||||
Baz instance = this.injector.getInstance(Baz.class);
|
||||
assertNotNull(instance);
|
||||
assertEquals(instance, this.injector.getInstance(Baz.class));
|
||||
assertThat(instance).isNotNull();
|
||||
assertThat(this.injector.getInstance(Baz.class)).isEqualTo(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProviderUnbound() {
|
||||
assertNotNull(this.injector.getProvider(Foo.class).get());
|
||||
assertThat(this.injector.getProvider(Foo.class).get()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProviderBound() {
|
||||
assertNotNull(this.injector.getProvider(Service.class).get());
|
||||
assertThat(this.injector.getProvider(Service.class).get()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNamedInstance() {
|
||||
assertNotNull(this.injector.getInstance(Key.get(Thang.class, Names.named("thing"))));
|
||||
assertThat(this.injector.getInstance(Key.get(Thang.class, Names.named("thing")))).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNamedInjectedInstance() {
|
||||
assertNotNull(this.injector.getInstance(Thing.class).thang);
|
||||
assertThat(this.injector.getInstance(Thing.class).thang).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParameterizedType() {
|
||||
Parameterized<String> instance = this.injector.getInstance(Key.get(new TypeLiteral<Parameterized<String>>() {
|
||||
}));
|
||||
assertNotNull(instance);
|
||||
assertThat(instance).isNotNull();
|
||||
}
|
||||
|
||||
public interface Service {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BeanPostProcessorTests {
|
||||
|
||||
@@ -46,11 +46,11 @@ public class BeanPostProcessorTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
BeanPostProcessorTestConfig.class);
|
||||
PostProcessedBean postProcessedBean = context.getBean(PostProcessedBean.class);
|
||||
assertTrue(postProcessedBean.postProcessed);
|
||||
assertThat(postProcessedBean.postProcessed).isTrue();
|
||||
GuiceBeanThatWantsPostProcessedBean guiceBean1 = context.getBean(GuiceBeanThatWantsPostProcessedBean.class);
|
||||
assertTrue(guiceBean1.ppb.postProcessed);
|
||||
assertThat(guiceBean1.ppb.postProcessed).isTrue();
|
||||
GuiceBeanThatWantsSpringBean guiceBean2 = context.getBean(GuiceBeanThatWantsSpringBean.class);
|
||||
assertTrue(guiceBean2.springBean.ppb.postProcessed);
|
||||
assertThat(guiceBean2.springBean.ppb.postProcessed).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BindingAnnotationTests {
|
||||
|
||||
@@ -51,46 +50,46 @@ public class BindingAnnotationTests {
|
||||
// Check @Qualifier
|
||||
SomeDependencyWithQualifierOnProvider someDependencyWithQualifierOnClass = injector
|
||||
.getInstance(Key.get(SomeDependencyWithQualifierOnProvider.class, SomeQualifierAnnotation.class));
|
||||
assertNotNull(someDependencyWithQualifierOnClass);
|
||||
assertThat(someDependencyWithQualifierOnClass).isNotNull();
|
||||
|
||||
// Check @BindingAnnotation on Spring @Bean available in Guice
|
||||
SomeDependencyWithQualifierOnProvider someDependencyWithBindingAnnotationOnProvider = injector
|
||||
.getInstance(Key.get(SomeDependencyWithQualifierOnProvider.class, SomeQualifierAnnotation.class));
|
||||
assertNotNull(someDependencyWithBindingAnnotationOnProvider);
|
||||
assertThat(someDependencyWithBindingAnnotationOnProvider).isNotNull();
|
||||
|
||||
// Check @BindingAnnotation on Guice Binding available in Spring
|
||||
SomeStringHolder stringHolder = context.getBean(SomeStringHolder.class);
|
||||
assertEquals("annotated", stringHolder.annotatedString);
|
||||
assertEquals("other", stringHolder.otherAnnotatedString);
|
||||
assertThat(stringHolder.annotatedString).isEqualTo("annotated");
|
||||
assertThat(stringHolder.otherAnnotatedString).isEqualTo("other");
|
||||
|
||||
// Check javax @Named
|
||||
SomeDependencyWithNamedAnnotationOnProvider someDependencyWithNamedAnnotationOnProvider = injector
|
||||
.getInstance(Key.get(SomeDependencyWithNamedAnnotationOnProvider.class, Names.named("javaxNamed")));
|
||||
assertNotNull(someDependencyWithNamedAnnotationOnProvider);
|
||||
assertThat(someDependencyWithNamedAnnotationOnProvider).isNotNull();
|
||||
|
||||
// Check Guice @Named
|
||||
SomeDependencyWithGuiceNamedAnnotationOnProvider someDependencyWithGuiceNamedAnnotationOnProvider = injector
|
||||
.getInstance(
|
||||
Key.get(SomeDependencyWithGuiceNamedAnnotationOnProvider.class, Names.named("guiceNamed")));
|
||||
assertNotNull(someDependencyWithGuiceNamedAnnotationOnProvider);
|
||||
assertThat(someDependencyWithGuiceNamedAnnotationOnProvider).isNotNull();
|
||||
|
||||
SomeDependencyWithGuiceNamedAnnotationOnProvider someSecondDependencyWithGuiceNamedAnnotationOnProvider = injector
|
||||
.getInstance(
|
||||
Key.get(SomeDependencyWithGuiceNamedAnnotationOnProvider.class, Names.named("guiceNamed2")));
|
||||
assertNotNull(someSecondDependencyWithGuiceNamedAnnotationOnProvider);
|
||||
assertThat(someSecondDependencyWithGuiceNamedAnnotationOnProvider).isNotNull();
|
||||
|
||||
// Check @Qualifier with Interface
|
||||
SomeInterface someInterface = injector.getInstance(Key.get(SomeInterface.class, SomeQualifierAnnotation.class));
|
||||
assertNotNull(someInterface);
|
||||
assertThat(someInterface).isNotNull();
|
||||
|
||||
// Check different types with same @Named
|
||||
assertNotNull(injector.getInstance(SomeNamedDepWithType1.class));
|
||||
assertNotNull(injector.getInstance(SomeNamedDepWithType2.class));
|
||||
assertThat(injector.getInstance(SomeNamedDepWithType1.class)).isNotNull();
|
||||
assertThat(injector.getInstance(SomeNamedDepWithType2.class)).isNotNull();
|
||||
|
||||
assertNotNull(
|
||||
injector.getInstance(Key.get(SomeNamedDepWithType1.class, Names.named("sameNameDifferentType"))));
|
||||
assertNotNull(
|
||||
injector.getInstance(Key.get(SomeNamedDepWithType2.class, Names.named("sameNameDifferentType"))));
|
||||
assertThat(injector.getInstance(Key.get(SomeNamedDepWithType1.class, Names.named("sameNameDifferentType"))))
|
||||
.isNotNull();
|
||||
assertThat(injector.getInstance(Key.get(SomeNamedDepWithType2.class, Names.named("sameNameDifferentType"))))
|
||||
.isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class BindingDeduplicationTests {
|
||||
|
||||
@@ -44,16 +44,16 @@ public class BindingDeduplicationTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
BindingDeduplicationTestsConfig.class);
|
||||
SomeDependency someDependency = context.getBean(SomeDependency.class);
|
||||
assertNotNull(someDependency);
|
||||
assertThat(someDependency).isNotNull();
|
||||
SomeOptionalDependency someOptionalDependency = context.getBean(SomeOptionalDependency.class);
|
||||
assertNotNull(someOptionalDependency);
|
||||
assertThat(someOptionalDependency).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyDuplicateBindingErrorWhenDedupeNotEnabled() {
|
||||
System.setProperty("spring.guice.dedup", "false");
|
||||
assertThrows(CreationException.class, () -> {
|
||||
assertThatExceptionOfType(CreationException.class).isThrownBy(() -> {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
BindingDeduplicationTestsConfig.class);
|
||||
context.close();
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DuplicateNamesDifferentTypesTests {
|
||||
|
||||
@@ -41,16 +41,16 @@ public class DuplicateNamesDifferentTypesTests {
|
||||
DuplicateNamesDifferentTypesTestsConfig.class);
|
||||
|
||||
// Check Guice @Named
|
||||
assertNotNull(context.getBean(SomeNamedDepWithType1.class));
|
||||
assertNotNull(context.getBean(SomeNamedDepWithType2.class));
|
||||
assertNotNull(BeanFactoryAnnotationUtils.qualifiedBeanOfType(context.getBeanFactory(),
|
||||
SomeNamedDepWithType1.class, "sameNameDifferentType"));
|
||||
assertThat(context.getBean(SomeNamedDepWithType1.class)).isNotNull();
|
||||
assertThat(context.getBean(SomeNamedDepWithType2.class)).isNotNull();
|
||||
assertThat(BeanFactoryAnnotationUtils.qualifiedBeanOfType(context.getBeanFactory(), SomeNamedDepWithType1.class,
|
||||
"sameNameDifferentType")).isNotNull();
|
||||
|
||||
// Check javax @Named
|
||||
assertNotNull(context.getBean(SomeJavaxNamedDepWithType1.class));
|
||||
assertNotNull(context.getBean(SomeJavaxNamedDepWithType2.class));
|
||||
assertNotNull(BeanFactoryAnnotationUtils.qualifiedBeanOfType(context.getBeanFactory(),
|
||||
SomeJavaxNamedDepWithType1.class, "sameJavaxName"));
|
||||
assertThat(context.getBean(SomeJavaxNamedDepWithType1.class)).isNotNull();
|
||||
assertThat(context.getBean(SomeJavaxNamedDepWithType2.class)).isNotNull();
|
||||
assertThat(BeanFactoryAnnotationUtils.qualifiedBeanOfType(context.getBeanFactory(),
|
||||
SomeJavaxNamedDepWithType1.class, "sameJavaxName")).isNotNull();
|
||||
context.getBeansOfType(SomeJavaxNamedDepWithType1.class);
|
||||
|
||||
context.close();
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.annotation.InjectorFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ElementVisitorTests {
|
||||
|
||||
@@ -60,9 +60,9 @@ public class ElementVisitorTests {
|
||||
@Test
|
||||
public void verifySpringModuleDoesNotBreakWhenUsingElementVisitors() {
|
||||
ElementVisitorTestSpringBean testSpringBean = context.getBean(ElementVisitorTestSpringBean.class);
|
||||
assertEquals("spring created", testSpringBean.toString());
|
||||
assertThat(testSpringBean.toString()).isEqualTo("spring created");
|
||||
ElementVisitorTestGuiceBean testGuiceBean = context.getBean(ElementVisitorTestGuiceBean.class);
|
||||
assertEquals("spring created", testGuiceBean.toString());
|
||||
assertThat(testGuiceBean.toString()).isEqualTo("spring created");
|
||||
}
|
||||
|
||||
public static class ElementVisitorTestSpringBean {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.annotation.InjectorFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class InjectorFactoryTests {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class InjectorFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testMultipleInjectorFactoriesThrowsApplicationContextException() {
|
||||
assertThrows(ApplicationContextException.class, () -> {
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
InjectorFactoryConfig.class, SecondInjectorFactoryConfig.class, ModulesConfig.class);
|
||||
context.close();
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class JustInTimeBindingTests {
|
||||
|
||||
@@ -40,13 +40,13 @@ public class JustInTimeBindingTests {
|
||||
@Test
|
||||
public void springWithJustInTimeBinding() {
|
||||
System.setProperty("spring.guice.autowireJIT", "true");
|
||||
assertNotNull(springGetFoo());
|
||||
assertThat(springGetFoo()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springWithoutJustInTimeBinding() {
|
||||
System.setProperty("spring.guice.autowireJIT", "false");
|
||||
assertThrows(UnsatisfiedDependencyException.class, this::springGetFoo);
|
||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this::springGetFoo);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class LazyInitializationTests {
|
||||
|
||||
@@ -40,8 +39,8 @@ public class LazyInitializationTests {
|
||||
|
||||
Service service = context.getBean(Service.class);
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(service.getBean()));
|
||||
assertNotNull(context.getBean(TestBean.class));
|
||||
assertThat(AopUtils.isAopProxy(service.getBean())).isTrue();
|
||||
assertThat(context.getBean(TestBean.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,8 +52,8 @@ public class LazyInitializationTests {
|
||||
|
||||
Service service = context.getBean(Service.class);
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(service.getBean()));
|
||||
assertNotNull(context.getBean(TestBean.class));
|
||||
assertThat(AopUtils.isAopProxy(service.getBean())).isTrue();
|
||||
assertThat(context.getBean(TestBean.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test injecting Map
|
||||
@@ -60,7 +60,7 @@ public class MapWiringTests {
|
||||
|
||||
@Bean
|
||||
Bar foo(Map<String, Foo> foos) {
|
||||
assertFalse(foos.isEmpty());
|
||||
assertThat(foos.isEmpty()).isFalse();
|
||||
return new Bar();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.annotation.InjectorFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class ModuleFilteringTests {
|
||||
|
||||
@@ -43,11 +43,11 @@ public class ModuleFilteringTests {
|
||||
@Test
|
||||
public void verifyAllIsWellWhenNoModulesFiltered() {
|
||||
System.setProperty("spring.guice.modules.exclude", "FilterSomeNonExistentModule");
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
ModuleFilteringTestsConfig.class);
|
||||
SomeInterface someDependency = context.getBean(SomeInterface.class);
|
||||
assertNotNull(someDependency);
|
||||
assertThat(someDependency).isNotNull();
|
||||
context.close();
|
||||
});
|
||||
}
|
||||
@@ -57,7 +57,8 @@ public class ModuleFilteringTests {
|
||||
System.setProperty("spring.guice.modules.exclude", "FilterThisModule");
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
ModuleFilteringTestsConfig.class)) {
|
||||
assertThrows(NoSuchBeanDefinitionException.class, () -> context.getBean(SomeInterface.class));
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> context.getBean(SomeInterface.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -39,7 +39,7 @@ public class NativeGuiceTests {
|
||||
public void test() {
|
||||
Injector app = Guice.createInjector(new TestConfig());
|
||||
NativeGuiceTests instance = app.getInstance(NativeGuiceTests.class);
|
||||
assertNotNull(instance.bar);
|
||||
assertThat(instance.bar).isNotNull();
|
||||
}
|
||||
|
||||
public static class TestConfig extends AbstractModule {
|
||||
|
||||
@@ -34,9 +34,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class PrivateModuleTests {
|
||||
|
||||
@@ -59,34 +58,35 @@ public class PrivateModuleTests {
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
SomeInterface injectorProvidedPrivateBinding = injector
|
||||
.getInstance(Key.get(SomeInterface.class, Names.named("exposed")));
|
||||
assertNotNull(injectorProvidedPrivateBinding);
|
||||
assertThat(injectorProvidedPrivateBinding).isNotNull();
|
||||
SomeInterface springProvidedPrivateBinding = context.getBean(SomeInterface.class);
|
||||
assertNotNull(springProvidedPrivateBinding);
|
||||
assertThat(springProvidedPrivateBinding).isNotNull();
|
||||
SomeInterface namedPrivateBinding = BeanFactoryAnnotationUtils.qualifiedBeanOfType(context.getBeanFactory(),
|
||||
SomeInterface.class, "exposed");
|
||||
assertNotNull(namedPrivateBinding);
|
||||
assertEquals(injectorProvidedPrivateBinding, springProvidedPrivateBinding);
|
||||
assertEquals(injectorProvidedPrivateBinding, namedPrivateBinding);
|
||||
assertThat(namedPrivateBinding).isNotNull();
|
||||
assertThat(springProvidedPrivateBinding).isEqualTo(injectorProvidedPrivateBinding);
|
||||
assertThat(namedPrivateBinding).isEqualTo(injectorProvidedPrivateBinding);
|
||||
String beanDependingOnPrivateBinding = context.getBean("somethingThatWantsAPrivateBinding", String.class);
|
||||
assertNotNull(beanDependingOnPrivateBinding);
|
||||
assertEquals("foo", beanDependingOnPrivateBinding);
|
||||
assertThat(beanDependingOnPrivateBinding).isNotNull();
|
||||
assertThat(beanDependingOnPrivateBinding).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPrivateModulesPrivateBindingsAreNotExposedViaInjector() {
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
assertThrows(ConfigurationException.class,
|
||||
() -> injector.getInstance(Key.get(SomeInterface.class, Names.named("notexposed"))));
|
||||
assertThatExceptionOfType(ConfigurationException.class)
|
||||
.isThrownBy(() -> injector.getInstance(Key.get(SomeInterface.class, Names.named("notexposed"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPrivateModulesPrivateBindingsAreNotExposedViaSpring() {
|
||||
assertThrows(NoSuchBeanDefinitionException.class, () -> context.getBean("notexposed", SomeInterface.class));
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> context.getBean("notexposed", SomeInterface.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPrivateModulesPrivateBindingsAreNotExposedViaSpringWithQualifier() {
|
||||
assertThrows(NoSuchBeanDefinitionException.class, () -> BeanFactoryAnnotationUtils
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> BeanFactoryAnnotationUtils
|
||||
.qualifiedBeanOfType(context.getBeanFactory(), SomeInterface.class, "notexposed"));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PrototypeScopedBeanTests {
|
||||
|
||||
@@ -40,9 +39,9 @@ public class PrototypeScopedBeanTests {
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
GuiceService1 gs1 = injector.getInstance(GuiceService1.class);
|
||||
GuiceService2 gs2 = injector.getInstance((GuiceService2.class));
|
||||
assertNotNull(gs1);
|
||||
assertNotNull(gs2);
|
||||
assertNotEquals(gs1.bean, gs2.bean);
|
||||
assertThat(gs1).isNotNull();
|
||||
assertThat(gs2).isNotNull();
|
||||
assertThat(gs2.bean).isNotEqualTo(gs1.bean);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Scope;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -29,8 +28,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ScopingTests {
|
||||
|
||||
@@ -40,25 +38,25 @@ public class ScopingTests {
|
||||
SomeSingletonDependency someSingletonDependency1 = context.getBean(SomeSingletonDependency.class);
|
||||
SomeSingletonDependency someSingletonDependency2 = context.getBean(SomeSingletonDependency.class);
|
||||
|
||||
assertNotNull(someSingletonDependency1);
|
||||
assertNotNull(someSingletonDependency2);
|
||||
assertEquals(someSingletonDependency1, someSingletonDependency2);
|
||||
assertThat(someSingletonDependency1).isNotNull();
|
||||
assertThat(someSingletonDependency2).isNotNull();
|
||||
assertThat(someSingletonDependency2).isEqualTo(someSingletonDependency1);
|
||||
|
||||
SomeNoScopeDependency someNoScopeDependency1 = context.getBean(SomeNoScopeDependency.class);
|
||||
SomeNoScopeDependency someNoScopeDependency2 = context.getBean(SomeNoScopeDependency.class);
|
||||
|
||||
assertNotNull(someNoScopeDependency1);
|
||||
assertNotNull(someNoScopeDependency2);
|
||||
Assertions.assertNotEquals(someNoScopeDependency1, someNoScopeDependency2);
|
||||
assertThat(someNoScopeDependency1).isNotNull();
|
||||
assertThat(someNoScopeDependency2).isNotNull();
|
||||
assertThat(someNoScopeDependency2).isNotEqualTo(someNoScopeDependency1);
|
||||
|
||||
SomeCustomScopeDependency someCustomScopeDependency1 = context.getBean(SomeCustomScopeDependency.class);
|
||||
SomeCustomScopeDependency someCustomScopeDependency2 = context.getBean(SomeCustomScopeDependency.class);
|
||||
|
||||
assertNotNull(someCustomScopeDependency1);
|
||||
assertNotNull(someCustomScopeDependency2);
|
||||
Assertions.assertNotEquals(someCustomScopeDependency1, someCustomScopeDependency2);
|
||||
assertEquals(someCustomScopeDependency1.value, "custom");
|
||||
assertEquals(someCustomScopeDependency2.value, "custom");
|
||||
assertThat(someCustomScopeDependency1).isNotNull();
|
||||
assertThat(someCustomScopeDependency2).isNotNull();
|
||||
assertThat(someCustomScopeDependency2).isNotEqualTo(someCustomScopeDependency1);
|
||||
assertThat("custom").isEqualTo(someCustomScopeDependency1.value);
|
||||
assertThat("custom").isEqualTo(someCustomScopeDependency2.value);
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.injector.SpringInjector;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SimpleWiringTests {
|
||||
|
||||
@Test
|
||||
public void guiceyFoo() {
|
||||
Injector app = Guice.createInjector(new TestConfig());
|
||||
assertNotNull(app.getInstance(Foo.class));
|
||||
assertThat(app.getInstance(Foo.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +46,7 @@ public class SimpleWiringTests {
|
||||
MyService.class);
|
||||
context.getDefaultListableBeanFactory().registerBeanDefinition(Foo.class.getSimpleName(),
|
||||
new RootBeanDefinition(Foo.class));
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ public class SimpleWiringTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class,
|
||||
ModulesConfig.class);
|
||||
Injector app = new SpringInjector(context);
|
||||
assertNotNull(app.getInstance(Foo.class));
|
||||
assertThat(app.getInstance(Foo.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.injector.SpringInjector;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpringAutowiredCollectionTests {
|
||||
|
||||
@@ -41,8 +41,8 @@ public class SpringAutowiredCollectionTests {
|
||||
|
||||
ServicesHolder servicesHolder = injector.getInstance(ServicesHolder.class);
|
||||
|
||||
assertEquals(2, servicesHolder.existingServices.size());
|
||||
assertEquals(0, servicesHolder.nonExistingServices.size());
|
||||
assertThat(servicesHolder.existingServices).hasSize(2);
|
||||
assertThat(servicesHolder.nonExistingServices).isEmpty();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -33,7 +32,7 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SuperClassTests {
|
||||
|
||||
@@ -55,9 +54,9 @@ public class SuperClassTests {
|
||||
@SuppressWarnings("resource")
|
||||
private void baseTestSpringInterface(Class<?> configClass) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
assertTrue(context.getBean(IParent.class) instanceof IGrandChildImpl);
|
||||
assertTrue(context.getBean(IChild.class) instanceof IGrandChildImpl);
|
||||
assertTrue(context.getBean(IGrandChild.class) instanceof IGrandChildImpl);
|
||||
assertThat(context.getBean(IParent.class) instanceof IGrandChildImpl).isTrue();
|
||||
assertThat(context.getBean(IChild.class) instanceof IGrandChildImpl).isTrue();
|
||||
assertThat(context.getBean(IGrandChild.class) instanceof IGrandChildImpl).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,9 +78,9 @@ public class SuperClassTests {
|
||||
private void baseTestGuiceInterface(Class<?> configClass) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
assertTrue(injector.getInstance(IParent.class) instanceof IGrandChildImpl);
|
||||
assertTrue(injector.getInstance(IChild.class) instanceof IGrandChildImpl);
|
||||
assertTrue(injector.getInstance(IGrandChild.class) instanceof IGrandChildImpl);
|
||||
assertThat(injector.getInstance(IParent.class) instanceof IGrandChildImpl).isTrue();
|
||||
assertThat(injector.getInstance(IChild.class) instanceof IGrandChildImpl).isTrue();
|
||||
assertThat(injector.getInstance(IGrandChild.class) instanceof IGrandChildImpl).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,49 +103,49 @@ public class SuperClassTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
|
||||
String[] allParentBeanNames = context.getBeanNamesForType(IParentWithType.class);
|
||||
Assertions.assertEquals(2, allParentBeanNames.length);
|
||||
assertThat(allParentBeanNames.length).isEqualTo(2);
|
||||
|
||||
String[] stringParentBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IParentWithType.class, String.class));
|
||||
Assertions.assertEquals(1, stringParentBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IGrandChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringParentBeanNames[0])));
|
||||
assertThat(stringParentBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IGrandChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringParentBeanNames[0]))).isTrue();
|
||||
|
||||
String[] integerParentBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IParentWithType.class, Integer.class));
|
||||
Assertions.assertEquals(1, integerParentBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IGrandChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerParentBeanNames[0])));
|
||||
assertThat(integerParentBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IGrandChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerParentBeanNames[0]))).isTrue();
|
||||
|
||||
String[] allChildBeanNames = context.getBeanNamesForType(IChildWithType.class);
|
||||
Assertions.assertEquals(2, allChildBeanNames.length);
|
||||
assertThat(allChildBeanNames.length).isEqualTo(2);
|
||||
|
||||
String[] stringChildBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IChildWithType.class, String.class));
|
||||
Assertions.assertEquals(1, stringChildBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringChildBeanNames[0])));
|
||||
assertThat(stringChildBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringChildBeanNames[0]))).isTrue();
|
||||
|
||||
String[] integerChildBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IChildWithType.class, Integer.class));
|
||||
Assertions.assertEquals(1, integerChildBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerChildBeanNames[0])));
|
||||
assertThat(integerChildBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerChildBeanNames[0]))).isTrue();
|
||||
|
||||
String[] allGrandChildBeanNames = context.getBeanNamesForType(IGrandChildWithType.class);
|
||||
Assertions.assertEquals(2, allGrandChildBeanNames.length);
|
||||
assertThat(allGrandChildBeanNames.length).isEqualTo(2);
|
||||
|
||||
String[] stringGrandChildBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IGrandChildWithType.class, String.class));
|
||||
Assertions.assertEquals(1, stringGrandChildBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IGrandChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringGrandChildBeanNames[0])));
|
||||
assertThat(stringGrandChildBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IGrandChildWithType<String>>() {
|
||||
}.getRawType().isInstance(context.getBean(stringGrandChildBeanNames[0]))).isTrue();
|
||||
|
||||
String[] integerGrandChildBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IGrandChildWithType.class, Integer.class));
|
||||
Assertions.assertEquals(1, integerGrandChildBeanNames.length);
|
||||
assertTrue(new TypeLiteral<IGrandChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerGrandChildBeanNames[0])));
|
||||
assertThat(integerGrandChildBeanNames.length).isEqualTo(1);
|
||||
assertThat(new TypeLiteral<IGrandChildWithType<Integer>>() {
|
||||
}.getRawType().isInstance(context.getBean(integerGrandChildBeanNames[0]))).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@@ -172,28 +171,28 @@ public class SuperClassTests {
|
||||
IParentWithType<String> iParentString = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IParentWithType<String>>() {
|
||||
}));
|
||||
assertTrue(iParentString instanceof IGrandChildString);
|
||||
assertThat(iParentString instanceof IGrandChildString).isTrue();
|
||||
IParentWithType<Integer> iParentInteger = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IParentWithType<Integer>>() {
|
||||
}));
|
||||
assertTrue(iParentInteger instanceof IGrandChildInteger);
|
||||
assertThat(iParentInteger instanceof IGrandChildInteger).isTrue();
|
||||
|
||||
IChildWithType<String> iChildString = injector.getInstance(Key.get(new TypeLiteral<IChildWithType<String>>() {
|
||||
}));
|
||||
assertTrue(iChildString instanceof IGrandChildString);
|
||||
assertThat(iChildString instanceof IGrandChildString).isTrue();
|
||||
IChildWithType<Integer> iChildInteger = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IChildWithType<Integer>>() {
|
||||
}));
|
||||
assertTrue(iChildInteger instanceof IGrandChildInteger);
|
||||
assertThat(iChildInteger instanceof IGrandChildInteger).isTrue();
|
||||
|
||||
IGrandChildWithType<String> iGrandChildString = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IGrandChildWithType<String>>() {
|
||||
}));
|
||||
assertTrue(iGrandChildString instanceof IGrandChildString);
|
||||
assertThat(iGrandChildString instanceof IGrandChildString).isTrue();
|
||||
IGrandChildWithType<Integer> iGrandChildInteger = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IGrandChildWithType<Integer>>() {
|
||||
}));
|
||||
assertTrue(iGrandChildInteger instanceof IGrandChildInteger);
|
||||
assertThat(iGrandChildInteger instanceof IGrandChildInteger).isTrue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@@ -201,11 +200,11 @@ public class SuperClassTests {
|
||||
public void testSpringClass() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ModulesConfig.class);
|
||||
IFoo iFoo = context.getBean(IFoo.class);
|
||||
assertTrue(iFoo instanceof Foo);
|
||||
assertTrue(iFoo instanceof SubFoo);
|
||||
assertThat(iFoo instanceof Foo).isTrue();
|
||||
assertThat(iFoo instanceof SubFoo).isTrue();
|
||||
|
||||
Foo foo = context.getBean(Foo.class);
|
||||
assertTrue(foo instanceof SubFoo);
|
||||
assertThat(foo instanceof SubFoo).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,11 +227,11 @@ public class SuperClassTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
IFoo iFoo = injector.getInstance(IFoo.class);
|
||||
assertTrue(iFoo instanceof Foo);
|
||||
assertTrue(iFoo instanceof SubFoo);
|
||||
assertThat(iFoo instanceof Foo).isTrue();
|
||||
assertThat(iFoo instanceof SubFoo).isTrue();
|
||||
|
||||
Foo foo = injector.getInstance(Foo.class);
|
||||
assertTrue(foo instanceof SubFoo);
|
||||
assertThat(foo instanceof SubFoo).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,25 +254,25 @@ public class SuperClassTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
String[] stringBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IFooWithType.class, String.class));
|
||||
Assertions.assertEquals(1, stringBeanNames.length);
|
||||
assertTrue(context.getBean(stringBeanNames[0]) instanceof StringFoo);
|
||||
assertTrue(context.getBean(stringBeanNames[0]) instanceof SubStringFoo);
|
||||
assertThat(stringBeanNames.length).isEqualTo(1);
|
||||
assertThat(context.getBean(stringBeanNames[0]) instanceof StringFoo).isTrue();
|
||||
assertThat(context.getBean(stringBeanNames[0]) instanceof SubStringFoo).isTrue();
|
||||
|
||||
stringBeanNames = context.getBeanNamesForType(StringFoo.class);
|
||||
Assertions.assertEquals(1, stringBeanNames.length);
|
||||
assertTrue(context.getBean(stringBeanNames[0]) instanceof StringFoo);
|
||||
assertTrue(context.getBean(stringBeanNames[0]) instanceof SubStringFoo);
|
||||
assertThat(stringBeanNames.length).isEqualTo(1);
|
||||
assertThat(context.getBean(stringBeanNames[0]) instanceof StringFoo).isTrue();
|
||||
assertThat(context.getBean(stringBeanNames[0]) instanceof SubStringFoo).isTrue();
|
||||
|
||||
String[] integerBeanNames = context
|
||||
.getBeanNamesForType(ResolvableType.forClassWithGenerics(IFooWithType.class, Integer.class));
|
||||
Assertions.assertEquals(1, integerBeanNames.length);
|
||||
assertTrue(context.getBean(integerBeanNames[0]) instanceof IntegerFoo);
|
||||
assertTrue(context.getBean(integerBeanNames[0]) instanceof SubIntegerFoo);
|
||||
assertThat(integerBeanNames.length).isEqualTo(1);
|
||||
assertThat(context.getBean(integerBeanNames[0]) instanceof IntegerFoo).isTrue();
|
||||
assertThat(context.getBean(integerBeanNames[0]) instanceof SubIntegerFoo).isTrue();
|
||||
|
||||
integerBeanNames = context.getBeanNamesForType(IntegerFoo.class);
|
||||
Assertions.assertEquals(1, integerBeanNames.length);
|
||||
assertTrue(context.getBean(integerBeanNames[0]) instanceof IntegerFoo);
|
||||
assertTrue(context.getBean(integerBeanNames[0]) instanceof SubIntegerFoo);
|
||||
assertThat(integerBeanNames.length).isEqualTo(1);
|
||||
assertThat(context.getBean(integerBeanNames[0]) instanceof IntegerFoo).isTrue();
|
||||
assertThat(context.getBean(integerBeanNames[0]) instanceof SubIntegerFoo).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -298,20 +297,20 @@ public class SuperClassTests {
|
||||
|
||||
IFooWithType<String> iFooWithTypeString = injector.getInstance(Key.get(new TypeLiteral<IFooWithType<String>>() {
|
||||
}));
|
||||
assertTrue(iFooWithTypeString instanceof StringFoo);
|
||||
assertTrue(iFooWithTypeString instanceof SubStringFoo);
|
||||
assertThat(iFooWithTypeString instanceof StringFoo).isTrue();
|
||||
assertThat(iFooWithTypeString instanceof SubStringFoo).isTrue();
|
||||
|
||||
StringFoo stringFoo = injector.getInstance(StringFoo.class);
|
||||
assertTrue(stringFoo instanceof SubStringFoo);
|
||||
assertThat(stringFoo instanceof SubStringFoo).isTrue();
|
||||
|
||||
IFooWithType<Integer> iFooWithTypeInteger = injector
|
||||
.getInstance(Key.get(new TypeLiteral<IFooWithType<Integer>>() {
|
||||
}));
|
||||
assertTrue(iFooWithTypeInteger instanceof IntegerFoo);
|
||||
assertTrue(iFooWithTypeInteger instanceof SubIntegerFoo);
|
||||
assertThat(iFooWithTypeInteger instanceof IntegerFoo).isTrue();
|
||||
assertThat(iFooWithTypeInteger instanceof SubIntegerFoo).isTrue();
|
||||
|
||||
IntegerFoo integerFoo = injector.getInstance(IntegerFoo.class);
|
||||
assertTrue(integerFoo instanceof SubIntegerFoo);
|
||||
assertThat(integerFoo instanceof SubIntegerFoo).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -334,7 +333,7 @@ public class SuperClassTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
|
||||
Bar bar = context.getBean(Bar.class);
|
||||
assertTrue(bar instanceof Bar);
|
||||
assertThat(bar instanceof Bar).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -356,7 +355,7 @@ public class SuperClassTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||
Injector injector = context.getBean(Injector.class);
|
||||
Bar bar = injector.getInstance(Bar.class);
|
||||
assertTrue(bar instanceof Bar);
|
||||
assertThat(bar instanceof Bar).isTrue();
|
||||
}
|
||||
|
||||
static class DisableJITConfig {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -49,7 +49,7 @@ public class EnableGuiceModulesTests {
|
||||
@Test
|
||||
public void test() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -57,28 +57,28 @@ public class EnableGuiceModulesTests {
|
||||
public void testWithDedupFeatureEnabled() {
|
||||
System.setProperty("spring.guice.dedup", "true");
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void module() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ModuleConfig.class);
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleBean() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ModuleBeanConfig.class);
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjectorCreationDoesNotCauseCircularDependencyError() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MySpringConfig.class);
|
||||
assertNotNull(context.getBean(SpringProvidedBean.class));
|
||||
assertThat(context.getBean(SpringProvidedBean.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class GuiceModuleAnnotationGenericTypeTests {
|
||||
|
||||
@Test
|
||||
public void testBinding() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
|
||||
assertNotNull(context.getBean(Foo.class));
|
||||
assertThat(context.getBean(Foo.class)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.guice.module.SpringModule;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -44,44 +44,44 @@ public class GuiceModuleAnnotationTests {
|
||||
@Test
|
||||
public void includes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludesConfig.class);
|
||||
assertNotNull(injector.getBinding(Service.class));
|
||||
assertThat(injector.getBinding(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesNames() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludeNamesConfig.class);
|
||||
assertNotNull(injector.getBinding(Service.class));
|
||||
assertThat(injector.getBinding(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesPatterns() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludePatternsConfig.class);
|
||||
assertNotNull(injector.getBinding(Service.class));
|
||||
assertThat(injector.getBinding(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataExcludesConfig.class);
|
||||
assertThrows(ConfigurationException.class, () -> injector.getInstance(Service.class));
|
||||
assertThatExceptionOfType(ConfigurationException.class).isThrownBy(() -> injector.getInstance(Service.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludesNames() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataExcludeNamesConfig.class);
|
||||
assertThrows(ConfigurationException.class, () -> injector.getBinding(Service.class));
|
||||
assertThatExceptionOfType(ConfigurationException.class).isThrownBy(() -> injector.getBinding(Service.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludesPatterns() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataExcludePatternsConfig.class);
|
||||
assertThrows(ConfigurationException.class, () -> injector.getBinding(Service.class));
|
||||
assertThatExceptionOfType(ConfigurationException.class).isThrownBy(() -> injector.getBinding(Service.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoIncludes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludesConfig.class,
|
||||
MetadataMoreIncludesConfig.class);
|
||||
assertNotNull(injector.getBinding(Service.class));
|
||||
assertThat(injector.getBinding(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
private Injector createInjector(Class<?>... config) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.AbstractCompleteWiringTests;
|
||||
import org.springframework.guice.injector.SpringInjector;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -52,7 +52,7 @@ public class ModuleBeanWiringTests extends AbstractCompleteWiringTests {
|
||||
|
||||
@Test
|
||||
public void bindToSpringBeanFromGuiceModule() throws Exception {
|
||||
assertNotNull(this.context.getBean(Spam.class));
|
||||
assertThat(this.context.getBean(Spam.class)).isNotNull();
|
||||
}
|
||||
|
||||
@EnableGuiceModules
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.AbstractCompleteWiringTests;
|
||||
import org.springframework.guice.injector.SpringInjector;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -52,7 +52,7 @@ public class ModuleNamedBeanWiringTests extends AbstractCompleteWiringTests {
|
||||
|
||||
@Test
|
||||
public void bindToSpringBeanFromGuiceModule() throws Exception {
|
||||
assertNotNull(this.context.getBean(Spam.class));
|
||||
assertThat(this.context.getBean(Spam.class)).isNotNull();
|
||||
}
|
||||
|
||||
@EnableGuiceModules
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.guice.AbstractCompleteWiringTests.Baz;
|
||||
import org.springframework.guice.AbstractCompleteWiringTests.MyService;
|
||||
import org.springframework.guice.AbstractCompleteWiringTests.Service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class SpringInjectorTests {
|
||||
|
||||
@@ -48,29 +48,30 @@ public class SpringInjectorTests {
|
||||
|
||||
@Test
|
||||
public void instance() {
|
||||
assertNotNull(this.injector.getInstance(Service.class));
|
||||
assertThat(this.injector.getInstance(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiple() {
|
||||
this.injector = new SpringInjector(create(Additional.class));
|
||||
assertThrows(NoUniqueBeanDefinitionException.class, () -> this.injector.getInstance(Service.class));
|
||||
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.injector.getInstance(Service.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void named() {
|
||||
this.injector = new SpringInjector(create(Additional.class));
|
||||
assertNotNull(this.injector.getInstance(Key.get(Service.class, Names.named("service"))));
|
||||
assertThat(this.injector.getInstance(Key.get(Service.class, Names.named("service")))).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provider() {
|
||||
assertNotNull(this.injector.getProvider(Service.class).get());
|
||||
assertThat(this.injector.getProvider(Service.class).get()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindNewObject() {
|
||||
assertNotNull(this.injector.getInstance(Baz.class));
|
||||
assertThat(this.injector.getInstance(Baz.class)).isNotNull();
|
||||
}
|
||||
|
||||
private ApplicationContext create(Class<?>... config) {
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
import org.springframework.guice.annotation.InjectorFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DevelepmentStageInjectorTest {
|
||||
|
||||
@@ -55,9 +54,9 @@ public class DevelepmentStageInjectorTest {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
DevelepmentStageInjectorTest.ModulesConfig.class);
|
||||
TestGuiceModule testGuiceModule = context.getBean(TestGuiceModule.class);
|
||||
assertFalse(testGuiceModule.getProviderExecuted());
|
||||
assertThat(testGuiceModule.getProviderExecuted()).isFalse();
|
||||
GuiceToken guiceToken = context.getBean(GuiceToken.class);
|
||||
assertTrue(testGuiceModule.getProviderExecuted());
|
||||
assertThat(testGuiceModule.getProviderExecuted()).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.util.AopTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpringModuleGuiceBindingAwareTests {
|
||||
|
||||
@@ -43,26 +41,26 @@ public class SpringModuleGuiceBindingAwareTests {
|
||||
new SpringModule(BeanFactoryProvider.from(GuiceProjectWithSpringLibraryTestSpringConfig.class)));
|
||||
|
||||
// check guice provided bindings
|
||||
assertNotNull(injector.getInstance(GuiceDependency1.class));
|
||||
assertNotNull(injector.getInstance(IGuiceDependency1.class));
|
||||
assertThat(injector.getInstance(GuiceDependency1.class)).isNotNull();
|
||||
assertThat(injector.getInstance(IGuiceDependency1.class)).isNotNull();
|
||||
|
||||
// check spring bindings as interface
|
||||
ISpringBean springBean = injector.getInstance(ISpringBean.class);
|
||||
assertNotNull(springBean);
|
||||
assertNotNull(springBean.getDep1());
|
||||
assertNotNull(springBean.getDep2());
|
||||
assertNotNull(springBean.getDep3());
|
||||
assertThat(springBean).isNotNull();
|
||||
assertThat(springBean.getDep1()).isNotNull();
|
||||
assertThat(springBean.getDep2()).isNotNull();
|
||||
assertThat(springBean.getDep3()).isNotNull();
|
||||
|
||||
// invoke a method to make sure we aren't dealing with a lazy proxy
|
||||
assertEquals("done", springBean.getDep1().doWork());
|
||||
assertThat(springBean.getDep1().doWork()).isEqualTo("done");
|
||||
|
||||
// check binding equality
|
||||
assertSame(injector.getInstance(IGuiceDependency1.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep1()));
|
||||
assertSame(injector.getInstance(IGuiceDependency2.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep2()));
|
||||
assertSame(injector.getInstance(IGuiceDependency3.class),
|
||||
AopTestUtils.getTargetObject(springBean.getDep3()));
|
||||
assertThat(injector.getInstance(IGuiceDependency1.class))
|
||||
.isSameAs(AopTestUtils.getTargetObject(springBean.getDep1()));
|
||||
assertThat(injector.getInstance(IGuiceDependency2.class))
|
||||
.isSameAs(AopTestUtils.getTargetObject(springBean.getDep2()));
|
||||
assertThat(injector.getInstance(IGuiceDependency3.class))
|
||||
.isSameAs(AopTestUtils.getTargetObject(springBean.getDep3()));
|
||||
}
|
||||
|
||||
static class SimpleGuiceModule extends AbstractModule {
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.name.Names;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -35,8 +34,8 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -47,37 +46,40 @@ public class SpringModuleMetadataTests {
|
||||
@Test
|
||||
public void twoConfigClasses() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, OtherConfig.class);
|
||||
assertNotNull(injector.getInstance(Service.class));
|
||||
assertThat(injector.getInstance(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoServices() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MoreConfig.class);
|
||||
assertThrows(ProvisionException.class, () -> assertNotNull(injector.getInstance(Service.class)));
|
||||
assertThatExceptionOfType(ProvisionException.class)
|
||||
.isThrownBy(() -> assertThat(injector.getInstance(Service.class)).isNotNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoServicesOnePrimary() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, PrimaryConfig.class);
|
||||
assertNotNull(injector.getInstance(Service.class));
|
||||
assertThat(injector.getInstance(Service.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoServicesByName() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MoreConfig.class);
|
||||
assertNotNull(injector.getInstance(Key.get(Service.class, Names.named("service"))));
|
||||
assertThat(injector.getInstance(Key.get(Service.class, Names.named("service")))).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataIncludesConfig.class);
|
||||
assertThrows(ConfigurationException.class, () -> Assertions.assertNull(injector.getBinding(Service.class)));
|
||||
assertThatExceptionOfType(ConfigurationException.class)
|
||||
.isThrownBy(() -> assertThat(injector.getBinding(Service.class)).isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludes() throws Exception {
|
||||
Injector injector = createInjector(TestConfig.class, MetadataExcludesConfig.class);
|
||||
assertThrows(ConfigurationException.class, () -> Assertions.assertNull(injector.getBinding(Service.class)));
|
||||
assertThatExceptionOfType(ConfigurationException.class)
|
||||
.isThrownBy(() -> assertThat(injector.getBinding(Service.class)).isNull());
|
||||
}
|
||||
|
||||
private Injector createInjector(Class<?>... config) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.guice.annotation.EnableGuiceModules;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpringModuleWrappedTests {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SpringModuleWrappedTests {
|
||||
public void testDependenciesFromWrappedModule() {
|
||||
Injector injector = Guice.createInjector(
|
||||
new SpringModule(BeanFactoryProvider.from(TestConfig.class, ModuleProviderConfig.class)));
|
||||
assertNotNull(injector.getInstance(Baz.class));
|
||||
assertThat(injector.getInstance(Baz.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user