diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java index 844cbc44281..b0820f5d9c3 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java @@ -20,8 +20,7 @@ import java.util.Collections; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link AuditEvent}. @@ -34,17 +33,17 @@ public class AuditEventTests { public void testNowEvent() throws Exception { AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b")); - assertEquals("b", event.getData().get("a")); - assertEquals("UNKNOWN", event.getType()); - assertEquals("phil", event.getPrincipal()); - assertNotNull(event.getTimestamp()); + assertThat(event.getData().get("a")).isEqualTo("b"); + assertThat(event.getType()).isEqualTo("UNKNOWN"); + assertThat(event.getPrincipal()).isEqualTo("phil"); + assertThat(event.getTimestamp()).isNotNull(); } @Test public void testConvertStringsToData() throws Exception { AuditEvent event = new AuditEvent("phil", "UNKNOWN", "a=b", "c=d"); - assertEquals("b", event.getData().get("a")); - assertEquals("d", event.getData().get("c")); + assertThat(event.getData().get("a")).isEqualTo("b"); + assertThat(event.getData().get("c")).isEqualTo("d"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java index 0383e03051d..4c7f05f3eeb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java @@ -24,8 +24,7 @@ import java.util.Map; import org.junit.Test; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link InMemoryAuditEventRepository}. @@ -41,9 +40,9 @@ public class InMemoryAuditEventRepositoryTests { repository.add(new AuditEvent("dave", "a")); repository.add(new AuditEvent("dave", "b")); List events = repository.find("dave", null); - assertThat(events.size(), equalTo(2)); - assertThat(events.get(0).getType(), equalTo("a")); - assertThat(events.get(1).getType(), equalTo("b")); + assertThat(events.size()).isEqualTo(2); + assertThat(events.get(0).getType()).isEqualTo("a"); + assertThat(events.get(1).getType()).isEqualTo("b"); } @@ -54,9 +53,9 @@ public class InMemoryAuditEventRepositoryTests { repository.add(new AuditEvent("dave", "b")); repository.add(new AuditEvent("dave", "c")); List events = repository.find("dave", null); - assertThat(events.size(), equalTo(2)); - assertThat(events.get(0).getType(), equalTo("b")); - assertThat(events.get(1).getType(), equalTo("c")); + assertThat(events.size()).isEqualTo(2); + assertThat(events.get(0).getType()).isEqualTo("b"); + assertThat(events.get(1).getType()).isEqualTo("c"); } @Test @@ -67,9 +66,9 @@ public class InMemoryAuditEventRepositoryTests { repository.add(new AuditEvent("dave", "c")); repository.add(new AuditEvent("phil", "d")); List events = repository.find("dave", null); - assertThat(events.size(), equalTo(2)); - assertThat(events.get(0).getType(), equalTo("a")); - assertThat(events.get(1).getType(), equalTo("c")); + assertThat(events.size()).isEqualTo(2); + assertThat(events.get(0).getType()).isEqualTo("a"); + assertThat(events.get(1).getType()).isEqualTo("c"); } @Test @@ -89,12 +88,12 @@ public class InMemoryAuditEventRepositoryTests { repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data)); calendar.add(Calendar.DAY_OF_YEAR, 1); List events = repository.find(null, after); - assertThat(events.size(), equalTo(2)); - assertThat(events.get(0).getType(), equalTo("c")); - assertThat(events.get(1).getType(), equalTo("d")); + assertThat(events.size()).isEqualTo(2); + assertThat(events.get(0).getType()).isEqualTo("c"); + assertThat(events.get(1).getType()).isEqualTo("d"); events = repository.find("dave", after); - assertThat(events.size(), equalTo(1)); - assertThat(events.get(0).getType(), equalTo("c")); + assertThat(events.size()).isEqualTo(1); + assertThat(events.get(0).getType()).isEqualTo("c"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java index 4bae931068e..7c3ea637ac0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java @@ -31,9 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.access.event.AbstractAuthorizationEvent; import org.springframework.security.authentication.event.AbstractAuthenticationEvent; -import static org.hamcrest.Matchers.instanceOf; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link AuditAutoConfiguration}. @@ -48,33 +46,33 @@ public class AuditAutoConfigurationTests { @Test public void testTraceConfiguration() throws Exception { registerAndRefresh(AuditAutoConfiguration.class); - assertNotNull(this.context.getBean(AuditEventRepository.class)); - assertNotNull(this.context.getBean(AuthenticationAuditListener.class)); - assertNotNull(this.context.getBean(AuthorizationAuditListener.class)); + assertThat(this.context.getBean(AuditEventRepository.class)).isNotNull(); + assertThat(this.context.getBean(AuthenticationAuditListener.class)).isNotNull(); + assertThat(this.context.getBean(AuthorizationAuditListener.class)).isNotNull(); } @Test public void ownAutoRepository() throws Exception { registerAndRefresh(CustomAuditEventRepositoryConfiguration.class, AuditAutoConfiguration.class); - assertThat(this.context.getBean(AuditEventRepository.class), - instanceOf(TestAuditEventRepository.class)); + assertThat(this.context.getBean(AuditEventRepository.class)) + .isInstanceOf(TestAuditEventRepository.class); } @Test public void ownAuthenticationAuditListener() throws Exception { registerAndRefresh(CustomAuthenticationAuditListenerConfiguration.class, AuditAutoConfiguration.class); - assertThat(this.context.getBean(AbstractAuthenticationAuditListener.class), - instanceOf(TestAuthenticationAuditListener.class)); + assertThat(this.context.getBean(AbstractAuthenticationAuditListener.class)) + .isInstanceOf(TestAuthenticationAuditListener.class); } @Test public void ownAuthorizationAuditListener() throws Exception { registerAndRefresh(CustomAuthorizationAuditListenerConfiguration.class, AuditAutoConfiguration.class); - assertThat(this.context.getBean(AbstractAuthorizationAuditListener.class), - instanceOf(TestAuthorizationAuditListener.class)); + assertThat(this.context.getBean(AbstractAuthorizationAuditListener.class)) + .isInstanceOf(TestAuthorizationAuditListener.class); } private void registerAndRefresh(Class... annotatedClasses) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CacheStatisticsAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CacheStatisticsAutoConfigurationTests.java index 9025d375c4e..6c350fbf139 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CacheStatisticsAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CacheStatisticsAutoConfigurationTests.java @@ -53,8 +53,8 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.util.Assert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; /** * Tests for {@link CacheStatisticsAutoConfiguration}. @@ -160,8 +160,8 @@ public class CacheStatisticsAutoConfigurationTests { private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio, Double missRatio) { - assertNotNull("Cache metrics must not be null", metrics); - assertEquals("Wrong size for metrics " + metrics, size, metrics.getSize()); + assertThat(metrics).isNotNull(); + assertThat(metrics.getSize()).isEqualTo(size); checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio, metrics.getHitRatio()); checkRatio("Wrong miss ratio for metrics " + metrics, missRatio, @@ -170,10 +170,10 @@ public class CacheStatisticsAutoConfigurationTests { private void checkRatio(String message, Double expected, Double actual) { if (expected == null || actual == null) { - assertEquals(message, expected, actual); + assertThat(actual).as(message).isEqualTo(expected); } else { - assertEquals(message, expected, actual, 0.01D); + assertThat(actual).as(message).isEqualTo(expected, offset(0.01D)); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java index b0fce565e4b..5684852049f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java @@ -51,11 +51,7 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link CrshAutoConfiguration}. @@ -82,13 +78,12 @@ public class CrshAutoConfigurationTests { env.setProperty("shell.disabled_plugins", "GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin"); load(env); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - assertNotNull(lifeCycle); - - assertNull(lifeCycle.getContext().getPlugin(GroovyRepl.class)); - assertNull(lifeCycle.getContext().getPlugin(ProcessorIOHandler.class)); - assertNull(lifeCycle.getContext().getPlugin(JaasAuthenticationPlugin.class)); + assertThat(lifeCycle).isNotNull(); + assertThat(lifeCycle.getContext().getPlugin(GroovyRepl.class)).isNull(); + assertThat(lifeCycle.getContext().getPlugin(ProcessorIOHandler.class)).isNull(); + assertThat(lifeCycle.getContext().getPlugin(JaasAuthenticationPlugin.class)) + .isNull(); } @Test @@ -96,13 +91,12 @@ public class CrshAutoConfigurationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - Map attributes = lifeCycle.getContext().getAttributes(); - assertTrue(attributes.containsKey("spring.version")); - assertTrue(attributes.containsKey("spring.beanfactory")); - assertEquals(this.context.getBeanFactory(), attributes.get("spring.beanfactory")); + assertThat(attributes.containsKey("spring.version")).isTrue(); + assertThat(attributes.containsKey("spring.beanfactory")).isTrue(); + assertThat(attributes.get("spring.beanfactory")) + .isEqualTo(this.context.getBeanFactory()); } @Test @@ -113,12 +107,11 @@ public class CrshAutoConfigurationTests { load(env); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - - assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port")); - assertEquals("600000", - lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout")); - assertEquals("600000", - lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.port")).isEqualTo("3333"); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout")) + .isEqualTo("600000"); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")) + .isEqualTo("600000"); } @Test @@ -127,11 +120,9 @@ public class CrshAutoConfigurationTests { env.setProperty("shell.ssh.enabled", "true"); env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem"); load(env); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - - assertEquals("~/.ssh/id.pem", - lifeCycle.getConfig().getProperty("crash.ssh.keypath")); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.keypath")) + .isEqualTo("~/.ssh/id.pem"); } @Test @@ -141,13 +132,11 @@ public class CrshAutoConfigurationTests { env.setProperty("shell.ssh.auth-timeout", "300000"); env.setProperty("shell.ssh.idle-timeout", "400000"); load(env); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - - assertEquals("300000", - lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout")); - assertEquals("400000", - lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout")) + .isEqualTo("300000"); + assertThat(lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")) + .isEqualTo("400000"); } private void load(MockEnvironment env) { @@ -162,9 +151,7 @@ public class CrshAutoConfigurationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - int count = 0; Iterator resources = lifeCycle.getContext() .loadResources("login", ResourceKind.LIFECYCLE).iterator(); @@ -172,8 +159,7 @@ public class CrshAutoConfigurationTests { count++; resources.next(); } - assertEquals(1, count); - + assertThat(count).isEqualTo(1); count = 0; resources = lifeCycle.getContext() .loadResources("sleep.groovy", ResourceKind.COMMAND).iterator(); @@ -181,7 +167,7 @@ public class CrshAutoConfigurationTests { count++; resources.next(); } - assertEquals(1, count); + assertThat(count).isEqualTo(1); } @Test @@ -189,9 +175,7 @@ public class CrshAutoConfigurationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - int count = 0; Iterator resources = lifeCycle.getContext() .loadResources("jdbc.groovy", ResourceKind.COMMAND).iterator(); @@ -199,7 +183,7 @@ public class CrshAutoConfigurationTests { count++; resources.next(); } - assertEquals(0, count); + assertThat(count).isEqualTo(0); } @Test @@ -209,10 +193,8 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginContext pluginContext = lifeCycle.getContext(); - int count = 0; Iterator plugins = pluginContext .getPlugins(AuthenticationPlugin.class).iterator(); @@ -220,7 +202,7 @@ public class CrshAutoConfigurationTests { count++; plugins.next(); } - assertEquals(3, count); + assertThat(count).isEqualTo(3); } @Test @@ -231,9 +213,8 @@ public class CrshAutoConfigurationTests { this.context.setServletContext(new MockServletContext()); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - assertEquals("simple", lifeCycle.getConfig().get("crash.auth")); + assertThat(lifeCycle.getConfig().get("crash.auth")).isEqualTo("simple"); } @Test @@ -247,11 +228,10 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - assertEquals("jaas", lifeCycle.getConfig().get("crash.auth")); - assertEquals("my-test-domain", - lifeCycle.getConfig().get("crash.auth.jaas.domain")); + assertThat(lifeCycle.getConfig().get("crash.auth")).isEqualTo("jaas"); + assertThat(lifeCycle.getConfig().get("crash.auth.jaas.domain")) + .isEqualTo("my-test-domain"); } @Test @@ -265,10 +245,10 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - assertEquals("key", lifeCycle.getConfig().get("crash.auth")); - assertEquals("~/test.pem", lifeCycle.getConfig().get("crash.auth.key.path")); + assertThat(lifeCycle.getConfig().get("crash.auth")).isEqualTo("key"); + assertThat(lifeCycle.getConfig().get("crash.auth.key.path")) + .isEqualTo("~/test.pem"); } @Test @@ -283,13 +263,11 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - assertEquals("simple", lifeCycle.getConfig().get("crash.auth")); - + assertThat(lifeCycle.getConfig().get("crash.auth")).isEqualTo("simple"); AuthenticationPlugin authenticationPlugin = null; String authentication = lifeCycle.getConfig().getProperty("crash.auth"); - assertNotNull(authentication); + assertThat(authentication).isNotNull(); for (AuthenticationPlugin plugin : lifeCycle.getContext() .getPlugins(AuthenticationPlugin.class)) { if (authentication.equals(plugin.getName())) { @@ -297,10 +275,10 @@ public class CrshAutoConfigurationTests { break; } } - assertNotNull(authenticationPlugin); - assertTrue(authenticationPlugin.authenticate("user", "password")); - assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), - "password")); + assertThat(authenticationPlugin).isNotNull(); + assertThat(authenticationPlugin.authenticate("user", "password")).isTrue(); + assertThat(authenticationPlugin.authenticate(UUID.randomUUID().toString(), + "password")).isFalse(); } @Test @@ -313,12 +291,10 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - AuthenticationPlugin authenticationPlugin = null; String authentication = lifeCycle.getConfig().getProperty("crash.auth"); - assertNotNull(authentication); + assertThat(authentication).isNotNull(); for (AuthenticationPlugin plugin : lifeCycle.getContext() .getPlugins(AuthenticationPlugin.class)) { if (authentication.equals(plugin.getName())) { @@ -326,11 +302,10 @@ public class CrshAutoConfigurationTests { break; } } - assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, - SecurityConfiguration.PASSWORD)); - - assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), - SecurityConfiguration.PASSWORD)); + assertThat(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, + SecurityConfiguration.PASSWORD)).isTrue(); + assertThat(authenticationPlugin.authenticate(UUID.randomUUID().toString(), + SecurityConfiguration.PASSWORD)).isFalse(); } @Test @@ -343,12 +318,10 @@ public class CrshAutoConfigurationTests { this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); - PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); - AuthenticationPlugin authenticationPlugin = null; String authentication = lifeCycle.getConfig().getProperty("crash.auth"); - assertNotNull(authentication); + assertThat(authentication).isNotNull(); for (AuthenticationPlugin plugin : lifeCycle.getContext() .getPlugins(AuthenticationPlugin.class)) { if (authentication.equals(plugin.getName())) { @@ -356,11 +329,10 @@ public class CrshAutoConfigurationTests { break; } } - assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, - SecurityConfiguration.PASSWORD)); - - assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), - SecurityConfiguration.PASSWORD)); + assertThat(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, + SecurityConfiguration.PASSWORD)).isTrue(); + assertThat(authenticationPlugin.authenticate(UUID.randomUUID().toString(), + SecurityConfiguration.PASSWORD)).isFalse(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java index e171e0e1207..3bc2b3eef94 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java @@ -47,10 +47,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EndpointAutoConfiguration}. @@ -76,15 +73,15 @@ public class EndpointAutoConfigurationTests { @Test public void endpoints() throws Exception { load(EndpointAutoConfiguration.class); - assertNotNull(this.context.getBean(BeansEndpoint.class)); - assertNotNull(this.context.getBean(DumpEndpoint.class)); - assertNotNull(this.context.getBean(EnvironmentEndpoint.class)); - assertNotNull(this.context.getBean(HealthEndpoint.class)); - assertNotNull(this.context.getBean(InfoEndpoint.class)); - assertNotNull(this.context.getBean(MetricsEndpoint.class)); - assertNotNull(this.context.getBean(ShutdownEndpoint.class)); - assertNotNull(this.context.getBean(TraceEndpoint.class)); - assertNotNull(this.context.getBean(RequestMappingEndpoint.class)); + assertThat(this.context.getBean(BeansEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(DumpEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(EnvironmentEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(HealthEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(InfoEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(MetricsEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(ShutdownEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(TraceEndpoint.class)).isNotNull(); + assertThat(this.context.getBean(RequestMappingEndpoint.class)).isNotNull(); } @Test @@ -92,19 +89,19 @@ public class EndpointAutoConfigurationTests { load(EmbeddedDataSourceConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); HealthEndpoint bean = this.context.getBean(HealthEndpoint.class); - assertNotNull(bean); + assertThat(bean).isNotNull(); Health result = bean.invoke(); - assertNotNull(result); - assertTrue("Wrong result: " + result, result.getDetails().containsKey("db")); + assertThat(result).isNotNull(); + assertThat(result.getDetails().containsKey("db")).isTrue(); } @Test public void healthEndpointWithDefaultHealthIndicator() { load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); HealthEndpoint bean = this.context.getBean(HealthEndpoint.class); - assertNotNull(bean); + assertThat(bean).isNotNull(); Health result = bean.invoke(); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -112,8 +109,8 @@ public class EndpointAutoConfigurationTests { load(PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); Map metrics = endpoint.invoke(); - assertTrue(metrics.containsKey("mem")); - assertTrue(metrics.containsKey("heap.used")); + assertThat(metrics.containsKey("mem")).isTrue(); + assertThat(metrics.containsKey("heap.used")).isTrue(); } @Test @@ -124,18 +121,19 @@ public class EndpointAutoConfigurationTests { Map metrics = endpoint.invoke(); // Custom metrics - assertTrue(metrics.containsKey("foo")); + assertThat(metrics.containsKey("foo")).isTrue(); // System metrics still available - assertTrue(metrics.containsKey("mem")); - assertTrue(metrics.containsKey("heap.used")); + assertThat(metrics.containsKey("mem")).isTrue(); + assertThat(metrics.containsKey("heap.used")).isTrue(); } @Test public void autoConfigurationAuditEndpoints() { load(EndpointAutoConfiguration.class, ConditionEvaluationReport.class); - assertNotNull(this.context.getBean(AutoConfigurationReportEndpoint.class)); + assertThat(this.context.getBean(AutoConfigurationReportEndpoint.class)) + .isNotNull(); } @Test @@ -145,9 +143,9 @@ public class EndpointAutoConfigurationTests { this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); - assertNotNull(endpoint); - assertNotNull(endpoint.invoke().get("git")); - assertEquals("bar", endpoint.invoke().get("foo")); + assertThat(endpoint).isNotNull(); + assertThat(endpoint.invoke().get("git")).isNotNull(); + assertThat(endpoint.invoke().get("foo")).isEqualTo("bar"); } @Test @@ -158,8 +156,8 @@ public class EndpointAutoConfigurationTests { this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); - assertNotNull(endpoint); - assertNull(endpoint.invoke().get("git")); + assertThat(endpoint).isNotNull(); + assertThat(endpoint.invoke().get("git")).isNull(); } @Test @@ -169,8 +167,8 @@ public class EndpointAutoConfigurationTests { FlywayAutoConfiguration.class, EndpointAutoConfiguration.class); this.context.refresh(); FlywayEndpoint endpoint = this.context.getBean(FlywayEndpoint.class); - assertNotNull(endpoint); - assertEquals(1, endpoint.invoke().size()); + assertThat(endpoint).isNotNull(); + assertThat(endpoint.invoke()).hasSize(1); } @Test @@ -180,8 +178,8 @@ public class EndpointAutoConfigurationTests { LiquibaseAutoConfiguration.class, EndpointAutoConfiguration.class); this.context.refresh(); LiquibaseEndpoint endpoint = this.context.getBean(LiquibaseEndpoint.class); - assertNotNull(endpoint); - assertEquals(1, endpoint.invoke().size()); + assertThat(endpoint).isNotNull(); + assertThat(endpoint.invoke()).hasSize(1); } private void load(Class... config) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java index 62c6c22d7dc..de974e32fb8 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMBeanExportAutoConfigurationTests.java @@ -43,10 +43,7 @@ import org.springframework.mock.env.MockEnvironment; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EndpointMBeanExportAutoConfiguration}. @@ -71,11 +68,10 @@ public class EndpointMBeanExportAutoConfigurationTests { EndpointMBeanExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); + assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - - assertFalse(mbeanExporter.getServer() - .queryNames(getObjectName("*", "*,*", this.context), null).isEmpty()); + assertThat(mbeanExporter.getServer() + .queryNames(getObjectName("*", "*,*", this.context), null)).isNotEmpty(); } @Test @@ -86,12 +82,10 @@ public class EndpointMBeanExportAutoConfigurationTests { ManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); - + assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - - assertTrue(mbeanExporter.getServer() - .queryNames(getObjectName("*", "*,*", this.context), null).isEmpty()); + assertThat(mbeanExporter.getServer() + .queryNames(getObjectName("*", "*,*", this.context), null)).isEmpty(); } @Test @@ -102,12 +96,10 @@ public class EndpointMBeanExportAutoConfigurationTests { NestedInManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); - + assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - - assertTrue(mbeanExporter.getServer() - .queryNames(getObjectName("*", "*,*", this.context), null).isEmpty()); + assertThat(mbeanExporter.getServer() + .queryNames(getObjectName("*", "*,*", this.context), null)).isEmpty(); } @Test(expected = NoSuchBeanDefinitionException.class) @@ -120,7 +112,6 @@ public class EndpointMBeanExportAutoConfigurationTests { EndpointMBeanExportAutoConfiguration.class); this.context.refresh(); this.context.getBean(EndpointMBeanExporter.class); - fail(); } @Test @@ -138,11 +129,9 @@ public class EndpointMBeanExportAutoConfigurationTests { this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - - assertNotNull(mbeanExporter.getServer() - .getMBeanInfo(ObjectNameManager.getInstance( - getObjectName("test-domain", "healthEndpoint", this.context) - .toString() + ",key1=value1,key2=value2"))); + assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance( + getObjectName("test-domain", "healthEndpoint", this.context).toString() + + ",key1=value1,key2=value2"))).isNotNull(); } @Test @@ -151,15 +140,12 @@ public class EndpointMBeanExportAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class); - AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); parent.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class); this.context.setParent(parent); - parent.refresh(); this.context.refresh(); - parent.close(); } @@ -178,9 +164,7 @@ public class EndpointMBeanExportAutoConfigurationTests { return ObjectNameManager.getInstance(String.format(name, domain, beanKey, ObjectUtils.getIdentityHexString(applicationContext))); } - else { - return ObjectNameManager.getInstance(String.format(name, domain, beanKey)); - } + return ObjectNameManager.getInstance(String.format(name, domain, beanKey)); } @Configuration @@ -223,6 +207,7 @@ public class EndpointMBeanExportAutoConfigurationTests { public Boolean invoke() { return true; } + } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index c06db14e248..34aa43725da 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -64,8 +64,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for MVC {@link Endpoint}s. @@ -89,18 +88,16 @@ public class EndpointMvcIntegrationTests { public void envEndpointHidden() throws InterruptedException { String body = new TestRestTemplate().getForObject( "http://localhost:" + this.port + "/env/user.dir", String.class); - assertNotNull(body); - assertTrue("Wrong body: \n" + body, body.contains("spring-boot-actuator")); - assertTrue(this.interceptor.invoked()); + assertThat(body).isNotNull().contains("spring-boot-actuator"); + assertThat(this.interceptor.invoked()).isTrue(); } @Test public void healthEndpointNotHidden() throws InterruptedException { String body = new TestRestTemplate() .getForObject("http://localhost:" + this.port + "/health", String.class); - assertNotNull(body); - assertTrue("Wrong body: \n" + body, body.contains("status")); - assertTrue(this.interceptor.invoked()); + assertThat(body).isNotNull().contains("status"); + assertThat(this.interceptor.invoked()).isTrue(); } @Target(ElementType.TYPE) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index f43a17bb266..18be090dc92 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -60,6 +60,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.test.assertj.Matched; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -79,16 +80,9 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; -import static org.hamcrest.Matchers.equalTo; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -136,8 +130,10 @@ public class EndpointWebMvcAutoConfigurationTests { assertContent("/endpoint", ports.get().server, "endpointoutput"); assertContent("/controller", ports.get().management, null); assertContent("/endpoint", ports.get().management, null); - assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); - assertTrue(this.applicationContext.containsBean("applicationContextIdFilter")); + assertThat(hasHeader("/endpoint", ports.get().server, "X-Application-Context")) + .isTrue(); + assertThat(this.applicationContext.containsBean("applicationContextIdFilter")) + .isTrue(); this.applicationContext.close(); assertAllClosed(); } @@ -150,8 +146,10 @@ public class EndpointWebMvcAutoConfigurationTests { BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); - assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); - assertFalse(this.applicationContext.containsBean("applicationContextIdFilter")); + assertThat(hasHeader("/endpoint", ports.get().server, "X-Application-Context")) + .isFalse(); + assertThat(this.applicationContext.containsBean("applicationContextIdFilter")) + .isFalse(); this.applicationContext.close(); assertAllClosed(); } @@ -171,7 +169,7 @@ public class EndpointWebMvcAutoConfigurationTests { .getBean(ManagementContextResolver.class).getApplicationContext(); List interceptors = (List) ReflectionTestUtils.getField( managementContext.getBean(EndpointHandlerMapping.class), "interceptors"); - assertEquals(1, interceptors.size()); + assertThat(interceptors).hasSize(1); this.applicationContext.close(); assertAllClosed(); } @@ -244,7 +242,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.addApplicationListener(grabManagementPort); this.applicationContext.refresh(); int managementPort = grabManagementPort.getServletContainer().getPort(); - assertThat(managementPort, not(equalTo(ports.get().server))); + assertThat(managementPort).isNotEqualTo(ports.get().server); assertContent("/controller", ports.get().server, "controlleroutput"); assertContent("/endpoint", ports.get().server, null); assertContent("/controller", managementPort, null); @@ -337,8 +335,9 @@ public class EndpointWebMvcAutoConfigurationTests { EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); assertContent("/controller", ports.get().server, "controlleroutput"); - assertEquals("foo", - this.applicationContext.getBean(ServerProperties.class).getDisplayName()); + ServerProperties serverProperties = this.applicationContext + .getBean(ServerProperties.class); + assertThat(serverProperties.getDisplayName()).isEqualTo("foo"); this.applicationContext.close(); assertAllClosed(); } @@ -354,9 +353,9 @@ public class EndpointWebMvcAutoConfigurationTests { .getProperty("local.server.port", Integer.class); Integer localManagementPort = this.applicationContext.getEnvironment() .getProperty("local.management.port", Integer.class); - assertThat(localServerPort, notNullValue()); - assertThat(localManagementPort, notNullValue()); - assertThat(localServerPort, equalTo(localManagementPort)); + assertThat(localServerPort).isNotNull(); + assertThat(localManagementPort).isNotNull(); + assertThat(localServerPort).isEqualTo(localManagementPort); this.applicationContext.close(); assertAllClosed(); } @@ -373,11 +372,11 @@ public class EndpointWebMvcAutoConfigurationTests { .getProperty("local.server.port", Integer.class); Integer localManagementPort = this.applicationContext.getEnvironment() .getProperty("local.management.port", Integer.class); - assertThat(localServerPort, notNullValue()); - assertThat(localManagementPort, notNullValue()); - assertThat(localServerPort, not(equalTo(localManagementPort))); - assertThat(this.applicationContext.getBean(ServerPortConfig.class).getCount(), - equalTo(2)); + assertThat(localServerPort).isNotNull(); + assertThat(localManagementPort).isNotNull(); + assertThat(localServerPort).isNotEqualTo(localManagementPort); + assertThat(this.applicationContext.getBean(ServerPortConfig.class).getCount()) + .isEqualTo(2); this.applicationContext.close(); assertAllClosed(); } @@ -389,7 +388,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.refresh(); RequestMappingInfoHandlerMapping mapping = this.applicationContext .getBean(RequestMappingInfoHandlerMapping.class); - assertThat(mapping, not(instanceOf(EndpointHandlerMapping.class))); + assertThat(mapping).isNotEqualTo(instanceOf(EndpointHandlerMapping.class)); } @Test @@ -398,8 +397,7 @@ public class EndpointWebMvcAutoConfigurationTests { ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); // /health, /metrics, /env, /actuator (/shutdown is disabled by default) - assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), - is(equalTo(4))); + assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).hasSize(4); } @Test @@ -409,8 +407,7 @@ public class EndpointWebMvcAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.applicationContext, "ENDPOINTS_ENABLED:false"); this.applicationContext.refresh(); - assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), - is(equalTo(0))); + assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).isEmpty(); } @Test @@ -450,9 +447,8 @@ public class EndpointWebMvcAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.applicationContext, "endpoints.shutdown.enabled:true"); this.applicationContext.refresh(); - assertThat( - this.applicationContext.getBeansOfType(ShutdownMvcEndpoint.class).size(), - is(equalTo(1))); + assertThat(this.applicationContext.getBeansOfType(ShutdownMvcEndpoint.class)) + .hasSize(1); } private void endpointDisabled(String name, Class type) { @@ -461,7 +457,7 @@ public class EndpointWebMvcAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.applicationContext, String.format("endpoints.%s.enabled:false", name)); this.applicationContext.refresh(); - assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(0))); + assertThat(this.applicationContext.getBeansOfType(type)).isEmpty(); } private void endpointEnabledOverride(String name, Class type) @@ -472,7 +468,7 @@ public class EndpointWebMvcAutoConfigurationTests { "endpoints.enabled:false", String.format("endpoints_%s_enabled:true", name)); this.applicationContext.refresh(); - assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(1))); + assertThat(this.applicationContext.getBeansOfType(type)).hasSize(1); } private void assertAllClosed() throws Exception { @@ -482,7 +478,6 @@ public class EndpointWebMvcAutoConfigurationTests { assertContent("/endpoint", ports.get().management, null); } - @SuppressWarnings("unchecked") public void assertContent(String url, int port, Object expected) throws Exception { SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); ClientHttpRequest request = clientHttpRequestFactory @@ -493,10 +488,10 @@ public class EndpointWebMvcAutoConfigurationTests { String actual = StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")); if (expected instanceof Matcher) { - assertThat(actual, is((Matcher) expected)); + assertThat(actual).is(Matched.by((Matcher) expected)); } else { - assertThat(actual, equalTo(expected)); + assertThat(actual).isEqualTo(expected); } } finally { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 829066b9584..d5dbcd4d5b4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -57,8 +57,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.core.CassandraOperations; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; /** @@ -88,9 +87,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -102,9 +101,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -116,9 +115,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertSame(this.context.getBean("customHealthIndicator"), - beans.values().iterator().next()); + assertThat(beans).hasSize(1); + assertThat(this.context.getBean("customHealthIndicator")) + .isSameAs(beans.values().iterator().next()); } @Test @@ -131,9 +130,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(DiskSpaceHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(DiskSpaceHealthIndicator.class); } @Test @@ -145,9 +144,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(RedisHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(RedisHealthIndicator.class); } @Test @@ -160,9 +159,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -175,9 +174,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(MongoHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(MongoHealthIndicator.class); } @Test @@ -191,9 +190,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -204,7 +203,7 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(4, beans.size()); + assertThat(beans).hasSize(4); } @Test @@ -216,9 +215,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(DataSourceHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(DataSourceHealthIndicator.class); } @Test @@ -234,11 +233,11 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); + assertThat(beans).hasSize(1); HealthIndicator healthIndicator = beans.values().iterator().next(); - assertEquals(DataSourceHealthIndicator.class, healthIndicator.getClass()); + assertThat(healthIndicator.getClass()).isEqualTo(DataSourceHealthIndicator.class); DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator) healthIndicator; - assertEquals("SELECT from FOOBAR", dataSourceHealthIndicator.getQuery()); + assertThat(dataSourceHealthIndicator.getQuery()).isEqualTo("SELECT from FOOBAR"); } @Test @@ -251,9 +250,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -265,9 +264,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(RabbitHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(RabbitHealthIndicator.class); } @Test @@ -280,9 +279,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -294,9 +293,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(SolrHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(SolrHealthIndicator.class); } @Test @@ -309,9 +308,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -320,9 +319,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(DiskSpaceHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(DiskSpaceHealthIndicator.class); } @Test @@ -336,9 +335,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(MailHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(MailHealthIndicator.class); } @Test @@ -352,9 +351,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -367,9 +366,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(JmsHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(JmsHealthIndicator.class); } @Test @@ -383,9 +382,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -400,9 +399,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ElasticsearchHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ElasticsearchHealthIndicator.class); } @Test @@ -418,9 +417,9 @@ public class HealthIndicatorAutoConfigurationTests { Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(ApplicationHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(ApplicationHealthIndicator.class); } @Test @@ -432,9 +431,9 @@ public class HealthIndicatorAutoConfigurationTests { this.context.refresh(); Map beans = this.context .getBeansOfType(HealthIndicator.class); - assertEquals(1, beans.size()); - assertEquals(CassandraHealthIndicator.class, - beans.values().iterator().next().getClass()); + assertThat(beans).hasSize(1); + assertThat(beans.values().iterator().next().getClass()) + .isEqualTo(CassandraHealthIndicator.class); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java index 0c00865d862..d886083736e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthMvcEndpointAutoConfigurationTests.java @@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.mock.web.MockServletContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EndpointWebMvcAutoConfiguration} of the {@link HealthMvcEndpoint}. @@ -62,8 +62,8 @@ public class HealthMvcEndpointAutoConfigurationTests { this.context.refresh(); Health health = (Health) this.context.getBean(HealthMvcEndpoint.class) .invoke(null); - assertEquals(Status.UP, health.getStatus()); - assertEquals(null, health.getDetails().get("foo")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("foo")).isNull(); } @Test @@ -76,9 +76,9 @@ public class HealthMvcEndpointAutoConfigurationTests { this.context.refresh(); Health health = (Health) this.context.getBean(HealthMvcEndpoint.class) .invoke(null); - assertEquals(Status.UP, health.getStatus()); + assertThat(health.getStatus()).isEqualTo(Status.UP); Health map = (Health) health.getDetails().get("test"); - assertEquals("bar", map.getDetails().get("foo")); + assertThat(map.getDetails().get("foo")).isEqualTo("bar"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index b0172767db6..48619e7df1a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -41,7 +41,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link JolokiaAutoConfiguration}. @@ -74,8 +74,7 @@ public class JolokiaAutoConfigurationTests { HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class); this.context.refresh(); - assertEquals(1, - this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length); + assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1); } @Test @@ -89,8 +88,7 @@ public class JolokiaAutoConfigurationTests { HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class); this.context.refresh(); - assertEquals(1, - this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length); + assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar")) .andExpect(MockMvcResultMatchers.content() @@ -122,8 +120,7 @@ public class JolokiaAutoConfigurationTests { HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class); this.context.refresh(); - assertEquals(0, - this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length); + assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).isEmpty(); } private void assertEndpointEnabled(String... pairs) { @@ -135,8 +132,7 @@ public class JolokiaAutoConfigurationTests { HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class); this.context.refresh(); - assertEquals(1, - this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length); + assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java index 96917c57c34..295afb6d557 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementServerPropertiesAutoConfigurationTests.java @@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure; import org.junit.Test; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ManagementServerPropertiesAutoConfiguration}. @@ -33,8 +31,8 @@ public class ManagementServerPropertiesAutoConfigurationTests { @Test public void defaultManagementServerProperties() { ManagementServerProperties properties = new ManagementServerProperties(); - assertThat(properties.getPort(), nullValue()); - assertThat(properties.getContextPath(), equalTo("")); + assertThat(properties.getPort()).isNull(); + assertThat(properties.getContextPath()).isEqualTo(""); } @Test @@ -42,22 +40,22 @@ public class ManagementServerPropertiesAutoConfigurationTests { ManagementServerProperties properties = new ManagementServerProperties(); properties.setPort(123); properties.setContextPath("/foo"); - assertThat(properties.getPort(), equalTo(123)); - assertThat(properties.getContextPath(), equalTo("/foo")); + assertThat(properties.getPort()).isEqualTo(123); + assertThat(properties.getContextPath()).isEqualTo("/foo"); } @Test public void trailingSlashOfContextPathIsRemoved() { ManagementServerProperties properties = new ManagementServerProperties(); properties.setContextPath("/foo/"); - assertThat(properties.getContextPath(), equalTo("/foo")); + assertThat(properties.getContextPath()).isEqualTo("/foo"); } @Test public void slashOfContextPathIsDefaultValue() { ManagementServerProperties properties = new ManagementServerProperties(); properties.setContextPath("/"); - assertThat(properties.getContextPath(), equalTo("")); + assertThat(properties.getContextPath()).isEqualTo(""); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java index 40b806ca185..804a6bfaeb2 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.actuate.autoconfigure; +import java.util.ArrayList; + import javax.servlet.Filter; import org.hamcrest.Matchers; @@ -42,6 +44,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -55,12 +58,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.util.StringUtils; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -96,21 +94,20 @@ public class ManagementWebSecurityAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false"); this.context.refresh(); - assertNotNull(this.context.getBean(AuthenticationManagerBuilder.class)); + assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull(); FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class); // 1 for static resources, one for management endpoints and one for the rest - assertThat(filterChainProxy.getFilterChains(), hasSize(3)); - assertThat(filterChainProxy.getFilters("/beans"), hasSize(greaterThan(0))); - assertThat(filterChainProxy.getFilters("/beans/"), hasSize(greaterThan(0))); - assertThat(filterChainProxy.getFilters("/beans.foo"), hasSize(greaterThan(0))); - assertThat(filterChainProxy.getFilters("/beans/foo/bar"), - hasSize(greaterThan(0))); + assertThat(filterChainProxy.getFilterChains()).hasSize(3); + assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty(); + assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty(); + assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty(); + assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty(); } @Test public void testPathNormalization() throws Exception { String path = "admin/./error"; - assertEquals("admin/error", StringUtils.cleanPath(path)); + assertThat(StringUtils.cleanPath(path)).isEqualTo("admin/error"); } @Test @@ -120,8 +117,10 @@ public class ManagementWebSecurityAutoConfigurationTests { this.context.register(WebConfiguration.class); this.context.refresh(); UserDetails user = getUser(); - assertTrue(user.getAuthorities().containsAll(AuthorityUtils - .commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN"))); + ArrayList authorities = new ArrayList( + user.getAuthorities()); + assertThat(authorities).containsAll(AuthorityUtils + .commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN")); } private UserDetails getUser() { @@ -147,8 +146,8 @@ public class ManagementWebSecurityAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none"); this.context.refresh(); // Just the application and management endpoints now - assertEquals(2, - this.context.getBean(FilterChainProxy.class).getFilterChains().size()); + assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains()) + .hasSize(2); } @Test @@ -160,8 +159,8 @@ public class ManagementWebSecurityAutoConfigurationTests { this.context.refresh(); // Just the management endpoints (one filter) and ignores now plus the backup // filter on app endpoints - assertEquals(3, - this.context.getBean(FilterChainProxy.class).getFilterChains().size()); + assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains()) + .hasSize(3); } @Test @@ -174,8 +173,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ManagementServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertEquals(this.context.getBean(TestConfiguration.class).authenticationManager, - this.context.getBean(AuthenticationManager.class)); + assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo( + this.context.getBean(TestConfiguration.class).authenticationManager); } @Test @@ -188,8 +187,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ManagementServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertEquals(this.context.getBean(TestConfiguration.class).authenticationManager, - this.context.getBean(AuthenticationManager.class)); + assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo( + this.context.getBean(TestConfiguration.class).authenticationManager); } // gh-2466 diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java index 288d9bf1a11..1b614245660 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricExportAutoConfigurationTests.java @@ -42,9 +42,7 @@ import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; import org.springframework.messaging.SubscribableChannel; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MetricExportAutoConfiguration}. @@ -76,7 +74,7 @@ public class MetricExportAutoConfigurationTests { MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); MetricExporters exporter = this.context.getBean(MetricExporters.class); - assertNotNull(exporter); + assertThat(exporter).isNotNull(); } @Test @@ -86,7 +84,7 @@ public class MetricExportAutoConfigurationTests { MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(GaugeService.class); - assertNotNull(gaugeService); + assertThat(gaugeService).isNotNull(); gaugeService.submit("foo", 2.7); MetricExporters exporters = this.context.getBean(MetricExporters.class); MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters() @@ -132,7 +130,7 @@ public class MetricExportAutoConfigurationTests { MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBean(StatsdMetricWriter.class), notNullValue()); + assertThat(this.context.getBean(StatsdMetricWriter.class)).isNotNull(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java index ff31fa15847..19c96adaf7b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java @@ -53,11 +53,10 @@ import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.util.NestedServletException; -import static org.hamcrest.Matchers.equalTo; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willThrow; @@ -173,7 +172,7 @@ public class MetricFilterAutoConfigurationTests { public void skipsFilterIfMissingServices() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( MetricFilterAutoConfiguration.class); - assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0)); + assertThat(context.getBeansOfType(Filter.class).size()).isEqualTo(0); context.close(); } @@ -184,7 +183,7 @@ public class MetricFilterAutoConfigurationTests { "endpoints.metrics.filter.enabled:false"); context.register(Config.class, MetricFilterAutoConfiguration.class); context.refresh(); - assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0)); + assertThat(context.getBeansOfType(Filter.class).size()).isEqualTo(0); context.close(); } @@ -269,7 +268,7 @@ public class MetricFilterAutoConfigurationTests { fail(); } catch (Exception ex) { - assertThat(result.getRequest().getAttribute(attributeName), is(nullValue())); + assertThat(result.getRequest().getAttribute(attributeName)).isNull(); verify(context.getBean(CounterService.class)) .increment("status.500.createFailure"); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java index 33298b2d4bc..44fb330da1d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfigurationTests.java @@ -33,10 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; /** @@ -61,12 +58,12 @@ public class MetricRepositoryAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext( MetricRepositoryAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(BufferGaugeService.class); - assertNotNull(gaugeService); - assertNotNull(this.context.getBean(BufferCounterService.class)); - assertNotNull(this.context.getBean(PrefixMetricReader.class)); + assertThat(gaugeService).isNotNull(); + assertThat(this.context.getBean(BufferCounterService.class)).isNotNull(); + assertThat(this.context.getBean(PrefixMetricReader.class)).isNotNull(); gaugeService.submit("foo", 2.7); - assertEquals(2.7, - this.context.getBean(MetricReader.class).findOne("gauge.foo").getValue()); + MetricReader bean = this.context.getBean(MetricReader.class); + assertThat(bean.findOne("gauge.foo").getValue()).isEqualTo(2.7); } @Test @@ -75,25 +72,23 @@ public class MetricRepositoryAutoConfigurationTests { MetricsDropwizardAutoConfiguration.class, MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(GaugeService.class); - assertNotNull(gaugeService); + assertThat(gaugeService).isNotNull(); gaugeService.submit("foo", 2.7); DropwizardMetricServices exporter = this.context .getBean(DropwizardMetricServices.class); - assertEquals(gaugeService, exporter); + assertThat(exporter).isEqualTo(gaugeService); MetricRegistry registry = this.context.getBean(MetricRegistry.class); @SuppressWarnings("unchecked") Gauge gauge = (Gauge) registry.getMetrics().get("gauge.foo"); - assertEquals(new Double(2.7), gauge.getValue()); + assertThat(gauge.getValue()).isEqualTo(new Double(2.7)); } @Test public void skipsIfBeansExist() throws Exception { this.context = new AnnotationConfigApplicationContext(Config.class, MetricRepositoryAutoConfiguration.class); - assertThat(this.context.getBeansOfType(BufferGaugeService.class).size(), - equalTo(0)); - assertThat(this.context.getBeansOfType(BufferCounterService.class).size(), - equalTo(0)); + assertThat(this.context.getBeansOfType(BufferGaugeService.class)).isEmpty(); + assertThat(this.context.getBeansOfType(BufferCounterService.class)).isEmpty(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java index 1d5c45c265c..f46f111ed5b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java @@ -59,10 +59,7 @@ import org.springframework.jdbc.core.ConnectionCallback; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.SocketUtils; -import static org.hamcrest.Matchers.hasKey; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -88,14 +85,14 @@ public class PublicMetricsAutoConfigurationTests { @Test public void systemPublicMetrics() throws Exception { load(); - assertEquals(1, this.context.getBeansOfType(SystemPublicMetrics.class).size()); + assertThat(this.context.getBeansOfType(SystemPublicMetrics.class)).hasSize(1); } @Test public void metricReaderPublicMetrics() throws Exception { load(); - assertEquals(1, - this.context.getBeansOfType(MetricReaderPublicMetrics.class).size()); + assertThat(this.context.getBeansOfType(MetricReaderPublicMetrics.class)) + .hasSize(1); } @Test @@ -104,15 +101,15 @@ public class PublicMetricsAutoConfigurationTests { RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class); RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class); - assertNotNull(richGaugeReader); + assertThat(richGaugeReader).isNotNull(); given(richGaugeReader.findAll()) .willReturn(Collections.singletonList(new RichGauge("bar", 3.7d))); RichGaugeReaderPublicMetrics publicMetrics = context .getBean(RichGaugeReaderPublicMetrics.class); - assertNotNull(publicMetrics); + assertThat(publicMetrics).isNotNull(); Collection> metrics = publicMetrics.metrics(); - assertNotNull(metrics); - assertEquals(metrics.size(), 6); + assertThat(metrics).isNotNull(); + assertThat(6).isEqualTo(metrics.size()); assertHasMetric(metrics, new Metric("bar.val", 3.7d)); assertHasMetric(metrics, new Metric("bar.avg", 3.7d)); assertHasMetric(metrics, new Metric("bar.min", 3.7d)); @@ -125,8 +122,7 @@ public class PublicMetricsAutoConfigurationTests { @Test public void noDataSource() { load(); - assertEquals(0, - this.context.getBeansOfType(DataSourcePublicMetrics.class).size()); + assertThat(this.context.getBeansOfType(DataSourcePublicMetrics.class)).isEmpty(); } @Test @@ -194,13 +190,13 @@ public class PublicMetricsAutoConfigurationTests { @Test public void tomcatMetrics() throws Exception { loadWeb(TomcatConfiguration.class); - assertEquals(1, this.context.getBeansOfType(TomcatPublicMetrics.class).size()); + assertThat(this.context.getBeansOfType(TomcatPublicMetrics.class)).hasSize(1); } @Test public void noCacheMetrics() { load(); - assertEquals(0, this.context.getBeansOfType(CachePublicMetrics.class).size()); + assertThat(this.context.getBeansOfType(CachePublicMetrics.class)).isEmpty(); } @Test @@ -236,7 +232,7 @@ public class PublicMetricsAutoConfigurationTests { content.put(metric.getName(), metric.getValue()); } for (String key : keys) { - assertThat(content, hasKey(key)); + assertThat(content).containsKey(key); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java index d442f92f5c8..a10e3bc5ba1 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java @@ -40,11 +40,7 @@ import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.web.MockServletContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ShellProperties}. @@ -59,8 +55,8 @@ public class ShellPropertiesTests { RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); binder.bind(new MutablePropertyValues( Collections.singletonMap("shell.auth", "spring"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals("spring", props.getAuth()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getAuth()).isEqualTo("spring"); } @Test @@ -69,8 +65,8 @@ public class ShellPropertiesTests { RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); binder.bind( new MutablePropertyValues(Collections.singletonMap("shell.auth", ""))); - assertTrue(binder.getBindingResult().hasErrors()); - assertEquals("simple", props.getAuth()); + assertThat(binder.getBindingResult().hasErrors()).isTrue(); + assertThat(props.getAuth()).isEqualTo("simple"); } @Test @@ -80,8 +76,8 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); binder.bind(new MutablePropertyValues( Collections.singletonMap("shell.command_refresh_interval", "1"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals(1, props.getCommandRefreshInterval()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getCommandRefreshInterval()).isEqualTo(1); } @Test @@ -91,8 +87,8 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.command_path_patterns", "pattern1, pattern2"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals(2, props.getCommandPathPatterns().length); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getCommandPathPatterns().length).isEqualTo(2); Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" }, props.getCommandPathPatterns()); } @@ -104,8 +100,8 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.config_path_patterns", "pattern1, pattern2"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals(2, props.getConfigPathPatterns().length); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getConfigPathPatterns().length).isEqualTo(2); Assert.assertArrayEquals(new String[] { "pattern1", "pattern2" }, props.getConfigPathPatterns()); } @@ -117,10 +113,9 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.disabled_plugins", "pattern1, pattern2"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals(2, props.getDisabledPlugins().length); - assertArrayEquals(new String[] { "pattern1", "pattern2" }, - props.getDisabledPlugins()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getDisabledPlugins().length).isEqualTo(2); + assertThat(props.getDisabledPlugins()).containsExactly("pattern1", "pattern2"); } @Test @@ -130,10 +125,8 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.disabled_commands", "pattern1, pattern2"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertEquals(2, props.getDisabledCommands().length); - assertArrayEquals(new String[] { "pattern1", "pattern2" }, - props.getDisabledCommands()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(props.getDisabledCommands()).containsExactly("pattern1", "pattern2"); } @Test @@ -146,12 +139,12 @@ public class ShellPropertiesTests { map.put("shell.ssh.port", "2222"); map.put("shell.ssh.key_path", "~/.ssh/test.pem"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = props.asCrshShellConfig(); - assertEquals("2222", p.get("crash.ssh.port")); - assertEquals("~/.ssh/test.pem", p.get("crash.ssh.keypath")); + assertThat(p.get("crash.ssh.port")).isEqualTo("2222"); + assertThat(p.get("crash.ssh.keypath")).isEqualTo("~/.ssh/test.pem"); } @Test @@ -164,12 +157,12 @@ public class ShellPropertiesTests { map.put("shell.ssh.port", "2222"); map.put("shell.ssh.key_path", "~/.ssh/test.pem"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = props.asCrshShellConfig(); - assertNull(p.get("crash.ssh.port")); - assertNull(p.get("crash.ssh.keypath")); + assertThat(p.get("crash.ssh.port")).isNull(); + assertThat(p.get("crash.ssh.keypath")).isNull(); } @Test @@ -181,11 +174,11 @@ public class ShellPropertiesTests { map.put("shell.telnet.enabled", "true"); map.put("shell.telnet.port", "2222"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = props.asCrshShellConfig(); - assertEquals("2222", p.get("crash.telnet.port")); + assertThat(p.get("crash.telnet.port")).isEqualTo("2222"); } @Test @@ -197,11 +190,11 @@ public class ShellPropertiesTests { map.put("shell.telnet.enabled", "false"); map.put("shell.telnet.port", "2222"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = props.asCrshShellConfig(); - assertNull(p.get("crash.telnet.port")); + assertThat(p.get("crash.telnet.port")).isNull(); } @Test @@ -212,12 +205,12 @@ public class ShellPropertiesTests { Map map = new HashMap(); map.put("shell.auth.jaas.domain", "my-test-domain"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = new Properties(); props.applyToCrshShellConfig(p); - assertEquals("my-test-domain", p.get("crash.auth.jaas.domain")); + assertThat(p.get("crash.auth.jaas.domain")).isEqualTo("my-test-domain"); } @Test @@ -228,12 +221,12 @@ public class ShellPropertiesTests { Map map = new HashMap(); map.put("shell.auth.key.path", "~/.ssh/test.pem"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = new Properties(); props.applyToCrshShellConfig(p); - assertEquals("~/.ssh/test.pem", p.get("crash.auth.key.path")); + assertThat(p.get("crash.auth.key.path")).isEqualTo("~/.ssh/test.pem"); } @Test @@ -243,12 +236,12 @@ public class ShellPropertiesTests { binder.setConversionService(new DefaultConversionService()); Map map = new HashMap(); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = new Properties(); props.applyToCrshShellConfig(p); - assertNull(p.get("crash.auth.key.path")); + assertThat(p.get("crash.auth.key.path")).isNull(); } @Test @@ -260,13 +253,13 @@ public class ShellPropertiesTests { map.put("shell.auth.simple.user.name", "username123"); map.put("shell.auth.simple.user.password", "password123"); binder.bind(new MutablePropertyValues(map)); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = new Properties(); props.applyToCrshShellConfig(p); - assertEquals("username123", p.get("crash.auth.simple.username")); - assertEquals("password123", p.get("crash.auth.simple.password")); + assertThat(p.get("crash.auth.simple.username")).isEqualTo("username123"); + assertThat(p.get("crash.auth.simple.password")).isEqualTo("password123"); } @Test @@ -275,8 +268,8 @@ public class ShellPropertiesTests { RelaxedDataBinder binder = new RelaxedDataBinder(security, "security"); binder.bind(new MutablePropertyValues(Collections .singletonMap("shell.auth.simple.user.password", "${ADMIN_PASSWORD}"))); - assertFalse(binder.getBindingResult().hasErrors()); - assertTrue(security.getUser().isDefaultPassword()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(security.getUser().isDefaultPassword()).isTrue(); } @Test @@ -285,8 +278,8 @@ public class ShellPropertiesTests { RelaxedDataBinder binder = new RelaxedDataBinder(security, "security"); binder.bind(new MutablePropertyValues( Collections.singletonMap("shell.auth.simple.user.password", ""))); - assertFalse(binder.getBindingResult().hasErrors()); - assertTrue(security.getUser().isDefaultPassword()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); + assertThat(security.getUser().isDefaultPassword()).isTrue(); } @Test @@ -295,12 +288,12 @@ public class ShellPropertiesTests { RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.spring"); binder.bind(new MutablePropertyValues( Collections.singletonMap("shell.auth.spring.roles", "role1, role2"))); - assertFalse(binder.getBindingResult().hasErrors()); + assertThat(binder.getBindingResult().hasErrors()).isFalse(); Properties p = new Properties(); props.applyToCrshShellConfig(p); - assertEquals("role1,role2", p.get("crash.auth.spring.roles")); + assertThat(p.get("crash.auth.spring.roles")).isEqualTo("role1,role2"); } @Test @@ -316,7 +309,7 @@ public class ShellPropertiesTests { PluginLifeCycle lifeCycle = context.getBean(PluginLifeCycle.class); String uuid = lifeCycle.getConfig().getProperty("test.uuid"); - assertEquals(TestShellConfiguration.uuid, uuid); + assertThat(uuid).isEqualTo(TestShellConfiguration.uuid); context.close(); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceRepositoryAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceRepositoryAutoConfigurationTests.java index cec5c97a9df..bd0523fc793 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceRepositoryAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceRepositoryAutoConfigurationTests.java @@ -24,9 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; /** @@ -40,7 +38,7 @@ public class TraceRepositoryAutoConfigurationTests { public void configuresInMemoryTraceRepository() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TraceRepositoryAutoConfiguration.class); - assertNotNull(context.getBean(InMemoryTraceRepository.class)); + assertThat(context.getBean(InMemoryTraceRepository.class)).isNotNull(); context.close(); } @@ -48,9 +46,8 @@ public class TraceRepositoryAutoConfigurationTests { public void skipsIfRepositoryExists() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( Config.class, TraceRepositoryAutoConfiguration.class); - assertThat(context.getBeansOfType(InMemoryTraceRepository.class).size(), - equalTo(0)); - assertThat(context.getBeansOfType(TraceRepository.class).size(), equalTo(1)); + assertThat(context.getBeansOfType(InMemoryTraceRepository.class)).isEmpty(); + assertThat(context.getBeansOfType(TraceRepository.class)).hasSize(1); context.close(); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java index 9f6e0196f8e..8352919763c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java @@ -22,7 +22,7 @@ import org.springframework.boot.actuate.trace.WebRequestTraceFilter; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link TraceWebFilterAutoConfiguration}. @@ -37,7 +37,7 @@ public class TraceWebFilterAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class, TraceRepositoryAutoConfiguration.class, TraceWebFilterAutoConfiguration.class); - assertNotNull(context.getBean(WebRequestTraceFilter.class)); + assertThat(context.getBean(WebRequestTraceFilter.class)).isNotNull(); context.close(); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java index b65ac25bfd8..f587f7ea55a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java @@ -31,8 +31,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Abstract base class for endpoint tests. @@ -79,12 +78,12 @@ public abstract class AbstractEndpointTests> { @Test public void getId() throws Exception { - assertThat(getEndpointBean().getId(), equalTo(this.id)); + assertThat(getEndpointBean().getId()).isEqualTo(this.id); } @Test public void isSensitive() throws Exception { - assertThat(getEndpointBean().isSensitive(), equalTo(this.sensitive)); + assertThat(getEndpointBean().isSensitive()).isEqualTo(this.sensitive); } @Test @@ -93,7 +92,7 @@ public abstract class AbstractEndpointTests> { EnvironmentTestUtils.addEnvironment(this.context, this.property + ".id:myid"); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().getId(), equalTo("myid")); + assertThat(getEndpointBean().getId()).isEqualTo("myid"); } @Test @@ -105,7 +104,7 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isSensitive(), equalTo(!this.sensitive)); + assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive); } @Test @@ -118,12 +117,12 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isSensitive(), equalTo(!this.sensitive)); + assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive); } @Test public void isEnabledByDefault() throws Exception { - assertThat(getEndpointBean().isEnabled(), equalTo(true)); + assertThat(getEndpointBean().isEnabled()).isTrue(); } @Test @@ -134,7 +133,7 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isEnabled(), equalTo(false)); + assertThat(getEndpointBean().isEnabled()).isFalse(); } @Test @@ -147,7 +146,7 @@ public abstract class AbstractEndpointTests> { this.context.register(this.configClass); this.context.refresh(); ((AbstractEndpoint) getEndpointBean()).setEnabled(true); - assertThat(getEndpointBean().isEnabled(), equalTo(true)); + assertThat(getEndpointBean().isEnabled()).isTrue(); } @Test @@ -158,7 +157,7 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isEnabled(), equalTo(false)); + assertThat(getEndpointBean().isEnabled()).isFalse(); } @Test @@ -171,7 +170,7 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isEnabled(), equalTo(true)); + assertThat(getEndpointBean().isEnabled()).isTrue(); } @Test @@ -199,7 +198,7 @@ public abstract class AbstractEndpointTests> { this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.register(this.configClass); this.context.refresh(); - assertThat(getEndpointBean().isSensitive(), equalTo(sensitive)); + assertThat(getEndpointBean().isSensitive()).isEqualTo(sensitive); } @SuppressWarnings("unchecked") diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java index c9c6bda7f12..42511f1dea0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java @@ -33,7 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; /** @@ -57,9 +57,9 @@ public class AutoConfigurationReportEndpointTests this.context.register(this.configClass); this.context.refresh(); Report report = getEndpointBean().invoke(); - assertTrue(report.getPositiveMatches().isEmpty()); - assertTrue(report.getNegativeMatches().containsKey("a")); - assertTrue(report.getExclusions().contains("com.foo.Bar")); + assertThat(report.getPositiveMatches()).isEmpty(); + assertThat(report.getNegativeMatches()).containsKey("a"); + assertThat(report.getExclusions()).contains("com.foo.Bar"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/BeansEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/BeansEndpointTests.java index 9f13c4f63c0..37bed9056fb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/BeansEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/BeansEndpointTests.java @@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link BeansEndpoint}. @@ -42,8 +41,8 @@ public class BeansEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { List result = getEndpointBean().invoke(); - assertEquals(1, result.size()); - assertTrue(result.get(0) instanceof Map); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isInstanceOf(Map.class); } @Configuration @@ -56,4 +55,5 @@ public class BeansEndpointTests extends AbstractEndpointTests { } } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java index 9d56e8e4da8..31557c84c2f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java @@ -29,8 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ConfigurationPropertiesReportEndpoint} when used with bean methods. @@ -65,9 +64,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("other"); - assertNotNull(nestedProperties); - assertEquals("other", nestedProperties.get("prefix")); - assertNotNull(nestedProperties.get("properties")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("other"); + assertThat(nestedProperties.get("properties")).isNotNull(); } @Test @@ -81,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("bar"); - assertNotNull(nestedProperties); - assertEquals("other", nestedProperties.get("prefix")); - assertNotNull(nestedProperties.get("properties")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("other"); + assertThat(nestedProperties.get("properties")).isNotNull(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointParentTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointParentTests.java index 0ae3cdbe28f..241bec9e9d5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointParentTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointParentTests.java @@ -28,8 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ConfigurationPropertiesReportEndpoint} when used with a parent @@ -63,8 +62,8 @@ public class ConfigurationPropertiesReportEndpointParentTests { ConfigurationPropertiesReportEndpoint endpoint = this.context .getBean(ConfigurationPropertiesReportEndpoint.class); Map result = endpoint.invoke(); - assertTrue(result.containsKey("parent")); - assertEquals(3, result.size()); // the endpoint, the test props and the parent + assertThat(result).containsKey("parent"); + assertThat(result).hasSize(3); // the endpoint, the test props and the parent // System.err.println(result); } @@ -80,8 +79,8 @@ public class ConfigurationPropertiesReportEndpointParentTests { ConfigurationPropertiesReportEndpoint endpoint = this.context .getBean(ConfigurationPropertiesReportEndpoint.class); Map result = endpoint.invoke(); - assertTrue(result.containsKey("parent")); - assertEquals(3, result.size()); // the endpoint, the test props and the parent + assertThat(result.containsKey("parent")).isTrue(); + assertThat(result).hasSize(3); // the endpoint, the test props and the parent // System.err.println(result); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointProxyTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointProxyTests.java index 636cdcad2f0..222002b31c2 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointProxyTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointProxyTests.java @@ -38,8 +38,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ConfigurationPropertiesReportEndpoint} when used against a proxy @@ -69,7 +68,7 @@ public class ConfigurationPropertiesReportEndpointProxyTests { this.context.refresh(); Map report = this.context .getBean(ConfigurationPropertiesReportEndpoint.class).invoke(); - assertThat(report.toString(), containsString("prefix=executor.sql")); + assertThat(report.toString()).contains("prefix=executor.sql"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java index 015bc27f2fb..41bf5a01495 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java @@ -32,8 +32,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ConfigurationPropertiesReportEndpoint} serialization. @@ -67,13 +66,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(2, map.size()); - assertEquals("foo", map.get("name")); + assertThat(map).isNotNull(); + assertThat(map).hasSize(2); + assertThat(map.get("name")).isEqualTo("foo"); } @Test @@ -87,12 +86,12 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); + assertThat(nestedProperties).isNotNull(); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(2, map.size()); - assertEquals("foo", ((Map) map.get("bar")).get("name")); + assertThat(map).isNotNull(); + assertThat(map).hasSize(2); + assertThat(((Map) map.get("bar")).get("name")).isEqualTo("foo"); } @Test @@ -106,13 +105,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(1, map.size()); - assertEquals("Cannot serialize 'foo'", map.get("error")); + assertThat(map).isNotNull(); + assertThat(map).hasSize(1); + assertThat(map.get("error")).isEqualTo("Cannot serialize 'foo'"); } @Test @@ -126,13 +125,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(3, map.size()); - assertEquals("foo", ((Map) map.get("map")).get("name")); + assertThat(map).isNotNull(); + assertThat(map).hasSize(3); + assertThat(((Map) map.get("map")).get("name")).isEqualTo("foo"); } @Test @@ -145,14 +144,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); + assertThat(nestedProperties).isNotNull(); System.err.println(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(3, map.size()); - assertEquals(null, (map.get("map"))); + assertThat(map).isNotNull(); + assertThat(map).hasSize(3); + assertThat((map.get("map"))).isNull(); } @Test @@ -166,13 +165,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(3, map.size()); - assertEquals("foo", ((List) map.get("list")).get(0)); + assertThat(map).isNotNull(); + assertThat(map).hasSize(3); + assertThat(((List) map.get("list")).get(0)).isEqualTo("foo"); } @Test @@ -186,14 +185,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("foo"); - assertNotNull(nestedProperties); + assertThat(nestedProperties).isNotNull(); System.err.println(nestedProperties); - assertEquals("foo", nestedProperties.get("prefix")); + assertThat(nestedProperties.get("prefix")).isEqualTo("foo"); Map map = (Map) nestedProperties .get("properties"); - assertNotNull(map); - assertEquals(3, map.size()); - assertEquals("192.168.1.10", map.get("address")); + assertThat(map).isNotNull(); + assertThat(map).hasSize(3); + assertThat(map.get("address")).isEqualTo("192.168.1.10"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java index 350e8e5c715..0c41f2348b9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java @@ -28,11 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ConfigurationPropertiesReportEndpoint}. @@ -49,7 +45,7 @@ public class ConfigurationPropertiesReportEndpointTests @Test public void testInvoke() throws Exception { - assertThat(getEndpointBean().invoke().size(), greaterThan(0)); + assertThat(getEndpointBean().invoke().size()).isGreaterThan(0); } @Test @@ -59,9 +55,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) properties .get("testProperties"); - assertNotNull(nestedProperties); - assertEquals("test", nestedProperties.get("prefix")); - assertNotNull(nestedProperties.get("properties")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("prefix")).isEqualTo("test"); + assertThat(nestedProperties.get("properties")).isNotNull(); } @Test @@ -71,9 +67,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("******", nestedProperties.get("dbPassword")); - assertEquals("654321", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("******"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321"); } @Test @@ -84,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("123456", nestedProperties.get("dbPassword")); - assertEquals("******", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("123456"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******"); } @SuppressWarnings("unchecked") @@ -97,9 +93,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("******", nestedProperties.get("dbPassword")); - assertEquals("654321", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("******"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321"); } @SuppressWarnings("unchecked") @@ -114,9 +110,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("123456", nestedProperties.get("dbPassword")); - assertEquals("******", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("123456"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******"); } @SuppressWarnings("unchecked") @@ -131,9 +127,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("******", nestedProperties.get("dbPassword")); - assertEquals("654321", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("******"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321"); } @Test @@ -149,9 +145,9 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); - assertEquals("******", nestedProperties.get("dbPassword")); - assertEquals("******", nestedProperties.get("myTestProperty")); + assertThat(nestedProperties).isNotNull(); + assertThat(nestedProperties.get("dbPassword")).isEqualTo("******"); + assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******"); } @Test @@ -168,13 +164,13 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertNotNull(nestedProperties); + assertThat(nestedProperties).isNotNull(); Map secrets = (Map) nestedProperties .get("secrets"); Map hidden = (Map) nestedProperties.get("hidden"); - assertEquals("******", secrets.get("mine")); - assertEquals("******", secrets.get("yours")); - assertEquals("******", hidden.get("mine")); + assertThat(secrets.get("mine")).isEqualTo("******"); + assertThat(secrets.get("yours")).isEqualTo("******"); + assertThat(hidden.get("mine")).isEqualTo("******"); } @Test @@ -184,7 +180,7 @@ public class ConfigurationPropertiesReportEndpointTests Map properties = report.invoke(); Map nestedProperties = (Map) ((Map) properties .get("testProperties")).get("properties"); - assertThat(nestedProperties.get("mixedBoolean"), equalTo((Object) true)); + assertThat(nestedProperties.get("mixedBoolean")).isEqualTo(true); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/DumpEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/DumpEndpointTests.java index 2aecbb8c644..4815885c519 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/DumpEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/DumpEndpointTests.java @@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link DumpEndpoint}. @@ -42,7 +41,7 @@ public class DumpEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { List threadInfo = getEndpointBean().invoke(); - assertThat(threadInfo.size(), greaterThan(0)); + assertThat(threadInfo.size()).isGreaterThan(0); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java index bdc79501e68..0f3536f1c82 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java @@ -29,9 +29,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.MapPropertySource; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EnvironmentEndpoint}. @@ -49,7 +47,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("bar", ((Map) env.get("composite:one")).get("foo")); + assertThat(((Map) env.get("composite:one")).get("foo")) + .isEqualTo("bar"); } @SuppressWarnings("unchecked") @@ -76,16 +75,13 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("******", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("apiKey")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("mySecret")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("myCredentials")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("VCAP_SERVICES")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("******"); + assertThat(systemProperties.get("apiKey")).isEqualTo("******"); + assertThat(systemProperties.get("mySecret")).isEqualTo("******"); + assertThat(systemProperties.get("myCredentials")).isEqualTo("******"); + assertThat(systemProperties.get("VCAP_SERVICES")).isEqualTo("******"); } @SuppressWarnings("unchecked") @@ -97,14 +93,14 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("******", ((Map) env.get("systemProperties")) - .get("my.services.amqp-free.credentials.uri")); - assertEquals("******", ((Map) env.get("systemProperties")) - .get("credentials.http_api_uri")); - assertEquals("******", ((Map) env.get("systemProperties")) - .get("my.services.cleardb-free.credentials")); - assertEquals("******", ((Map) env.get("systemProperties")) - .get("foo.mycredentials.uri")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("my.services.amqp-free.credentials.uri")) + .isEqualTo("******"); + assertThat(systemProperties.get("credentials.http_api_uri")).isEqualTo("******"); + assertThat(systemProperties.get("my.services.cleardb-free.credentials")) + .isEqualTo("******"); + assertThat(systemProperties.get("foo.mycredentials.uri")).isEqualTo("******"); } @@ -116,10 +112,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("123456", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("apiKey")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("123456"); + assertThat(systemProperties.get("apiKey")).isEqualTo("******"); } @SuppressWarnings("unchecked") @@ -130,10 +126,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("******", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("123456", - ((Map) env.get("systemProperties")).get("apiKey")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("******"); + assertThat(systemProperties.get("apiKey")).isEqualTo("123456"); } @SuppressWarnings("unchecked") @@ -148,10 +144,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("123456", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("apiKey")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("123456"); + assertThat(systemProperties.get("apiKey")).isEqualTo("******"); } @SuppressWarnings("unchecked") @@ -166,10 +162,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("******", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("123456", - ((Map) env.get("systemProperties")).get("apiKey")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("******"); + assertThat(systemProperties.get("apiKey")).isEqualTo("123456"); } @SuppressWarnings("unchecked") @@ -185,10 +181,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests env = report.invoke(); - assertEquals("******", - ((Map) env.get("systemProperties")).get("dbPassword")); - assertEquals("******", - ((Map) env.get("systemProperties")).get("apiKey")); + Map systemProperties = (Map) env + .get("systemProperties"); + assertThat(systemProperties.get("dbPassword")).isEqualTo("******"); + assertThat(systemProperties.get("apiKey")).isEqualTo("******"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java index 48f468a25ad..c10579ce91c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java @@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link FlywayEndpoint}. @@ -42,7 +41,7 @@ public class FlywayEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { - assertThat(getEndpointBean().invoke().size(), is(1)); + assertThat(getEndpointBean().invoke()).hasSize(1); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java index 3087538780e..21b4537393d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/HealthEndpointTests.java @@ -29,8 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link HealthEndpoint}. @@ -47,7 +46,7 @@ public class HealthEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { // As FINE isn't configured in the order we get UNKNOWN - assertThat(getEndpointBean().invoke().getStatus(), equalTo(Status.UNKNOWN)); + assertThat(getEndpointBean().invoke().getStatus()).isEqualTo(Status.UNKNOWN); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java index 7c99a739a75..3cb1abdbcb9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/InfoEndpointTests.java @@ -24,8 +24,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link InfoEndpoint}. @@ -41,7 +40,7 @@ public class InfoEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { - assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) "b")); + assertThat(getEndpointBean().invoke().get("a")).isEqualTo("b"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java index 9b63b602dc9..c5fde156f66 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java @@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link LiquibaseEndpoint}. @@ -43,7 +42,7 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests @Test public void invoke() throws Exception { - assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) 0.5f)); + assertThat(getEndpointBean().invoke().get("a")).isEqualTo(0.5f); } @Test @@ -68,10 +65,10 @@ public class MetricsEndpointTests extends AbstractEndpointTests publicMetrics.add(new TestPublicMetrics(1, this.metric1)); Map metrics = new MetricsEndpoint(publicMetrics).invoke(); Iterator> iterator = metrics.entrySet().iterator(); - assertEquals("a", iterator.next().getKey()); - assertEquals("b", iterator.next().getKey()); - assertEquals("c", iterator.next().getKey()); - assertFalse(iterator.hasNext()); + assertThat(iterator.next().getKey()).isEqualTo("a"); + assertThat(iterator.next().getKey()).isEqualTo("b"); + assertThat(iterator.next().getKey()).isEqualTo("c"); + assertThat(iterator.hasNext()).isFalse(); } private static class TestPublicMetrics implements PublicMetrics, Ordered { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java index 6d814342549..667989b67ed 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RequestMappingEndpointTests.java @@ -35,8 +35,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link RequestMappingEndpoint}. @@ -56,10 +55,10 @@ public class RequestMappingEndpointTests { this.endpoint.setHandlerMappings( Collections.singletonList(mapping)); Map result = this.endpoint.invoke(); - assertEquals(1, result.size()); + assertThat(result).hasSize(1); @SuppressWarnings("unchecked") Map map = (Map) result.get("/foo"); - assertEquals("java.lang.Object", map.get("type")); + assertThat(map.get("type")).isEqualTo("java.lang.Object"); } @Test @@ -72,10 +71,10 @@ public class RequestMappingEndpointTests { context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); this.endpoint.setApplicationContext(context); Map result = this.endpoint.invoke(); - assertEquals(1, result.size()); + assertThat(result).hasSize(1); @SuppressWarnings("unchecked") Map map = (Map) result.get("/foo"); - assertEquals("mapping", map.get("bean")); + assertThat(map.get("bean")).isEqualTo("mapping"); } @Test @@ -84,10 +83,10 @@ public class RequestMappingEndpointTests { MappingConfiguration.class); this.endpoint.setApplicationContext(context); Map result = this.endpoint.invoke(); - assertEquals(1, result.size()); + assertThat(result).hasSize(1); @SuppressWarnings("unchecked") Map map = (Map) result.get("/foo"); - assertEquals("scopedTarget.mapping", map.get("bean")); + assertThat(map.get("bean")).isEqualTo("scopedTarget.mapping"); } @Test @@ -100,12 +99,12 @@ public class RequestMappingEndpointTests { context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); this.endpoint.setApplicationContext(context); Map result = this.endpoint.invoke(); - assertEquals(1, result.size()); - assertTrue(result.keySet().iterator().next().contains("/dump")); + assertThat(result).hasSize(1); + assertThat(result.keySet().iterator().next().contains("/dump")).isTrue(); @SuppressWarnings("unchecked") Map handler = (Map) result.values().iterator() .next(); - assertTrue(handler.containsKey("method")); + assertThat(handler.containsKey("method")).isTrue(); } @Test @@ -117,12 +116,12 @@ public class RequestMappingEndpointTests { this.endpoint.setMethodMappings( Collections.>singletonList(mapping)); Map result = this.endpoint.invoke(); - assertEquals(1, result.size()); - assertTrue(result.keySet().iterator().next().contains("/dump")); + assertThat(result).hasSize(1); + assertThat(result.keySet().iterator().next().contains("/dump")).isTrue(); @SuppressWarnings("unchecked") Map handler = (Map) result.values().iterator() .next(); - assertTrue(handler.containsKey("method")); + assertThat(handler.containsKey("method")).isTrue(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java index 5e9ca0fd34b..492ebeef95f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/RichGaugeReaderPublicMetricsTests.java @@ -25,9 +25,7 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link RichGaugeReaderPublicMetrics}. @@ -50,23 +48,23 @@ public class RichGaugeReaderPublicMetricsTests { for (Metric metric : metrics.metrics()) { results.put(metric.getName(), metric); } - assertTrue(results.containsKey("a.val")); - assertThat(results.get("a.val").getValue().doubleValue(), equalTo(0.5d)); + assertThat(results.containsKey("a.val")).isTrue(); + assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d); - assertTrue(results.containsKey("a.avg")); - assertThat(results.get("a.avg").getValue().doubleValue(), equalTo(0.25d)); + assertThat(results.containsKey("a.avg")).isTrue(); + assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d); - assertTrue(results.containsKey("a.min")); - assertThat(results.get("a.min").getValue().doubleValue(), equalTo(0.0d)); + assertThat(results.containsKey("a.min")).isTrue(); + assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d); - assertTrue(results.containsKey("a.max")); - assertThat(results.get("a.max").getValue().doubleValue(), equalTo(0.5d)); + assertThat(results.containsKey("a.max")).isTrue(); + assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d); - assertTrue(results.containsKey("a.count")); - assertThat(results.get("a.count").getValue().longValue(), equalTo(2L)); + assertThat(results.containsKey("a.count")).isTrue(); + assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L); - assertTrue(results.containsKey("a.alpha")); - assertThat(results.get("a.alpha").getValue().doubleValue(), equalTo(-1.d)); + assertThat(results.containsKey("a.alpha")).isTrue(); + assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java index ffca349b5e2..1efbc3d48c6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java @@ -18,7 +18,7 @@ package org.springframework.boot.actuate.endpoint; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link Sanitizer}. @@ -27,23 +27,22 @@ import static org.junit.Assert.assertEquals; */ public class SanitizerTests { - private Sanitizer sanitizer = new Sanitizer(); - @Test public void defaults() throws Exception { - assertEquals(this.sanitizer.sanitize("password", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("my-password", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("my-OTHER.paSSword", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("somesecret", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("somekey", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("find", "secret"), "secret"); + Sanitizer sanitizer = new Sanitizer(); + assertThat(sanitizer.sanitize("password", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("my-password", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("my-OTHER.paSSword", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("somesecret", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("somekey", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("find", "secret")).isEqualTo("secret"); } @Test public void regex() throws Exception { - this.sanitizer.setKeysToSanitize(".*lock.*"); - assertEquals(this.sanitizer.sanitize("verylOCkish", "secret"), "******"); - assertEquals(this.sanitizer.sanitize("veryokish", "secret"), "secret"); + Sanitizer sanitizer = new Sanitizer(".*lock.*"); + assertThat(sanitizer.sanitize("verylOCkish", "secret")).isEqualTo("******"); + assertThat(sanitizer.sanitize("veryokish", "secret")).isEqualTo("secret"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java index a4de92086c9..4b6fff5b8b0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java @@ -27,10 +27,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.ContextClosedEvent; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ShutdownEndpoint}. @@ -48,16 +45,16 @@ public class ShutdownEndpointTests extends AbstractEndpointTests metric : publicMetrics.metrics()) { results.put(metric.getName(), metric); } - assertTrue(results.containsKey("mem")); - assertTrue(results.containsKey("mem.free")); - assertTrue(results.containsKey("processors")); - assertTrue(results.containsKey("uptime")); - assertTrue(results.containsKey("systemload.average")); - - assertTrue(results.containsKey("heap.committed")); - assertTrue(results.containsKey("heap.init")); - assertTrue(results.containsKey("heap.used")); - assertTrue(results.containsKey("heap")); - - assertTrue(results.containsKey("nonheap.committed")); - assertTrue(results.containsKey("nonheap.init")); - assertTrue(results.containsKey("nonheap.used")); - assertTrue(results.containsKey("nonheap")); - - assertTrue(results.containsKey("threads.peak")); - assertTrue(results.containsKey("threads.daemon")); - assertTrue(results.containsKey("threads.totalStarted")); - assertTrue(results.containsKey("threads")); - - assertTrue(results.containsKey("classes.loaded")); - assertTrue(results.containsKey("classes.unloaded")); - assertTrue(results.containsKey("classes")); + assertThat(results).containsKey("mem"); + assertThat(results).containsKey("mem.free"); + assertThat(results).containsKey("processors"); + assertThat(results).containsKey("uptime"); + assertThat(results).containsKey("systemload.average"); + assertThat(results).containsKey("heap.committed"); + assertThat(results).containsKey("heap.init"); + assertThat(results).containsKey("heap.used"); + assertThat(results).containsKey("heap"); + assertThat(results).containsKey("nonheap.committed"); + assertThat(results).containsKey("nonheap.init"); + assertThat(results).containsKey("nonheap.used"); + assertThat(results).containsKey("nonheap"); + assertThat(results).containsKey("threads.peak"); + assertThat(results).containsKey("threads.daemon"); + assertThat(results).containsKey("threads.totalStarted"); + assertThat(results).containsKey("threads"); + assertThat(results).containsKey("classes.loaded"); + assertThat(results).containsKey("classes.unloaded"); + assertThat(results).containsKey("classes"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java index 35f41999bcc..1e061145f95 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java @@ -27,8 +27,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.SocketUtils; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link TomcatPublicMetrics} @@ -46,9 +45,9 @@ public class TomcatPublicMetricsTests { TomcatPublicMetrics tomcatMetrics = context .getBean(TomcatPublicMetrics.class); Iterator> metrics = tomcatMetrics.metrics().iterator(); - assertThat(metrics.next().getName(), equalTo("httpsessions.max")); - assertThat(metrics.next().getName(), equalTo("httpsessions.active")); - assertThat(metrics.hasNext(), equalTo(false)); + assertThat(metrics.next().getName()).isEqualTo("httpsessions.max"); + assertThat(metrics.next().getName()).isEqualTo("httpsessions.active"); + assertThat(metrics.hasNext()).isFalse(); } finally { context.close(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TraceEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TraceEndpointTests.java index 203be5f180c..b5cbdbe46a0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TraceEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TraceEndpointTests.java @@ -27,8 +27,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link TraceEndpoint}. @@ -44,7 +43,7 @@ public class TraceEndpointTests extends AbstractEndpointTests { @Test public void invoke() throws Exception { Trace trace = getEndpointBean().invoke().get(0); - assertThat(trace.getInfo().get("a"), equalTo((Object) "b")); + assertThat(trace.getInfo().get("a")).isEqualTo("b"); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java index 99b36bc610b..652740aedc3 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanExporterTests.java @@ -42,13 +42,7 @@ import org.springframework.jmx.export.MBeanExporter; import org.springframework.jmx.support.ObjectNameManager; import org.springframework.util.ObjectUtils; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EndpointMBeanExporter} @@ -78,9 +72,9 @@ public class EndpointMBeanExporterTests { MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanInfo mbeanInfo = mbeanExporter.getServer() .getMBeanInfo(getObjectName("endpoint1", this.context)); - assertNotNull(mbeanInfo); - assertEquals(3, mbeanInfo.getOperations().length); - assertEquals(3, mbeanInfo.getAttributes().length); + assertThat(mbeanInfo).isNotNull(); + assertThat(mbeanInfo.getOperations().length).isEqualTo(3); + assertThat(mbeanInfo.getAttributes().length).isEqualTo(3); } @Test @@ -94,8 +88,8 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class, null, mpv)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertFalse(mbeanExporter.getServer() - .isRegistered(getObjectName("endpoint1", this.context))); + assertThat(mbeanExporter.getServer() + .isRegistered(getObjectName("endpoint1", this.context))).isFalse(); } @Test @@ -109,8 +103,8 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class, null, mpv)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertTrue(mbeanExporter.getServer() - .isRegistered(getObjectName("endpoint1", this.context))); + assertThat(mbeanExporter.getServer() + .isRegistered(getObjectName("endpoint1", this.context))).isTrue(); } @Test @@ -124,10 +118,10 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer() - .getMBeanInfo(getObjectName("endpoint1", this.context))); - assertNotNull(mbeanExporter.getServer() - .getMBeanInfo(getObjectName("endpoint2", this.context))); + assertThat(mbeanExporter.getServer() + .getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull(); + assertThat(mbeanExporter.getServer() + .getMBeanInfo(getObjectName("endpoint2", this.context))).isNotNull(); } @Test @@ -141,8 +135,9 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( - getObjectName("test-domain", "endpoint1", false, this.context))); + assertThat(mbeanExporter.getServer().getMBeanInfo( + getObjectName("test-domain", "endpoint1", false, this.context))) + .isNotNull(); } @Test @@ -158,8 +153,9 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer().getMBeanInfo( - getObjectName("test-domain", "endpoint1", true, this.context))); + assertThat(mbeanExporter.getServer().getMBeanInfo( + getObjectName("test-domain", "endpoint1", true, this.context))) + .isNotNull(); } @Test @@ -180,10 +176,9 @@ public class EndpointMBeanExporterTests { new RootBeanDefinition(TestEndpoint.class)); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer() - .getMBeanInfo(ObjectNameManager.getInstance( - getObjectName("test-domain", "endpoint1", true, this.context) - .toString() + ",key1=value1,key2=value2"))); + assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance( + getObjectName("test-domain", "endpoint1", true, this.context).toString() + + ",key1=value1,key2=value2"))).isNotNull(); } @Test @@ -198,9 +193,8 @@ public class EndpointMBeanExporterTests { parent.refresh(); this.context.refresh(); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); - assertNotNull(mbeanExporter.getServer() - .getMBeanInfo(getObjectName("endpoint1", this.context))); - + assertThat(mbeanExporter.getServer() + .getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull(); parent.close(); } @@ -216,8 +210,8 @@ public class EndpointMBeanExporterTests { Object response = mbeanExporter.getServer().invoke( getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]); - assertThat(response, is(instanceOf(Map.class))); - assertThat(((Map) response).get("date"), is(instanceOf(Long.class))); + assertThat(response).isInstanceOf(Map.class); + assertThat(((Map) response).get("date")).isInstanceOf(Long.class); } @Test @@ -237,8 +231,8 @@ public class EndpointMBeanExporterTests { Object response = mbeanExporter.getServer().invoke( getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]); - assertThat(response, is(instanceOf(Map.class))); - assertThat(((Map) response).get("date"), is(instanceOf(String.class))); + assertThat(response).isInstanceOf(Map.class); + assertThat(((Map) response).get("date")).isInstanceOf(String.class); } private ObjectName getObjectName(String beanKey, GenericApplicationContext context) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java index 26fa616529f..44be1690eae 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java @@ -31,11 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.method.HandlerMethod; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EndpointHandlerMapping}. @@ -61,14 +57,11 @@ public class EndpointHandlerMappingTests { Arrays.asList(endpointA, endpointB)); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertThat( - mapping.getHandler(new MockHttpServletRequest("GET", "/a")).getHandler(), - equalTo((Object) new HandlerMethod(endpointA, this.method))); - assertThat( - mapping.getHandler(new MockHttpServletRequest("GET", "/b")).getHandler(), - equalTo((Object) new HandlerMethod(endpointB, this.method))); - assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/c")), - nullValue()); + assertThat(mapping.getHandler(request("GET", "/a")).getHandler()) + .isEqualTo(new HandlerMethod(endpointA, this.method)); + assertThat(mapping.getHandler(request("GET", "/b")).getHandler()) + .isEqualTo(new HandlerMethod(endpointB, this.method)); + assertThat(mapping.getHandler(request("GET", "/c"))).isNull(); } @Test @@ -80,16 +73,11 @@ public class EndpointHandlerMappingTests { mapping.setApplicationContext(this.context); mapping.setPrefix("/a"); mapping.afterPropertiesSet(); - assertThat( - mapping.getHandler(new MockHttpServletRequest("GET", "/a/a")) - .getHandler(), - equalTo((Object) new HandlerMethod(endpointA, this.method))); - assertThat( - mapping.getHandler(new MockHttpServletRequest("GET", "/a/b")) - .getHandler(), - equalTo((Object) new HandlerMethod(endpointB, this.method))); - assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")), - nullValue()); + assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/a")) + .getHandler()).isEqualTo(new HandlerMethod(endpointA, this.method)); + assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/b")) + .getHandler()).isEqualTo(new HandlerMethod(endpointB, this.method)); + assertThat(mapping.getHandler(request("GET", "/a"))).isNull(); } @Test(expected = HttpRequestMethodNotSupportedException.class) @@ -99,8 +87,8 @@ public class EndpointHandlerMappingTests { Arrays.asList(endpoint)); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertNotNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a"))); - assertNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); + assertThat(mapping.getHandler(request("GET", "/a"))).isNotNull(); + assertThat(mapping.getHandler(request("POST", "/a"))).isNull(); } @Test @@ -110,7 +98,7 @@ public class EndpointHandlerMappingTests { Arrays.asList(endpoint)); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertNotNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); + assertThat(mapping.getHandler(request("POST", "/a"))).isNotNull(); } @Test(expected = HttpRequestMethodNotSupportedException.class) @@ -120,8 +108,8 @@ public class EndpointHandlerMappingTests { Arrays.asList(endpoint)); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertNotNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); - assertNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a"))); + assertThat(mapping.getHandler(request("POST", "/a"))).isNotNull(); + assertThat(mapping.getHandler(request("GET", "/a"))).isNull(); } @Test @@ -132,8 +120,7 @@ public class EndpointHandlerMappingTests { mapping.setDisabled(true); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")), - nullValue()); + assertThat(mapping.getHandler(request("GET", "/a"))).isNull(); } @Test @@ -145,10 +132,12 @@ public class EndpointHandlerMappingTests { mapping.setDisabled(true); mapping.setApplicationContext(this.context); mapping.afterPropertiesSet(); - assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")), - nullValue()); - assertThat(mapping.getHandler(new MockHttpServletRequest("POST", "/a")), - nullValue()); + assertThat(mapping.getHandler(request("GET", "/a"))).isNull(); + assertThat(mapping.getHandler(request("POST", "/a"))).isNull(); + } + + private MockHttpServletRequest request(String method, String requestURI) { + return new MockHttpServletRequest(method, requestURI); } private static class TestEndpoint extends AbstractEndpoint { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java index 20999c0e539..40058ced26c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointBrowserPathIntegrationTests.java @@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -68,7 +68,8 @@ public class HalBrowserMvcEndpointBrowserPathIntegrationTests { MvcResult response = this.mockMvc .perform(get("/actuator/").accept(MediaType.TEXT_HTML)) .andExpect(status().isOk()).andReturn(); - assertEquals("/actuator/browser.html", response.getResponse().getForwardedUrl()); + assertThat(response.getResponse().getForwardedUrl()) + .isEqualTo("/actuator/browser.html"); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java index ffb22defe24..78538dfda1b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointDisabledIntegrationTests.java @@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -78,7 +78,8 @@ public class HalBrowserMvcEndpointDisabledIntegrationTests { MvcResult response = this.mockMvc .perform(get("/actuator/").accept(MediaType.TEXT_HTML)) .andExpect(status().isOk()).andReturn(); - assertEquals("/actuator/browser.html", response.getResponse().getForwardedUrl()); + assertThat(response.getResponse().getForwardedUrl()) + .isEqualTo("/actuator/browser.html"); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java index 77f17fd1356..2c06adad130 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointEndpointsDisabledIntegrationTests.java @@ -34,8 +34,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -91,7 +90,7 @@ public class HalBrowserMvcEndpointEndpointsDisabledIntegrationTests { @Test public void endpointsAllDisabled() throws Exception { - assertThat(this.mvcEndpoints.getEndpoints(), empty()); + assertThat(this.mvcEndpoints.getEndpoints()).isEmpty(); } @MinimalActuatorHypermediaApplication diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java index 855dc417572..78968489eda 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java @@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /** @@ -68,9 +67,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/spring/", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"_links\":")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"_links\":"); } @Test @@ -80,9 +78,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains(" entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/spring/actuator", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"_links\":")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"_links\":"); } @Test @@ -104,9 +100,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"_links\":")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"_links\":"); } @MinimalActuatorHypermediaApplication diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java index 6f9ca98e3a2..dbcf430ca62 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java @@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /** @@ -68,11 +67,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/actuator", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"_links\":")); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains(":" + this.port)); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"_links\":"); + assertThat(entity.getBody()).contains(":" + this.port); } @Test @@ -82,11 +79,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/actuator/", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"_links\":")); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains(":" + this.port)); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"_links\":"); + assertThat(entity.getBody()).contains(":" + this.port); } @Test @@ -96,9 +91,8 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/actuator/", HttpMethod.GET, new HttpEntity(null, headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains(" response = (ResponseEntity) result; - assertTrue(response.getBody().getStatus() == Status.DOWN); - assertEquals(HttpStatus.SERVICE_UNAVAILABLE, response.getStatusCode()); + assertThat(response.getBody().getStatus() == Status.DOWN).isTrue(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); } @Test @@ -104,10 +99,10 @@ public class HealthMvcEndpointTests { this.mvc.setStatusMapping( Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR)); Object result = this.mvc.invoke(null); - assertTrue(result instanceof ResponseEntity); + assertThat(result instanceof ResponseEntity).isTrue(); ResponseEntity response = (ResponseEntity) result; - assertTrue(response.getBody().getStatus().equals(new Status("OK"))); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + assertThat(response.getBody().getStatus().equals(new Status("OK"))).isTrue(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); } @Test @@ -118,10 +113,10 @@ public class HealthMvcEndpointTests { this.mvc.setStatusMapping(Collections.singletonMap("out-of-service", HttpStatus.INTERNAL_SERVER_ERROR)); Object result = this.mvc.invoke(null); - assertTrue(result instanceof ResponseEntity); + assertThat(result instanceof ResponseEntity).isTrue(); ResponseEntity response = (ResponseEntity) result; - assertTrue(response.getBody().getStatus().equals(Status.OUT_OF_SERVICE)); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + assertThat(response.getBody().getStatus().equals(Status.OUT_OF_SERVICE)).isTrue(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); } @Test @@ -130,9 +125,9 @@ public class HealthMvcEndpointTests { .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); given(this.endpoint.isSensitive()).willReturn(false); Object result = this.mvc.invoke(this.admin); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); - assertEquals("bar", ((Health) result).getDetails().get("foo")); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); + assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar"); } @Test @@ -140,9 +135,9 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(this.user); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); - assertNull(((Health) result).getDetails().get("foo")); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); + assertThat(((Health) result).getDetails().get("foo")).isNull(); } @Test @@ -152,19 +147,19 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(this.admin); - assertTrue(result instanceof Health); + assertThat(result instanceof Health).isTrue(); Health health = (Health) result; - assertTrue(health.getStatus() == Status.UP); - assertThat(health.getDetails().size(), is(equalTo(1))); - assertThat(health.getDetails().get("foo"), is(equalTo((Object) "bar"))); + assertThat(health.getStatus() == Status.UP).isTrue(); + assertThat(health.getDetails()).hasSize(1); + assertThat(health.getDetails().get("foo")).isEqualTo("bar"); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); result = this.mvc.invoke(null); // insecure now - assertTrue(result instanceof Health); + assertThat(result instanceof Health).isTrue(); health = (Health) result; // so the result is cached - assertTrue(health.getStatus() == Status.UP); + assertThat(health.getStatus() == Status.UP).isTrue(); // but the details are hidden - assertThat(health.getDetails().size(), is(equalTo(0))); + assertThat(health.getDetails()).isEmpty(); } @Test @@ -174,9 +169,9 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(null); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); - assertEquals("bar", ((Health) result).getDetails().get("foo")); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); + assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar"); } @Test @@ -185,9 +180,9 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(null); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); - assertNull(((Health) result).getDetails().get("foo")); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); + assertThat(((Health) result).getDetails().get("foo")).isNull(); } @Test @@ -198,9 +193,9 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(null); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); - assertEquals("bar", ((Health) result).getDetails().get("foo")); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); + assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar"); } @Test @@ -209,13 +204,13 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(null); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); result = this.mvc.invoke(null); @SuppressWarnings("unchecked") Health health = ((ResponseEntity) result).getBody(); - assertTrue(health.getStatus() == Status.DOWN); + assertThat(health.getStatus() == Status.DOWN).isTrue(); } @Test @@ -225,14 +220,14 @@ public class HealthMvcEndpointTests { given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); Object result = this.mvc.invoke(null); - assertTrue(result instanceof Health); - assertTrue(((Health) result).getStatus() == Status.UP); + assertThat(result instanceof Health).isTrue(); + assertThat(((Health) result).getStatus() == Status.UP).isTrue(); Thread.sleep(100); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); result = this.mvc.invoke(null); @SuppressWarnings("unchecked") Health health = ((ResponseEntity) result).getBody(); - assertTrue(health.getStatus() == Status.DOWN); + assertThat(health.getStatus() == Status.DOWN).isTrue(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java index f814720c338..9b9f0737561 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpointTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc; import java.util.Set; -import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,10 +42,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.instanceOf; -import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -78,10 +75,9 @@ public class JolokiaMvcEndpointTests { } @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) public void endpointRegistered() throws Exception { Set values = this.endpoints.getEndpoints(); - assertThat(values, (Matcher) hasItem(instanceOf(JolokiaMvcEndpoint.class))); + assertThat(values).hasAtLeastOneElementOfType(JolokiaMvcEndpoint.class); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java index 1c8b28caf18..27bd05d41db 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java @@ -31,9 +31,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.util.FileCopyUtils; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link LogFileMvcEndpoint}. @@ -67,7 +65,7 @@ public class LogFileMvcEndpointTests { MockHttpServletRequest request = new MockHttpServletRequest( HttpMethod.HEAD.name(), "/logfile"); this.mvc.invoke(request, response); - assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); + assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value()); } @Test @@ -77,7 +75,7 @@ public class LogFileMvcEndpointTests { MockHttpServletRequest request = new MockHttpServletRequest( HttpMethod.HEAD.name(), "/logfile"); this.mvc.invoke(request, response); - assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); + assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value()); } @Test @@ -87,7 +85,7 @@ public class LogFileMvcEndpointTests { MockHttpServletRequest request = new MockHttpServletRequest( HttpMethod.HEAD.name(), "/logfile"); this.mvc.invoke(request, response); - assertThat(response.getStatus(), equalTo(HttpStatus.OK.value())); + assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); } @Test @@ -98,7 +96,7 @@ public class LogFileMvcEndpointTests { MockHttpServletRequest request = new MockHttpServletRequest( HttpMethod.HEAD.name(), "/logfile"); this.mvc.invoke(request, response); - assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); + assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value()); } @Test @@ -108,8 +106,8 @@ public class LogFileMvcEndpointTests { MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/logfile"); this.mvc.invoke(request, response); - assertThat(response.getStatus(), equalTo(HttpStatus.OK.value())); - assertEquals("--TEST--", response.getContentAsString()); + assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); + assertThat(response.getContentAsString()).isEqualTo("--TEST--"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java index 6b1efe420ec..a9ccf712990 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointsTests.java @@ -22,7 +22,7 @@ import org.springframework.boot.actuate.endpoint.AbstractEndpoint; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.support.StaticApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MvcEndpoints}. @@ -41,7 +41,7 @@ public class MvcEndpointsTests { new TestEndpoint()); this.endpoints.setApplicationContext(this.context); this.endpoints.afterPropertiesSet(); - assertEquals(1, this.endpoints.getEndpoints().size()); + assertThat(this.endpoints.getEndpoints()).hasSize(1); } @Test @@ -52,7 +52,7 @@ public class MvcEndpointsTests { new TestEndpoint()); this.endpoints.setApplicationContext(this.context); this.endpoints.afterPropertiesSet(); - assertEquals(1, this.endpoints.getEndpoints().size()); + assertThat(this.endpoints.getEndpoints()).hasSize(1); } @Test @@ -61,7 +61,7 @@ public class MvcEndpointsTests { new EndpointMvcAdapter(new TestEndpoint())); this.endpoints.setApplicationContext(this.context); this.endpoints.afterPropertiesSet(); - assertEquals(1, this.endpoints.getEndpoints().size()); + assertThat(this.endpoints.getEndpoints()).hasSize(1); } @Test @@ -72,9 +72,9 @@ public class MvcEndpointsTests { new TestEndpoint()); this.endpoints.setApplicationContext(this.context); this.endpoints.afterPropertiesSet(); - assertEquals(1, this.endpoints.getEndpoints().size()); - assertEquals("/foo/bar", - this.endpoints.getEndpoints().iterator().next().getPath()); + assertThat(this.endpoints.getEndpoints()).hasSize(1); + assertThat(this.endpoints.getEndpoints().iterator().next().getPath()) + .isEqualTo("/foo/bar"); } protected static class TestEndpoint extends AbstractEndpoint { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java index 838c190c650..7401cf0a300 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java @@ -20,11 +20,7 @@ import java.util.Map; import org.junit.Test; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link NamePatternFilter}. @@ -37,54 +33,54 @@ public class NamePatternFilterTests { @Test public void nonRegex() throws Exception { MockNamePatternFilter filter = new MockNamePatternFilter(); - assertThat(filter.getResults("not.a.regex"), - hasEntry("not.a.regex", (Object) "not.a.regex")); - assertThat(filter.isGetNamesCalled(), equalTo(false)); + assertThat(filter.getResults("not.a.regex")).containsEntry("not.a.regex", + "not.a.regex"); + assertThat(filter.isGetNamesCalled()).isFalse(); } @Test public void regexRepetitionZeroOrMore() { MockNamePatternFilter filter = new MockNamePatternFilter(); Map results = filter.getResults("fo.*"); - assertThat(results.get("foo"), equalTo((Object) "foo")); - assertThat(results.get("fool"), equalTo((Object) "fool")); - assertThat(filter.isGetNamesCalled(), equalTo(true)); + assertThat(results.get("foo")).isEqualTo("foo"); + assertThat(results.get("fool")).isEqualTo("fool"); + assertThat(filter.isGetNamesCalled()).isTrue(); } @Test public void regexRepetitionOneOrMore() { MockNamePatternFilter filter = new MockNamePatternFilter(); Map results = filter.getResults("fo.+"); - assertThat(results.get("foo"), equalTo((Object) "foo")); - assertThat(results.get("fool"), equalTo((Object) "fool")); - assertThat(filter.isGetNamesCalled(), equalTo(true)); + assertThat(results.get("foo")).isEqualTo("foo"); + assertThat(results.get("fool")).isEqualTo("fool"); + assertThat(filter.isGetNamesCalled()).isTrue(); } @Test public void regexEndAnchor() { MockNamePatternFilter filter = new MockNamePatternFilter(); Map results = filter.getResults("foo$"); - assertThat(results.get("foo"), equalTo((Object) "foo")); - assertThat(results.get("fool"), is(nullValue())); - assertThat(filter.isGetNamesCalled(), equalTo(true)); + assertThat(results.get("foo")).isEqualTo("foo"); + assertThat(results.get("fool")).isNull(); + assertThat(filter.isGetNamesCalled()).isTrue(); } @Test public void regexStartAnchor() { MockNamePatternFilter filter = new MockNamePatternFilter(); Map results = filter.getResults("^foo"); - assertThat(results.get("foo"), equalTo((Object) "foo")); - assertThat(results.get("fool"), is(nullValue())); - assertThat(filter.isGetNamesCalled(), equalTo(true)); + assertThat(results.get("foo")).isEqualTo("foo"); + assertThat(results.get("fool")).isNull(); + assertThat(filter.isGetNamesCalled()).isTrue(); } @Test public void regexCharacterClass() { MockNamePatternFilter filter = new MockNamePatternFilter(); Map results = filter.getResults("fo[a-z]l"); - assertThat(results.get("foo"), is(nullValue())); - assertThat(results.get("fool"), equalTo((Object) "fool")); - assertThat(filter.isGetNamesCalled(), equalTo(true)); + assertThat(results.get("foo")).isNull(); + assertThat(results.get("fool")).isEqualTo("fool"); + assertThat(filter.isGetNamesCalled()).isTrue(); } private static class MockNamePatternFilter extends NamePatternFilter { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java index e5b2e61236b..909d00dd2de 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpointTests.java @@ -24,7 +24,7 @@ import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; /** @@ -43,7 +43,7 @@ public class ShutdownMvcEndpointTests { @SuppressWarnings("unchecked") ResponseEntity> response = (ResponseEntity>) this.mvc .invoke(); - assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ApplicationHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ApplicationHealthIndicatorTests.java index 4c0eab893bd..825ff894c03 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ApplicationHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ApplicationHealthIndicatorTests.java @@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link ApplicationHealthIndicator}. @@ -30,7 +30,7 @@ public class ApplicationHealthIndicatorTests { @Test public void indicatesUp() throws Exception { ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator(); - assertEquals(Status.UP, healthIndicator.health().getStatus()); + assertThat(healthIndicator.health().getStatus()).isEqualTo(Status.UP); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java index 1700cac7581..39154d2b90b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java @@ -25,10 +25,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasEntry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; /** @@ -72,11 +69,11 @@ public class CompositeHealthIndicatorTests { CompositeHealthIndicator composite = new CompositeHealthIndicator( this.healthAggregator, indicators); Health result = composite.health(); - assertThat(result.getDetails().size(), equalTo(2)); - assertThat(result.getDetails(), hasEntry("one", - (Object) new Health.Builder().unknown().withDetail("1", "1").build())); - assertThat(result.getDetails(), hasEntry("two", - (Object) new Health.Builder().unknown().withDetail("2", "2").build())); + assertThat(result.getDetails()).hasSize(2); + assertThat(result.getDetails()).containsEntry("one", + new Health.Builder().unknown().withDetail("1", "1").build()); + assertThat(result.getDetails()).containsEntry("two", + new Health.Builder().unknown().withDetail("2", "2").build()); } @Test @@ -88,13 +85,13 @@ public class CompositeHealthIndicatorTests { this.healthAggregator, indicators); composite.addHealthIndicator("three", this.three); Health result = composite.health(); - assertThat(result.getDetails().size(), equalTo(3)); - assertThat(result.getDetails(), hasEntry("one", - (Object) new Health.Builder().unknown().withDetail("1", "1").build())); - assertThat(result.getDetails(), hasEntry("two", - (Object) new Health.Builder().unknown().withDetail("2", "2").build())); - assertThat(result.getDetails(), hasEntry("three", - (Object) new Health.Builder().unknown().withDetail("3", "3").build())); + assertThat(result.getDetails()).hasSize(3); + assertThat(result.getDetails()).containsEntry("one", + new Health.Builder().unknown().withDetail("1", "1").build()); + assertThat(result.getDetails()).containsEntry("two", + new Health.Builder().unknown().withDetail("2", "2").build()); + assertThat(result.getDetails()).containsEntry("three", + new Health.Builder().unknown().withDetail("3", "3").build()); } @Test @@ -104,11 +101,11 @@ public class CompositeHealthIndicatorTests { composite.addHealthIndicator("one", this.one); composite.addHealthIndicator("two", this.two); Health result = composite.health(); - assertThat(result.getDetails().size(), equalTo(2)); - assertThat(result.getDetails(), hasEntry("one", - (Object) new Health.Builder().unknown().withDetail("1", "1").build())); - assertThat(result.getDetails(), hasEntry("two", - (Object) new Health.Builder().unknown().withDetail("2", "2").build())); + assertThat(result.getDetails().size()).isEqualTo(2); + assertThat(result.getDetails()).containsEntry("one", + new Health.Builder().unknown().withDetail("1", "1").build()); + assertThat(result.getDetails()).containsEntry("two", + new Health.Builder().unknown().withDetail("2", "2").build()); } @Test @@ -121,15 +118,12 @@ public class CompositeHealthIndicatorTests { CompositeHealthIndicator composite = new CompositeHealthIndicator( this.healthAggregator); composite.addHealthIndicator("db", innerComposite); - Health result = composite.health(); - ObjectMapper mapper = new ObjectMapper(); - assertEquals( - "{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\"" + assertThat(mapper.writeValueAsString(result)) + .isEqualTo("{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\"" + ",\"db1\":{\"status\":\"UNKNOWN\",\"1\":\"1\"}," - + "\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}", - mapper.writeValueAsString(result)); + + "\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java index 62fcf46beb6..1ac7811ae72 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DataSourceHealthIndicatorTests.java @@ -29,12 +29,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SingleConnectionDataSource; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -70,8 +65,8 @@ public class DataSourceHealthIndicatorTests { public void database() { this.indicator.setDataSource(this.dataSource); Health health = this.indicator.health(); - assertNotNull(health.getDetails().get("database")); - assertNotNull(health.getDetails().get("hello")); + assertThat(health.getDetails().get("database")).isNotNull(); + assertThat(health.getDetails().get("hello")).isNotNull(); } @Test @@ -82,9 +77,9 @@ public class DataSourceHealthIndicatorTests { this.indicator.setQuery("SELECT COUNT(*) from FOO"); Health health = this.indicator.health(); System.err.println(health); - assertNotNull(health.getDetails().get("database")); - assertEquals(Status.UP, health.getStatus()); - assertNotNull(health.getDetails().get("hello")); + assertThat(health.getDetails().get("database")).isNotNull(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("hello")).isNotNull(); } @Test @@ -92,8 +87,8 @@ public class DataSourceHealthIndicatorTests { this.indicator.setDataSource(this.dataSource); this.indicator.setQuery("SELECT COUNT(*) from BAR"); Health health = this.indicator.health(); - assertThat(health.getDetails().get("database"), notNullValue()); - assertEquals(Status.DOWN, health.getStatus()); + assertThat(health.getDetails().get("database")).isNotNull(); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); } @Test @@ -105,24 +100,24 @@ public class DataSourceHealthIndicatorTests { given(dataSource.getConnection()).willReturn(connection); this.indicator.setDataSource(dataSource); Health health = this.indicator.health(); - assertNotNull(health.getDetails().get("database")); + assertThat(health.getDetails().get("database")).isNotNull(); verify(connection, times(2)).close(); } @Test public void productLookups() throws Exception { - assertThat(Product.forProduct("newone"), nullValue()); - assertThat(Product.forProduct("HSQL Database Engine"), equalTo(Product.HSQLDB)); - assertThat(Product.forProduct("Oracle"), equalTo(Product.ORACLE)); - assertThat(Product.forProduct("Apache Derby"), equalTo(Product.DERBY)); - assertThat(Product.forProduct("DB2"), equalTo(Product.DB2)); - assertThat(Product.forProduct("DB2/LINUXX8664"), equalTo(Product.DB2)); - assertThat(Product.forProduct("DB2 UDB for AS/400"), equalTo(Product.DB2_AS400)); - assertThat(Product.forProduct("DB3 XDB for AS/400"), equalTo(Product.DB2_AS400)); - assertThat(Product.forProduct("Informix Dynamic Server"), - equalTo(Product.INFORMIX)); - assertThat(Product.forProduct("Firebird 2.5.WI"), equalTo(Product.FIREBIRD)); - assertThat(Product.forProduct("Firebird 2.1.LI"), equalTo(Product.FIREBIRD)); + assertThat(Product.forProduct("newone")).isNull(); + assertThat(Product.forProduct("HSQL Database Engine")).isEqualTo(Product.HSQLDB); + assertThat(Product.forProduct("Oracle")).isEqualTo(Product.ORACLE); + assertThat(Product.forProduct("Apache Derby")).isEqualTo(Product.DERBY); + assertThat(Product.forProduct("DB2")).isEqualTo(Product.DB2); + assertThat(Product.forProduct("DB2/LINUXX8664")).isEqualTo(Product.DB2); + assertThat(Product.forProduct("DB2 UDB for AS/400")).isEqualTo(Product.DB2_AS400); + assertThat(Product.forProduct("DB3 XDB for AS/400")).isEqualTo(Product.DB2_AS400); + assertThat(Product.forProduct("Informix Dynamic Server")) + .isEqualTo(Product.INFORMIX); + assertThat(Product.forProduct("Firebird 2.5.WI")).isEqualTo(Product.FIREBIRD); + assertThat(Product.forProduct("Firebird 2.1.LI")).isEqualTo(Product.FIREBIRD); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java index 69a9c0cdafe..c78971a436d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java @@ -26,7 +26,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; /** @@ -60,10 +60,10 @@ public class DiskSpaceHealthIndicatorTests { given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10); given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); Health health = this.healthIndicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); - assertEquals(THRESHOLD_BYTES + 10, health.getDetails().get("free")); - assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD_BYTES); + assertThat(health.getDetails().get("free")).isEqualTo(THRESHOLD_BYTES + 10); + assertThat(health.getDetails().get("total")).isEqualTo(THRESHOLD_BYTES * 10); } @Test @@ -71,10 +71,10 @@ public class DiskSpaceHealthIndicatorTests { given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10); given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); Health health = this.healthIndicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); - assertEquals(THRESHOLD_BYTES - 10, health.getDetails().get("free")); - assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD_BYTES); + assertThat(health.getDetails().get("free")).isEqualTo(THRESHOLD_BYTES - 10); + assertThat(health.getDetails().get("total")).isEqualTo(THRESHOLD_BYTES * 10); } private DiskSpaceHealthIndicatorProperties createProperties(File path, diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java index 713a682b544..9413d97fb4d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java @@ -39,11 +39,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import static org.hamcrest.Matchers.arrayContaining; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; @@ -84,9 +80,9 @@ public class ElasticsearchHealthIndicatorTests { .forClass(ClusterHealthRequest.class); given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture); Health health = this.indicator.health(); - assertThat(responseFuture.getTimeout, is(100L)); - assertThat(requestCaptor.getValue().indices(), is(arrayContaining("_all"))); - assertThat(health.getStatus(), is(Status.UP)); + assertThat(responseFuture.getTimeout).isEqualTo(100L); + assertThat(requestCaptor.getValue().indices()).contains("_all"); + assertThat(health.getStatus()).isEqualTo(Status.UP); } @Test @@ -99,9 +95,9 @@ public class ElasticsearchHealthIndicatorTests { this.properties.getIndices() .addAll(Arrays.asList("test-index-1", "test-index-2")); Health health = this.indicator.health(); - assertThat(requestCaptor.getValue().indices(), - is(arrayContaining("test-index-1", "test-index-2"))); - assertThat(health.getStatus(), is(Status.UP)); + assertThat(requestCaptor.getValue().indices()).contains("test-index-1", + "test-index-2"); + assertThat(health.getStatus()).isEqualTo(Status.UP); } @Test @@ -113,7 +109,7 @@ public class ElasticsearchHealthIndicatorTests { given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture); this.properties.setResponseTimeout(1000L); this.indicator.health(); - assertThat(responseFuture.getTimeout, is(1000L)); + assertThat(responseFuture.getTimeout).isEqualTo(1000L); } @Test @@ -123,7 +119,7 @@ public class ElasticsearchHealthIndicatorTests { given(this.cluster.health(any(ClusterHealthRequest.class))) .willReturn(responseFuture); Health health = this.indicator.health(); - assertThat(health.getStatus(), is(Status.UP)); + assertThat(health.getStatus()).isEqualTo(Status.UP); Map details = health.getDetails(); assertDetail(details, "clusterName", "test-cluster"); assertDetail(details, "activeShards", 1); @@ -141,7 +137,7 @@ public class ElasticsearchHealthIndicatorTests { responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED)); given(this.cluster.health(any(ClusterHealthRequest.class))) .willReturn(responseFuture); - assertThat(this.indicator.health().getStatus(), is(Status.DOWN)); + assertThat(this.indicator.health().getStatus()).isEqualTo(Status.DOWN); } @Test @@ -151,7 +147,7 @@ public class ElasticsearchHealthIndicatorTests { .onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW)); given(this.cluster.health(any(ClusterHealthRequest.class))) .willReturn(responseFuture); - assertThat(this.indicator.health().getStatus(), is(Status.UP)); + assertThat(this.indicator.health().getStatus()).isEqualTo(Status.UP); } @Test @@ -160,14 +156,14 @@ public class ElasticsearchHealthIndicatorTests { given(this.cluster.health(any(ClusterHealthRequest.class))) .willReturn(responseFuture); Health health = this.indicator.health(); - assertThat(health.getStatus(), is(Status.DOWN)); - assertThat((String) health.getDetails().get("error"), - containsString(ElasticsearchTimeoutException.class.getName())); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat((String) health.getDetails().get("error")) + .contains(ElasticsearchTimeoutException.class.getName()); } @SuppressWarnings("unchecked") private void assertDetail(Map details, String detail, T value) { - assertThat((T) details.get(detail), is(equalTo(value))); + assertThat((T) details.get(detail)).isEqualTo(value); } private final static class StubClusterHealthResponse extends ClusterHealthResponse { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthTests.java index c3ad64e04f5..edde833b009 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthTests.java @@ -22,9 +22,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link Health}. @@ -46,16 +44,16 @@ public class HealthTests { @Test public void createWithStatus() throws Exception { Health health = Health.status(Status.UP).build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void createWithDetails() throws Exception { Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) .build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().get("a"), equalTo((Object) "b")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("a")).isEqualTo("b"); } @Test @@ -65,12 +63,12 @@ public class HealthTests { Health h2 = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) .build(); Health h3 = new Health.Builder(Status.UP).build(); - assertThat(h1, equalTo(h1)); - assertThat(h1, equalTo(h2)); - assertThat(h1, not(equalTo(h3))); - assertThat(h1.hashCode(), equalTo(h1.hashCode())); - assertThat(h1.hashCode(), equalTo(h2.hashCode())); - assertThat(h1.hashCode(), not(equalTo(h3.hashCode()))); + assertThat(h1).isEqualTo(h1); + assertThat(h1).isEqualTo(h2); + assertThat(h1).isNotEqualTo(h3); + assertThat(h1.hashCode()).isEqualTo(h1.hashCode()); + assertThat(h1.hashCode()).isEqualTo(h2.hashCode()); + assertThat(h1.hashCode()).isNotEqualTo(h3.hashCode()); } @Test @@ -78,82 +76,82 @@ public class HealthTests { RuntimeException ex = new RuntimeException("bang"); Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) .withException(ex).build(); - assertThat(health.getDetails().get("a"), equalTo((Object) "b")); - assertThat(health.getDetails().get("error"), - equalTo((Object) "java.lang.RuntimeException: bang")); + assertThat(health.getDetails().get("a")).isEqualTo("b"); + assertThat(health.getDetails().get("error")) + .isEqualTo("java.lang.RuntimeException: bang"); } @Test public void withDetails() throws Exception { Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) .withDetail("c", "d").build(); - assertThat(health.getDetails().get("a"), equalTo((Object) "b")); - assertThat(health.getDetails().get("c"), equalTo((Object) "d")); + assertThat(health.getDetails().get("a")).isEqualTo("b"); + assertThat(health.getDetails().get("c")).isEqualTo("d"); } @Test public void unknownWithDetails() throws Exception { Health health = new Health.Builder().unknown().withDetail("a", "b").build(); - assertThat(health.getStatus(), equalTo(Status.UNKNOWN)); - assertThat(health.getDetails().get("a"), equalTo((Object) "b")); + assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); + assertThat(health.getDetails().get("a")).isEqualTo("b"); } @Test public void unknown() throws Exception { Health health = new Health.Builder().unknown().build(); - assertThat(health.getStatus(), equalTo(Status.UNKNOWN)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void upWithDetails() throws Exception { Health health = new Health.Builder().up().withDetail("a", "b").build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().get("a"), equalTo((Object) "b")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("a")).isEqualTo("b"); } @Test public void up() throws Exception { Health health = new Health.Builder().up().build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void downWithException() throws Exception { RuntimeException ex = new RuntimeException("bang"); Health health = Health.down(ex).build(); - assertThat(health.getStatus(), equalTo(Status.DOWN)); - assertThat(health.getDetails().get("error"), - equalTo((Object) "java.lang.RuntimeException: bang")); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().get("error")) + .isEqualTo("java.lang.RuntimeException: bang"); } @Test public void down() throws Exception { Health health = Health.down().build(); - assertThat(health.getStatus(), equalTo(Status.DOWN)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void outOfService() throws Exception { Health health = Health.outOfService().build(); - assertThat(health.getStatus(), equalTo(Status.OUT_OF_SERVICE)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void statusCode() throws Exception { Health health = Health.status("UP").build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().size()).isEqualTo(0); } @Test public void status() throws Exception { Health health = Health.status(Status.UP).build(); - assertThat(health.getStatus(), equalTo(Status.UP)); - assertThat(health.getDetails().size(), equalTo(0)); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().size()).isEqualTo(0); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/JmsHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/JmsHealthIndicatorTests.java index b10a1eb8cb2..5be69b8a9bf 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/JmsHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/JmsHealthIndicatorTests.java @@ -23,7 +23,7 @@ import javax.jms.JMSException; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -46,8 +46,8 @@ public class JmsHealthIndicatorTests { given(connectionFactory.createConnection()).willReturn(connection); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); Health health = indicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals("JMS test provider", health.getDetails().get("provider")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider"); verify(connection, times(1)).close(); } @@ -58,8 +58,8 @@ public class JmsHealthIndicatorTests { .willThrow(new JMSException("test", "123")); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); Health health = indicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertEquals(null, health.getDetails().get("provider")); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().get("provider")).isNull(); } @Test @@ -73,8 +73,8 @@ public class JmsHealthIndicatorTests { given(connectionFactory.createConnection()).willReturn(connection); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); Health health = indicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertEquals(null, health.getDetails().get("provider")); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().get("provider")).isNull(); verify(connection, times(1)).close(); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java index 63832896059..a0ba3f7f358 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java @@ -32,9 +32,7 @@ import org.junit.Test; import org.springframework.mail.javamail.JavaMailSenderImpl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; @@ -67,8 +65,8 @@ public class MailHealthIndicatorTests { public void smtpIsUp() { given(this.mailSender.getProtocol()).willReturn("success"); Health health = this.indicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals("smtp.acme.org:25", health.getDetails().get("location")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25"); } @Test @@ -76,11 +74,11 @@ public class MailHealthIndicatorTests { willThrow(new MessagingException("A test exception")).given(this.mailSender) .testConnection(); Health health = this.indicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertEquals("smtp.acme.org:25", health.getDetails().get("location")); + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25"); Object errorMessage = health.getDetails().get("error"); - assertNotNull(errorMessage); - assertTrue(errorMessage.toString().contains("A test exception")); + assertThat(errorMessage).isNotNull(); + assertThat(errorMessage.toString().contains("A test exception")).isTrue(); } public static class SuccessTransport extends Transport { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java index a02af1e4672..95893a52b93 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java @@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.mongodb.core.MongoTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -58,10 +56,11 @@ public class MongoHealthIndicatorTests { PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); - assertEquals(1, this.context.getBeanNamesForType(MongoTemplate.class).length); + assertThat(this.context.getBeanNamesForType(MongoTemplate.class).length) + .isEqualTo(1); MongoHealthIndicator healthIndicator = this.context .getBean(MongoHealthIndicator.class); - assertNotNull(healthIndicator); + assertThat(healthIndicator).isNotNull(); } @Test @@ -71,11 +70,9 @@ public class MongoHealthIndicatorTests { MongoTemplate mongoTemplate = mock(MongoTemplate.class); given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); - Health health = healthIndicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals("2.6.4", health.getDetails().get("version")); - + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("version")).isEqualTo("2.6.4"); verify(commandResult).getString("version"); verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } @@ -86,12 +83,11 @@ public class MongoHealthIndicatorTests { given(mongoTemplate.executeCommand("{ buildInfo: 1 }")) .willThrow(new MongoException("Connection failed")); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); - Health health = healthIndicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertTrue(((String) health.getDetails().get("error")) + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(((String) health.getDetails().get("error")) .contains("Connection failed")); - verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java index a2185250ac6..f950a93a800 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/OrderedHealthAggregatorTests.java @@ -23,7 +23,7 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link OrderedHealthAggregator}. @@ -46,7 +46,8 @@ public class OrderedHealthAggregatorTests { healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - assertEquals(Status.DOWN, this.healthAggregator.aggregate(healths).getStatus()); + assertThat(this.healthAggregator.aggregate(healths).getStatus()) + .isEqualTo(Status.DOWN); } @Test @@ -58,8 +59,8 @@ public class OrderedHealthAggregatorTests { healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); - assertEquals(Status.UNKNOWN, - this.healthAggregator.aggregate(healths).getStatus()); + assertThat(this.healthAggregator.aggregate(healths).getStatus()) + .isEqualTo(Status.UNKNOWN); } @Test @@ -70,7 +71,8 @@ public class OrderedHealthAggregatorTests { healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build()); - assertEquals(Status.DOWN, this.healthAggregator.aggregate(healths).getStatus()); + assertThat(this.healthAggregator.aggregate(healths).getStatus()) + .isEqualTo(Status.DOWN); } @Test @@ -83,7 +85,8 @@ public class OrderedHealthAggregatorTests { healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build()); - assertEquals(Status.DOWN, this.healthAggregator.aggregate(healths).getStatus()); + assertThat(this.healthAggregator.aggregate(healths).getStatus()) + .isEqualTo(Status.DOWN); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java index 30727b10c4a..9b9f3c71c37 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java @@ -26,8 +26,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link RabbitHealthIndicator}. @@ -50,10 +49,11 @@ public class RabbitHealthIndicatorTests { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); - assertEquals(1, this.context.getBeanNamesForType(RabbitAdmin.class).length); + assertThat(this.context.getBeanNamesForType(RabbitAdmin.class).length) + .isEqualTo(1); RabbitHealthIndicator healthIndicator = this.context .getBean(RabbitHealthIndicator.class); - assertNotNull(healthIndicator); + assertThat(healthIndicator).isNotNull(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java index e20367ded20..e48c0802263 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java @@ -30,9 +30,7 @@ import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -58,18 +56,17 @@ public class RedisHealthIndicatorTests { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, RedisAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); - assertEquals(1, - this.context.getBeanNamesForType(RedisConnectionFactory.class).length); + assertThat(this.context.getBeanNamesForType(RedisConnectionFactory.class)) + .hasSize(1); RedisHealthIndicator healthIndicator = this.context .getBean(RedisHealthIndicator.class); - assertNotNull(healthIndicator); + assertThat(healthIndicator).isNotNull(); } @Test public void redisIsUp() throws Exception { Properties info = new Properties(); info.put("redis_version", "2.8.9"); - RedisConnection redisConnection = mock(RedisConnection.class); RedisConnectionFactory redisConnectionFactory = mock( RedisConnectionFactory.class); @@ -77,11 +74,9 @@ public class RedisHealthIndicatorTests { given(redisConnection.info()).willReturn(info); RedisHealthIndicator healthIndicator = new RedisHealthIndicator( redisConnectionFactory); - Health health = healthIndicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals("2.8.9", health.getDetails().get("version")); - + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("version")).isEqualTo("2.8.9"); verify(redisConnectionFactory).getConnection(); verify(redisConnection).info(); } @@ -96,13 +91,12 @@ public class RedisHealthIndicatorTests { .willThrow(new RedisConnectionFailureException("Connection failed")); RedisHealthIndicator healthIndicator = new RedisHealthIndicator( redisConnectionFactory); - Health health = healthIndicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertTrue(((String) health.getDetails().get("error")) + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(((String) health.getDetails().get("error")) .contains("Connection failed")); - verify(redisConnectionFactory).getConnection(); verify(redisConnection).info(); } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java index 14ccbcb41bd..4ffc295dbe2 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java @@ -30,9 +30,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -57,10 +55,11 @@ public class SolrHealthIndicatorTests { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, SolrAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); - assertEquals(1, this.context.getBeanNamesForType(SolrServer.class).length); + assertThat(this.context.getBeanNamesForType(SolrServer.class).length) + .isEqualTo(1); SolrHealthIndicator healthIndicator = this.context .getBean(SolrHealthIndicator.class); - assertNotNull(healthIndicator); + assertThat(healthIndicator).isNotNull(); } @Test @@ -71,22 +70,21 @@ public class SolrHealthIndicatorTests { response.add("status", "OK"); pingResponse.setResponse(response); given(solrServer.ping()).willReturn(pingResponse); - SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); Health health = healthIndicator.health(); - assertEquals(Status.UP, health.getStatus()); - assertEquals("OK", health.getDetails().get("solrStatus")); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails().get("solrStatus")).isEqualTo("OK"); } @Test public void solrIsDown() throws Exception { SolrServer solrServer = mock(SolrServer.class); given(solrServer.ping()).willThrow(new IOException("Connection failed")); - SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); Health health = healthIndicator.health(); - assertEquals(Status.DOWN, health.getStatus()); - assertTrue(((String) health.getDetails().get("error")) + assertThat(health.getStatus()).isEqualTo(Status.DOWN); + assertThat(((String) health.getDetails().get("error")) .contains("Connection failed")); } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReaderTests.java index 2d2311746d8..92e84e3c666 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/aggregate/AggregateMetricReaderTests.java @@ -24,8 +24,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; import org.springframework.boot.actuate.metrics.writer.Delta; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link AggregateMetricReader}. @@ -41,20 +40,21 @@ public class AggregateMetricReaderTests { @Test public void writeAndReadDefaults() { this.source.set(new Metric("foo.bar.spam", 2.3)); - assertEquals(2.3, this.reader.findOne("aggregate.spam").getValue()); + assertThat(this.reader.findOne("aggregate.spam").getValue()).isEqualTo(2.3); } @Test public void defaultKeyPattern() { this.source.set(new Metric("foo.bar.spam.bucket.wham", 2.3)); - assertEquals(2.3, this.reader.findOne("aggregate.spam.bucket.wham").getValue()); + assertThat(this.reader.findOne("aggregate.spam.bucket.wham").getValue()) + .isEqualTo(2.3); } @Test public void addKeyPattern() { this.source.set(new Metric("foo.bar.spam.bucket.wham", 2.3)); this.reader.setKeyPattern("d.d.k.d"); - assertEquals(2.3, this.reader.findOne("aggregate.spam.wham").getValue()); + assertThat(this.reader.findOne("aggregate.spam.wham").getValue()).isEqualTo(2.3); } @Test @@ -63,42 +63,43 @@ public class AggregateMetricReaderTests { this.source.set(new Metric("off.bar.spam.bucket.wham", 2.4)); this.reader.setPrefix("www"); this.reader.setKeyPattern("k.d.k.d"); - assertEquals(2.3, this.reader.findOne("www.foo.spam.wham").getValue()); - assertEquals(2, this.reader.count()); + assertThat(this.reader.findOne("www.foo.spam.wham").getValue()).isEqualTo(2.3); + assertThat(this.reader.count()).isEqualTo(2); } @Test public void writeAndReadExtraLong() { this.source.set(new Metric("blee.foo.bar.spam", 2.3)); this.reader.setKeyPattern("d.d.d.k"); - assertEquals(2.3, this.reader.findOne("aggregate.spam").getValue()); + assertThat(this.reader.findOne("aggregate.spam").getValue()).isEqualTo(2.3); } @Test public void writeAndReadLatestValue() { this.source.set(new Metric("foo.bar.spam", 2.3, new Date(100L))); this.source.set(new Metric("oof.rab.spam", 2.4, new Date(0L))); - assertEquals(2.3, this.reader.findOne("aggregate.spam").getValue()); + assertThat(this.reader.findOne("aggregate.spam").getValue()).isEqualTo(2.3); } @Test public void onlyPrefixed() { this.source.set(new Metric("foo.bar.spam", 2.3)); - assertNull(this.reader.findOne("spam")); + assertThat(this.reader.findOne("spam")).isNull(); } @Test public void incrementCounter() { this.source.increment(new Delta("foo.bar.counter.spam", 2L)); this.source.increment(new Delta("oof.rab.counter.spam", 3L)); - assertEquals(5L, this.reader.findOne("aggregate.counter.spam").getValue()); + assertThat(this.reader.findOne("aggregate.counter.spam").getValue()) + .isEqualTo(5L); } @Test public void countGauges() { this.source.set(new Metric("foo.bar.spam", 2.3)); this.source.set(new Metric("oof.rab.spam", 2.4)); - assertEquals(1, this.reader.count()); + assertThat(this.reader.count()).isEqualTo(1); } @Test @@ -107,7 +108,7 @@ public class AggregateMetricReaderTests { this.source.set(new Metric("oof.rab.spam", 2.4)); this.source.increment(new Delta("foo.bar.counter.spam", 2L)); this.source.increment(new Delta("oof.rab.counter.spam", 3L)); - assertEquals(2, this.reader.count()); + assertThat(this.reader.count()).isEqualTo(2); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java index e30c879196a..bb01907559f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferGaugeServiceSpeedTests.java @@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.lang.UsesJava8; import org.springframework.util.StopWatch; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Speed tests for {@link BufferGaugeService}. @@ -117,7 +117,7 @@ public class BufferGaugeServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertTrue(number * threadCount < total.longValue()); + assertThat(number * threadCount < total.longValue()).isTrue(); } @Theory @@ -141,7 +141,7 @@ public class BufferGaugeServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertTrue(0 < total.longValue()); + assertThat(0 < total.longValue()).isTrue(); } private void iterate(String taskName) throws Exception { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReaderTests.java index d20a1e946a3..65093e2de74 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReaderTests.java @@ -18,8 +18,7 @@ package org.springframework.boot.actuate.metrics.buffer; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link BufferMetricReader}. @@ -39,21 +38,21 @@ public class BufferMetricReaderTests { public void countReflectsNumberOfMetrics() { this.gauges.set("foo", 1); this.counters.increment("bar", 2); - assertEquals(2, this.reader.count()); + assertThat(this.reader.count()).isEqualTo(2); } @Test public void findGauge() { this.gauges.set("foo", 1); - assertNotNull(this.reader.findOne("foo")); - assertEquals(1, this.reader.count()); + assertThat(this.reader.findOne("foo")).isNotNull(); + assertThat(this.reader.count()).isEqualTo(1); } @Test public void findCounter() { this.counters.increment("foo", 1); - assertNotNull(this.reader.findOne("foo")); - assertEquals(1, this.reader.count()); + assertThat(this.reader.findOne("foo")).isNotNull(); + assertThat(this.reader.count()).isEqualTo(1); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffersTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffersTests.java index afc65e445dd..323c8e4880a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffersTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffersTests.java @@ -20,8 +20,7 @@ import java.util.function.Consumer; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link CounterBuffers}. @@ -43,7 +42,7 @@ public class CounterBuffersTests { CounterBuffersTests.this.value = buffer.getValue(); } }); - assertEquals(2, this.value); + assertThat(this.value).isEqualTo(2); } @Test @@ -54,12 +53,12 @@ public class CounterBuffersTests { CounterBuffersTests.this.value = buffer.getValue(); } }); - assertEquals(0, this.value); + assertThat(this.value).isEqualTo(0); } @Test public void findNonExistent() { - assertNull(this.buffers.find("foo")); + assertThat(this.buffers.find("foo")).isNull(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterServiceSpeedTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterServiceSpeedTests.java index f7bd7b6344e..0efd1810d1b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterServiceSpeedTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/CounterServiceSpeedTests.java @@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.lang.UsesJava8; import org.springframework.util.StopWatch; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Speed tests for {@link CounterService}. @@ -116,7 +116,7 @@ public class CounterServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertEquals(number * threadCount, total.longValue()); + assertThat(total.longValue()).isEqualTo(number * threadCount); } @Theory @@ -140,7 +140,7 @@ public class CounterServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertEquals(number * threadCount, total.longValue()); + assertThat(total.longValue()).isEqualTo(number * threadCount); } private void iterate(String taskName) throws Exception { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultCounterServiceSpeedTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultCounterServiceSpeedTests.java index 60e8947750e..0b3362a337b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultCounterServiceSpeedTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultCounterServiceSpeedTests.java @@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultCounterService; import org.springframework.lang.UsesJava8; import org.springframework.util.StopWatch; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Speed tests for {@link DefaultCounterService}. @@ -124,7 +124,7 @@ public class DefaultCounterServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertEquals(number * threadCount, total.longValue()); + assertThat(total.longValue()).isEqualTo(number * threadCount); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java index bd84d21f7d5..2615372a2df 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DefaultGaugeServiceSpeedTests.java @@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultGaugeService; import org.springframework.lang.UsesJava8; import org.springframework.util.StopWatch; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Speed tests for {@link DefaultGaugeService}. @@ -125,7 +125,7 @@ public class DefaultGaugeServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertTrue(0 < total.longValue()); + assertThat(0 < total.longValue()).isTrue(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DropwizardCounterServiceSpeedTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DropwizardCounterServiceSpeedTests.java index 95e54902532..f5c2ea73bb8 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DropwizardCounterServiceSpeedTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/buffer/DropwizardCounterServiceSpeedTests.java @@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReade import org.springframework.lang.UsesJava8; import org.springframework.util.StopWatch; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Speeds tests for {@link DropwizardMetricServices DropwizardMetricServices'} @@ -127,7 +127,7 @@ public class DropwizardCounterServiceSpeedTests { }); watch.stop(); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); - assertEquals(number * threadCount, total.longValue()); + assertThat(total.longValue()).isEqualTo(number * threadCount); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServicesTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServicesTests.java index 530ad694121..a82773f9ed1 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServicesTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServicesTests.java @@ -23,8 +23,7 @@ import com.codahale.metrics.Gauge; import com.codahale.metrics.MetricRegistry; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link DropwizardMetricServices}. @@ -42,7 +41,7 @@ public class DropwizardMetricServicesTests { this.writer.increment("foo"); this.writer.increment("foo"); this.writer.increment("foo"); - assertEquals(3, this.registry.counter("counter.foo").getCount()); + assertThat(this.registry.counter("counter.foo").getCount()).isEqualTo(3); } @Test @@ -50,7 +49,7 @@ public class DropwizardMetricServicesTests { this.writer.increment("meter.foo"); this.writer.increment("meter.foo"); this.writer.increment("meter.foo"); - assertEquals(3, this.registry.meter("meter.foo").getCount()); + assertThat(this.registry.meter("meter.foo").getCount()).isEqualTo(3); } @Test @@ -58,7 +57,7 @@ public class DropwizardMetricServicesTests { this.writer.increment("counter.foo"); this.writer.increment("counter.foo"); this.writer.increment("counter.foo"); - assertEquals(3, this.registry.counter("counter.foo").getCount()); + assertThat(this.registry.counter("counter.foo").getCount()).isEqualTo(3); } @Test @@ -66,23 +65,23 @@ public class DropwizardMetricServicesTests { this.writer.submit("foo", 2.1); @SuppressWarnings("unchecked") Gauge gauge = (Gauge) this.registry.getMetrics().get("gauge.foo"); - assertEquals(new Double(2.1), gauge.getValue()); + assertThat(gauge.getValue()).isEqualTo(new Double(2.1)); this.writer.submit("foo", 2.3); - assertEquals(new Double(2.3), gauge.getValue()); + assertThat(gauge.getValue()).isEqualTo(new Double(2.3)); } @Test public void setPredefinedTimer() { this.writer.submit("timer.foo", 200); this.writer.submit("timer.foo", 300); - assertEquals(2, this.registry.timer("timer.foo").getCount()); + assertThat(this.registry.timer("timer.foo").getCount()).isEqualTo(2); } @Test public void setPredefinedHistogram() { this.writer.submit("histogram.foo", 2.1); this.writer.submit("histogram.foo", 2.3); - assertEquals(2, this.registry.histogram("histogram.foo").getCount()); + assertThat(this.registry.histogram("histogram.foo").getCount()).isEqualTo(2); } /** @@ -108,7 +107,8 @@ public class DropwizardMetricServicesTests { } for (WriterThread thread : threads) { - assertFalse("expected thread caused unexpected exception", thread.isFailed()); + assertThat(thread.isFailed()) + .as("expected thread caused unexpected exception").isFalse(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporterTests.java index 1dc4d01b913..948f7f8743b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricCopyExporterTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit import org.springframework.boot.actuate.metrics.writer.Delta; import org.springframework.boot.actuate.metrics.writer.GaugeWriter; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MetricCopyExporter}. @@ -45,18 +45,18 @@ public class MetricCopyExporterTests { public void export() { this.reader.set(new Metric("foo", 2.3)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); } @Test public void counter() { this.reader.increment(new Delta("counter.foo", 2)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); this.reader.increment(new Delta("counter.foo", 3)); this.exporter.export(); this.exporter.flush(); - assertEquals(5L, this.writer.findOne("counter.foo").getValue()); + assertThat(this.writer.findOne("counter.foo").getValue()).isEqualTo(5L); } @Test @@ -68,7 +68,7 @@ public class MetricCopyExporterTests { this.reader.increment(new Delta("counter.foo", 3)); exporter.export(); exporter.flush(); - assertEquals(5L, writer.getValue().getValue()); + assertThat(writer.getValue().getValue()).isEqualTo(5L); } @Test @@ -76,7 +76,7 @@ public class MetricCopyExporterTests { this.exporter.setIncludes("*"); this.reader.set(new Metric("foo", 2.3)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); } @Test @@ -86,7 +86,7 @@ public class MetricCopyExporterTests { this.reader.set(new Metric("foo", 2.3)); this.reader.set(new Metric("bar", 2.4)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); } @Test @@ -95,7 +95,7 @@ public class MetricCopyExporterTests { this.reader.set(new Metric("foo", 2.3)); this.reader.set(new Metric("bar", 2.4)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); } @Test @@ -103,7 +103,7 @@ public class MetricCopyExporterTests { this.reader.set(new Metric("foo", 2.3)); this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000)); this.exporter.export(); - assertEquals(0, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(0); } @Test @@ -112,7 +112,7 @@ public class MetricCopyExporterTests { this.exporter.setIgnoreTimestamps(true); this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000)); this.exporter.export(); - assertEquals(1, this.writer.count()); + assertThat(this.writer.count()).isEqualTo(1); } private static class SimpleGaugeWriter implements GaugeWriter { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java index 311f706b85b..fa3198e1eb9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java @@ -28,8 +28,7 @@ import org.springframework.boot.actuate.metrics.writer.GaugeWriter; import org.springframework.boot.actuate.metrics.writer.MetricWriter; import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MetricExporters}. @@ -54,8 +53,8 @@ public class MetricExportersTests { this.exporters.setReader(this.reader); this.exporters.setWriters(this.writers); this.exporters.configureTasks(new ScheduledTaskRegistrar()); - assertNotNull(this.exporters.getExporters()); - assertEquals(0, this.exporters.getExporters().size()); + assertThat(this.exporters.getExporters()).isNotNull(); + assertThat(this.exporters.getExporters()).isEmpty(); } @Test @@ -66,8 +65,8 @@ public class MetricExportersTests { this.exporters.setReader(this.reader); this.exporters.setWriters(this.writers); this.exporters.configureTasks(new ScheduledTaskRegistrar()); - assertNotNull(this.exporters.getExporters()); - assertEquals(1, this.exporters.getExporters().size()); + assertThat(this.exporters.getExporters()).isNotNull(); + assertThat(this.exporters.getExporters()).hasSize(1); } @Test @@ -77,8 +76,8 @@ public class MetricExportersTests { this.exporters.setExporters(Collections.singletonMap("foo", new MetricCopyExporter(this.reader, this.writer))); this.exporters.configureTasks(new ScheduledTaskRegistrar()); - assertNotNull(this.exporters.getExporters()); - assertEquals(1, this.exporters.getExporters().size()); + assertThat(this.exporters.getExporters()).isNotNull(); + assertThat(this.exporters.getExporters()).hasSize(1); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java index d7ec8909893..04fd1987bfc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.actuate.metrics.Iterables; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link PrefixMetricGroupExporter}. @@ -47,7 +47,7 @@ public class PrefixMetricGroupExporterTests { this.reader.set(new Metric("foo.spam", 1.3)); this.exporter.setGroups(Collections.singleton("foo")); this.exporter.export(); - assertEquals(1, Iterables.collection(this.writer.groups()).size()); + assertThat(Iterables.collection(this.writer.groups())).hasSize(1); } @Test @@ -56,7 +56,7 @@ public class PrefixMetricGroupExporterTests { this.reader.set(new Metric("foo.spam", 1.3)); this.exporter.setGroups(Collections.singleton("bar")); this.exporter.export(); - assertEquals(0, Iterables.collection(this.writer.groups()).size()); + assertThat(Iterables.collection(this.writer.groups())).isEmpty(); } @Test @@ -64,8 +64,8 @@ public class PrefixMetricGroupExporterTests { this.reader.set("foo", Arrays.>asList(new Metric("bar", 2.3), new Metric("spam", 1.3))); this.exporter.export(); - assertEquals(1, this.writer.countGroups()); - assertEquals(2, Iterables.collection(this.writer.findAll("foo")).size()); + assertThat(this.writer.countGroups()).isEqualTo(1); + assertThat(Iterables.collection(this.writer.findAll("foo"))).hasSize(2); } @Test @@ -75,7 +75,7 @@ public class PrefixMetricGroupExporterTests { this.reader.set(new Metric("foobar.spam", 1.3)); this.exporter.setGroups(Collections.singleton("foo")); this.exporter.export(); - assertEquals(1, Iterables.collection(this.writer.groups()).size()); + assertThat(Iterables.collection(this.writer.groups())).hasSize(1); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporterTests.java index 122b71c050b..0d48071f93f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/RichGaugeExporterTests.java @@ -23,7 +23,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link RichGaugeExporter}. @@ -43,7 +43,7 @@ public class RichGaugeExporterTests { public void prefixedMetricsCopied() { this.reader.set(new Metric("foo", 2.3)); this.exporter.export(); - assertEquals(1, Iterables.collection(this.writer.groups()).size()); + assertThat(Iterables.collection(this.writer.groups())).hasSize(1); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java index 146c3587592..6b4dea5e08d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java @@ -32,7 +32,7 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SpringIntegrationMetricReader}. @@ -50,7 +50,7 @@ public class SpringIntegrationMetricReaderTests { @Test public void test() { - assertTrue(this.reader.count() > 0); + assertThat(this.reader.count() > 0).isTrue(); } @Configuration diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java index 20f0151627f..f5564fc2df5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jmx/DefaultMetricNamingStrategyTests.java @@ -20,7 +20,7 @@ import javax.management.ObjectName; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link DefaultMetricNamingStrategy}. @@ -35,37 +35,37 @@ public class DefaultMetricNamingStrategyTests { public void simpleName() throws Exception { ObjectName name = this.strategy.getObjectName(null, "domain:type=MetricValue,name=foo"); - assertEquals("domain", name.getDomain()); - assertEquals("foo", name.getKeyProperty("type")); + assertThat(name.getDomain()).isEqualTo("domain"); + assertThat(name.getKeyProperty("type")).isEqualTo("foo"); } @Test public void onePeriod() throws Exception { ObjectName name = this.strategy.getObjectName(null, "domain:type=MetricValue,name=foo.bar"); - assertEquals("domain", name.getDomain()); - assertEquals("foo", name.getKeyProperty("type")); - assertEquals("Wrong name: " + name, "bar", name.getKeyProperty("value")); + assertThat(name.getDomain()).isEqualTo("domain"); + assertThat(name.getKeyProperty("type")).isEqualTo("foo"); + assertThat(name.getKeyProperty("value")).isEqualTo("bar"); } @Test public void twoPeriods() throws Exception { ObjectName name = this.strategy.getObjectName(null, "domain:type=MetricValue,name=foo.bar.spam"); - assertEquals("domain", name.getDomain()); - assertEquals("foo", name.getKeyProperty("type")); - assertEquals("Wrong name: " + name, "bar", name.getKeyProperty("name")); - assertEquals("Wrong name: " + name, "spam", name.getKeyProperty("value")); + assertThat(name.getDomain()).isEqualTo("domain"); + assertThat(name.getKeyProperty("type")).isEqualTo("foo"); + assertThat(name.getKeyProperty("name")).isEqualTo("bar"); + assertThat(name.getKeyProperty("value")).isEqualTo("spam"); } @Test public void threePeriods() throws Exception { ObjectName name = this.strategy.getObjectName(null, "domain:type=MetricValue,name=foo.bar.spam.bucket"); - assertEquals("domain", name.getDomain()); - assertEquals("foo", name.getKeyProperty("type")); - assertEquals("Wrong name: " + name, "bar", name.getKeyProperty("name")); - assertEquals("Wrong name: " + name, "spam.bucket", name.getKeyProperty("value")); + assertThat(name.getDomain()).isEqualTo("domain"); + assertThat(name.getKeyProperty("type")).isEqualTo("foo"); + assertThat(name.getKeyProperty("name")).isEqualTo("bar"); + assertThat(name.getKeyProperty("value")).isEqualTo("spam.bucket"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/reader/MetricRegistryMetricReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/reader/MetricRegistryMetricReaderTests.java index 077549d98cf..4617dea14fe 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/reader/MetricRegistryMetricReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/reader/MetricRegistryMetricReaderTests.java @@ -25,10 +25,7 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MetricRegistryMetricReader}. @@ -52,9 +49,9 @@ public class MetricRegistryMetricReaderTests { } }); - assertThat(this.metricReader.findOne("test"), is(nullValue())); + assertThat(this.metricReader.findOne("test")).isNull(); this.metricRegistry.remove("test"); - assertThat(this.metricReader.findOne("test"), is(nullValue())); + assertThat(this.metricReader.findOne("test")).isNull(); } @Test @@ -69,9 +66,9 @@ public class MetricRegistryMetricReaderTests { }); Metric metric = (Metric) this.metricReader.findOne("test"); - assertThat(metric.getValue(), equalTo(Integer.valueOf(5))); + assertThat(metric.getValue()).isEqualTo(Integer.valueOf(5)); this.metricRegistry.remove("test"); - assertThat(this.metricReader.findOne("test"), is(nullValue())); + assertThat(this.metricReader.findOne("test")).isNull(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java index 4748f6ad35c..9f07ab81a82 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java @@ -23,7 +23,8 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.writer.Delta; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; /** * Tests for {@link InMemoryMetricRepository}. @@ -35,13 +36,15 @@ public class InMemoryMetricRepositoryTests { @Test public void increment() { this.repository.increment(new Delta("foo", 1, new Date())); - assertEquals(1.0, this.repository.findOne("foo").getValue().doubleValue(), 0.01); + assertThat(this.repository.findOne("foo").getValue().doubleValue()).isEqualTo(1.0, + offset(0.01)); } @Test public void set() { this.repository.set(new Metric("foo", 2.5, new Date())); - assertEquals(2.5, this.repository.findOne("foo").getValue().doubleValue(), 0.01); + assertThat(this.repository.findOne("foo").getValue().doubleValue()).isEqualTo(2.5, + offset(0.01)); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryPrefixMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryPrefixMetricRepositoryTests.java index 21e861cd454..29881f7c5cf 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryPrefixMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryPrefixMetricRepositoryTests.java @@ -24,8 +24,7 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.writer.Delta; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Dave Syer @@ -43,8 +42,8 @@ public class InMemoryPrefixMetricRepositoryTests { for (Metric metric : this.repository.findAll("foo")) { names.add(metric.getName()); } - assertEquals(2, names.size()); - assertTrue(names.contains("foo.bar")); + assertThat(names).hasSize(2); + assertThat(names.contains("foo.bar")).isTrue(); } @Test @@ -54,8 +53,8 @@ public class InMemoryPrefixMetricRepositoryTests { for (Metric metric : this.repository.findAll("foo.*")) { names.add(metric.getName()); } - assertEquals(1, names.size()); - assertTrue(names.contains("foo.bar")); + assertThat(names).hasSize(1); + assertThat(names.contains("foo.bar")).isTrue(); } @Test @@ -65,8 +64,8 @@ public class InMemoryPrefixMetricRepositoryTests { for (Metric metric : this.repository.findAll("foo.")) { names.add(metric.getName()); } - assertEquals(1, names.size()); - assertTrue(names.contains("foo.bar")); + assertThat(names).hasSize(1); + assertThat(names.contains("foo.bar")).isTrue(); } @Test @@ -77,8 +76,8 @@ public class InMemoryPrefixMetricRepositoryTests { for (Metric metric : this.repository.findAll("foo")) { names.add(metric.getName()); } - assertEquals(1, names.size()); - assertTrue(names.contains("foo.bar")); + assertThat(names).hasSize(1); + assertThat(names.contains("foo.bar")).isTrue(); } @Test @@ -90,9 +89,9 @@ public class InMemoryPrefixMetricRepositoryTests { for (Metric metric : this.repository.findAll("foo")) { names.add(metric.getName()); } - assertEquals(2, names.size()); - assertTrue(names.contains("foo.bar")); - assertEquals(3L, this.repository.findOne("foo.bar").getValue()); + assertThat(names).hasSize(2); + assertThat(names.contains("foo.bar")).isTrue(); + assertThat(this.repository.findOne("foo.bar").getValue()).isEqualTo(3L); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepositoryTests.java index 3a21cfe5256..0db12ce2d9b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepositoryTests.java @@ -27,9 +27,8 @@ import org.springframework.boot.actuate.metrics.writer.Delta; import org.springframework.boot.redis.RedisTestServer; import org.springframework.data.redis.core.StringRedisTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; /** * Tests for {@link RedisMetricRepository}. @@ -54,26 +53,26 @@ public class RedisMetricRepositoryTests { @After public void clear() { - assertNotNull(new StringRedisTemplate(this.redis.getConnectionFactory()) - .opsForValue().get(this.prefix + ".foo")); + assertThat(new StringRedisTemplate(this.redis.getConnectionFactory()) + .opsForValue().get(this.prefix + ".foo")).isNotNull(); this.repository.reset("foo"); this.repository.reset("bar"); - assertNull(new StringRedisTemplate(this.redis.getConnectionFactory()) - .opsForValue().get(this.prefix + ".foo")); + assertThat(new StringRedisTemplate(this.redis.getConnectionFactory()) + .opsForValue().get(this.prefix + ".foo")).isNull(); } @Test public void setAndGet() { this.repository.set(new Metric("foo", 12.3)); Metric metric = this.repository.findOne("foo"); - assertEquals("foo", metric.getName()); - assertEquals(12.3, metric.getValue().doubleValue(), 0.01); + assertThat(metric.getName()).isEqualTo("foo"); + assertThat(metric.getValue().doubleValue()).isEqualTo(12.3, offset(0.01)); } @Test public void incrementAndGet() { this.repository.increment(new Delta("foo", 3L)); - assertEquals(3, this.repository.findOne("foo").getValue().longValue()); + assertThat(this.repository.findOne("foo").getValue().longValue()).isEqualTo(3); } @Test @@ -81,29 +80,29 @@ public class RedisMetricRepositoryTests { this.repository.set(new Metric("foo", 12.3)); this.repository.increment(new Delta("foo", 3L)); Metric metric = this.repository.findOne("foo"); - assertEquals("foo", metric.getName()); - assertEquals(15.3, metric.getValue().doubleValue(), 0.01); + assertThat(metric.getName()).isEqualTo("foo"); + assertThat(metric.getValue().doubleValue()).isEqualTo(15.3, offset(0.01)); } @Test public void findAll() { this.repository.increment(new Delta("foo", 3L)); this.repository.set(new Metric("bar", 12.3)); - assertEquals(2, Iterables.collection(this.repository.findAll()).size()); + assertThat(Iterables.collection(this.repository.findAll())).hasSize(2); } @Test public void findOneWithAll() { this.repository.increment(new Delta("foo", 3L)); Metric metric = this.repository.findAll().iterator().next(); - assertEquals("foo", metric.getName()); + assertThat(metric.getName()).isEqualTo("foo"); } @Test public void count() { this.repository.increment(new Delta("foo", 3L)); this.repository.set(new Metric("bar", 12.3)); - assertEquals(2, this.repository.count()); + assertThat(this.repository.count()).isEqualTo(2); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java index 5a93a8275a8..a5d156accc9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMultiMetricRepositoryTests.java @@ -37,9 +37,7 @@ import org.springframework.boot.actuate.metrics.writer.Delta; import org.springframework.boot.redis.RedisTestServer; import org.springframework.data.redis.core.StringRedisTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link RedisMultiMetricRepository}. @@ -77,14 +75,14 @@ public class RedisMultiMetricRepositoryTests { @After public void clear() { - assertTrue(new StringRedisTemplate(this.redis.getConnectionFactory()).opsForZSet() - .size("keys." + this.prefix) > 0); + assertThat(new StringRedisTemplate(this.redis.getConnectionFactory()).opsForZSet() + .size("keys." + this.prefix)).isGreaterThan(0); this.repository.reset("foo"); this.repository.reset("bar"); - assertNull(new StringRedisTemplate(this.redis.getConnectionFactory()) - .opsForValue().get(this.prefix + ".foo")); - assertNull(new StringRedisTemplate(this.redis.getConnectionFactory()) - .opsForValue().get(this.prefix + ".bar")); + assertThat(new StringRedisTemplate(this.redis.getConnectionFactory()) + .opsForValue().get(this.prefix + ".foo")).isNull(); + assertThat(new StringRedisTemplate(this.redis.getConnectionFactory()) + .opsForValue().get(this.prefix + ".bar")).isNull(); } @Test @@ -93,8 +91,8 @@ public class RedisMultiMetricRepositoryTests { Arrays.>asList(new Metric("foo.bar", 12.3))); this.repository.set("foo", Arrays.>asList(new Metric("foo.bar", 15.3))); - assertEquals(15.3, Iterables.collection(this.repository.findAll("foo")).iterator() - .next().getValue()); + assertThat(Iterables.collection(this.repository.findAll("foo")).iterator().next() + .getValue()).isEqualTo(15.3); } @Test @@ -102,7 +100,7 @@ public class RedisMultiMetricRepositoryTests { this.repository.set("foo", Arrays.>asList(new Metric("foo.val", 12.3), new Metric("foo.bar", 11.3))); - assertEquals(2, Iterables.collection(this.repository.findAll("foo")).size()); + assertThat(Iterables.collection(this.repository.findAll("foo"))).hasSize(2); } @Test @@ -114,8 +112,7 @@ public class RedisMultiMetricRepositoryTests { Arrays.>asList(new Metric("bar.val", 12.3), new Metric("bar.foo", 11.3))); Collection groups = Iterables.collection(this.repository.groups()); - assertEquals(2, groups.size()); - assertTrue("Wrong groups: " + groups, groups.contains("foo")); + assertThat(groups).hasSize(2).contains("foo"); } @Test @@ -126,7 +123,7 @@ public class RedisMultiMetricRepositoryTests { this.repository.set("bar", Arrays.>asList(new Metric("bar.val", 12.3), new Metric("bar.foo", 11.3))); - assertEquals(2, this.repository.countGroups()); + assertThat(this.repository.countGroups()).isEqualTo(2); } @Test @@ -142,9 +139,8 @@ public class RedisMultiMetricRepositoryTests { bar = metric; } } - assertEquals(2, names.size()); - assertTrue("Wrong names: " + names, names.contains("foo.bar")); - assertEquals(3d, bar.getValue()); + assertThat(names).hasSize(2).contains("foo.bar"); + assertThat(bar.getValue()).isEqualTo(3d); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java index 32171323beb..a3f93837d5b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepositoryTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; /** * @author Dave Syer @@ -33,8 +34,8 @@ public class InMemoryRichGaugeRepositoryTests { public void writeAndRead() { this.repository.set(new Metric("foo", 1d)); this.repository.set(new Metric("foo", 2d)); - assertEquals(2L, this.repository.findOne("foo").getCount()); - assertEquals(2d, this.repository.findOne("foo").getValue(), 0.01); + assertThat(this.repository.findOne("foo").getCount()).isEqualTo(2L); + assertThat(this.repository.findOne("foo").getValue()).isEqualTo(2d, offset(0.01)); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java index 24f99285517..d27af496f54 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/rich/MultiMetricRichGaugeReaderTests.java @@ -22,8 +22,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.export.RichGaugeExporter; import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link MultiMetricRichGaugeReader}. @@ -45,11 +44,11 @@ public class MultiMetricRichGaugeReaderTests { this.data.set(new Metric("foo", 1)); this.exporter.export(); // Check the exporter worked - assertEquals(6, this.repository.count()); - assertEquals(1, this.reader.count()); + assertThat(this.repository.count()).isEqualTo(6); + assertThat(this.reader.count()).isEqualTo(1); RichGauge one = this.reader.findOne("foo"); - assertNotNull(one); - assertEquals(2, one.getCount()); + assertThat(one).isNotNull(); + assertThat(one.getCount()).isEqualTo(2); } @Test @@ -57,10 +56,10 @@ public class MultiMetricRichGaugeReaderTests { this.data.set(new Metric("foo", 1)); this.data.set(new Metric("bar", 1)); this.exporter.export(); - assertEquals(2, this.reader.count()); + assertThat(this.reader.count()).isEqualTo(2); RichGauge one = this.reader.findOne("foo"); - assertNotNull(one); - assertEquals(1, one.getCount()); + assertThat(one).isNotNull(); + assertThat(one.getCount()).isEqualTo(1); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java index 12362919cb9..60e74b4f029 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java @@ -30,7 +30,7 @@ import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.writer.Delta; import org.springframework.util.SocketUtils; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link StatsdMetricWriter}. @@ -56,14 +56,14 @@ public class StatsdMetricWriterTests { public void increment() { this.writer.increment(new Delta("counter.foo", 3L)); this.server.waitForMessage(); - assertEquals("me.counter.foo:3|c", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.counter.foo:3|c"); } @Test public void setLongMetric() throws Exception { this.writer.set(new Metric("gauge.foo", 3L)); this.server.waitForMessage(); - assertEquals("me.gauge.foo:3|g", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.gauge.foo:3|g"); } @Test @@ -71,14 +71,14 @@ public class StatsdMetricWriterTests { this.writer.set(new Metric("gauge.foo", 3.7)); this.server.waitForMessage(); // Doubles are truncated - assertEquals("me.gauge.foo:3.7|g", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.gauge.foo:3.7|g"); } @Test public void setTimerMetric() throws Exception { this.writer.set(new Metric("timer.foo", 37L)); this.server.waitForMessage(); - assertEquals("me.timer.foo:37|ms", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.timer.foo:37|ms"); } @Test @@ -86,7 +86,7 @@ public class StatsdMetricWriterTests { this.writer = new StatsdMetricWriter("localhost", this.port); this.writer.set(new Metric("gauge.foo", 3L)); this.server.waitForMessage(); - assertEquals("gauge.foo:3|g", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("gauge.foo:3|g"); } @Test @@ -94,10 +94,10 @@ public class StatsdMetricWriterTests { this.writer = new StatsdMetricWriter("my.", "localhost", this.port); this.writer.set(new Metric("gauge.foo", 3L)); this.server.waitForMessage(); - assertEquals("my.gauge.foo:3|g", this.server.messagesReceived().get(0)); + assertThat(this.server.messagesReceived().get(0)).isEqualTo("my.gauge.foo:3|g"); } - private static final class DummyStatsDServer { + private static final class DummyStatsDServer implements Runnable { private final List messagesReceived = new ArrayList(); @@ -107,31 +107,29 @@ public class StatsdMetricWriterTests { try { this.server = new DatagramSocket(port); } - catch (SocketException e) { - throw new IllegalStateException(e); + catch (SocketException ex) { + throw new IllegalStateException(ex); } - new Thread(new Runnable() { - @Override - public void run() { - try { - final DatagramPacket packet = new DatagramPacket(new byte[256], - 256); - DummyStatsDServer.this.server.receive(packet); - DummyStatsDServer.this.messagesReceived.add( - new String(packet.getData(), Charset.forName("UTF-8")) - .trim()); - } - catch (Exception e) { - // Ignore - } - } - }).start(); + new Thread(this).start(); } public void stop() { this.server.close(); } + @Override + public void run() { + try { + DatagramPacket packet = new DatagramPacket(new byte[256], 256); + this.server.receive(packet); + this.messagesReceived.add( + new String(packet.getData(), Charset.forName("UTF-8")).trim()); + } + catch (Exception ex) { + // Ignore + } + } + public void waitForMessage() { while (this.messagesReceived.isEmpty()) { try { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/InMemoryRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepositoryTests.java old mode 100644 new mode 100755 similarity index 62% rename from spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/InMemoryRepositoryTests.java rename to spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepositoryTests.java index c5513560449..70c5c291e80 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/InMemoryRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepositoryTests.java @@ -29,21 +29,21 @@ import org.junit.Test; import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository.Callback; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** + * Tests for {@link SimpleInMemoryRepository}. + * * @author Dave Syer */ -public class InMemoryRepositoryTests { +public class SimpleInMemoryRepositoryTests { private final SimpleInMemoryRepository repository = new SimpleInMemoryRepository(); @Test public void setAndGet() { this.repository.set("foo", "bar"); - assertEquals("bar", this.repository.findOne("foo")); + assertThat(this.repository.findOne("foo")).isEqualTo("bar"); } @Test @@ -55,7 +55,7 @@ public class InMemoryRepositoryTests { return "bar"; } }); - assertEquals("bar", this.repository.findOne("foo")); + assertThat(this.repository.findOne("foo")).isEqualTo("bar"); } @Test @@ -66,7 +66,7 @@ public class InMemoryRepositoryTests { return "bar"; } }); - assertEquals("bar", this.repository.findOne("foo")); + assertThat(this.repository.findOne("foo")).isEqualTo("bar"); } @Test @@ -75,59 +75,59 @@ public class InMemoryRepositoryTests { this.repository.set("foo.bar", "one"); this.repository.set("foo.min", "two"); this.repository.set("foo.max", "three"); - assertEquals(3, - ((Collection) this.repository.findAllWithPrefix("foo")).size()); + assertThat(((Collection) this.repository.findAllWithPrefix("foo"))).hasSize(3); } @Test public void patternsAcceptedForRegisteredPrefix() { this.repository.set("foo.bar", "spam"); Iterator iterator = this.repository.findAllWithPrefix("foo.*").iterator(); - assertEquals("spam", iterator.next()); - assertFalse(iterator.hasNext()); + assertThat(iterator.next()).isEqualTo("spam"); + assertThat(iterator.hasNext()).isFalse(); } @Test public void updateConcurrent() throws Exception { - final SimpleInMemoryRepository repository = new SimpleInMemoryRepository(); + SimpleInMemoryRepository repository = new SimpleInMemoryRepository(); Collection> tasks = new ArrayList>(); for (int i = 0; i < 1000; i++) { - tasks.add(new Callable() { - @Override - public Boolean call() throws Exception { - repository.update("foo", new Callback() { - @Override - public Integer modify(Integer current) { - if (current == null) { - return 1; - } - return current + 1; - } - }); - return true; - } - }); - tasks.add(new Callable() { - @Override - public Boolean call() throws Exception { - repository.update("foo", new Callback() { - @Override - public Integer modify(Integer current) { - if (current == null) { - return -1; - } - return current - 1; - } - }); - return true; - } - }); + tasks.add(new RepositoryUpdate(repository, 1)); + tasks.add(new RepositoryUpdate(repository, -1)); } List> all = Executors.newFixedThreadPool(10).invokeAll(tasks); for (Future future : all) { - assertTrue(future.get(1, TimeUnit.SECONDS)); + assertThat(future.get(1, TimeUnit.SECONDS)).isTrue(); } - assertEquals(Integer.valueOf(0), repository.findOne("foo")); + assertThat(repository.findOne("foo")).isEqualTo(0); + } + + private static class RepositoryUpdate implements Callable { + + private final SimpleInMemoryRepository repository; + + private final int delta; + + RepositoryUpdate(SimpleInMemoryRepository repository, int delta) { + this.repository = repository; + this.delta = delta; + } + + @Override + public Boolean call() throws Exception { + this.repository.update("foo", new Callback() { + + @Override + public Integer modify(Integer current) { + if (current == null) { + return RepositoryUpdate.this.delta; + } + return current + RepositoryUpdate.this.delta; + } + + }); + return true; + } + } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java index b41f910d29b..fdf4964d23f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java @@ -22,12 +22,14 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.runners.MockitoJUnitRunner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** * Tests for {@link DefaultCounterService}. + * + * @author Dave Syer */ @RunWith(MockitoJUnitRunner.class) public class DefaultCounterServiceTests { @@ -44,32 +46,32 @@ public class DefaultCounterServiceTests { public void incrementWithExistingCounter() { this.service.increment("counter.foo"); verify(this.repository).increment(this.captor.capture()); - assertEquals("counter.foo", this.captor.getValue().getName()); - assertEquals(1L, this.captor.getValue().getValue()); + assertThat(this.captor.getValue().getName()).isEqualTo("counter.foo"); + assertThat(this.captor.getValue().getValue()).isEqualTo(1L); } @Test public void incrementWithExistingNearCounter() { this.service.increment("counter-foo"); verify(this.repository).increment(this.captor.capture()); - assertEquals("counter.counter-foo", this.captor.getValue().getName()); - assertEquals(1L, this.captor.getValue().getValue()); + assertThat(this.captor.getValue().getName()).isEqualTo("counter.counter-foo"); + assertThat(this.captor.getValue().getValue()).isEqualTo(1L); } @Test public void incrementPrependsCounter() { this.service.increment("foo"); verify(this.repository).increment(this.captor.capture()); - assertEquals("counter.foo", this.captor.getValue().getName()); - assertEquals(1L, this.captor.getValue().getValue()); + assertThat(this.captor.getValue().getName()).isEqualTo("counter.foo"); + assertThat(this.captor.getValue().getValue()).isEqualTo(1L); } @Test public void decrementPrependsCounter() { this.service.decrement("foo"); verify(this.repository).increment(this.captor.capture()); - assertEquals("counter.foo", this.captor.getValue().getName()); - assertEquals(-1L, this.captor.getValue().getValue()); + assertThat(this.captor.getValue().getName()).isEqualTo("counter.foo"); + assertThat(this.captor.getValue().getValue()).isEqualTo(-1L); } @Test @@ -77,4 +79,5 @@ public class DefaultCounterServiceTests { this.service.reset("foo"); verify(this.repository).reset("counter.foo"); } + } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeServiceTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeServiceTests.java index 0e6d150633a..56b90d5bc1d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeServiceTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultGaugeServiceTests.java @@ -21,12 +21,14 @@ import org.mockito.ArgumentCaptor; import org.springframework.boot.actuate.metrics.Metric; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** * Tests for {@link DefaultGaugeService}. + * + * @author Dave Syer */ public class DefaultGaugeServiceTests { @@ -40,8 +42,8 @@ public class DefaultGaugeServiceTests { @SuppressWarnings("rawtypes") ArgumentCaptor captor = ArgumentCaptor.forClass(Metric.class); verify(this.repository).set(captor.capture()); - assertEquals("gauge.foo", captor.getValue().getName()); - assertEquals(2.3, captor.getValue().getValue()); + assertThat(captor.getValue().getName()).isEqualTo("gauge.foo"); + assertThat(captor.getValue().getValue()).isEqualTo(2.3); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java index c13cd3550e5..4c77b85ce4a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java @@ -32,8 +32,7 @@ import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.User; import org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent; -import static org.hamcrest.Matchers.hasEntry; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -97,8 +96,8 @@ public class AuthenticationAuditListenerTests { ArgumentCaptor auditApplicationEvent = ArgumentCaptor .forClass(AuditApplicationEvent.class); verify(this.publisher).publishEvent(auditApplicationEvent.capture()); - assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(), - hasEntry("details", details)); + assertThat(auditApplicationEvent.getValue().getAuditEvent().getData()) + .containsEntry("details", details); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java index 496c9122a06..75f10e896c7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/ApplicationPidFileWriterTests.java @@ -37,9 +37,7 @@ import org.springframework.core.env.StandardEnvironment; import org.springframework.mock.env.MockPropertySource; import org.springframework.util.FileCopyUtils; -import static org.hamcrest.Matchers.isEmptyString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -76,8 +74,8 @@ public class ApplicationPidFileWriterTests { File file = this.temporaryFolder.newFile(); ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file); listener.onApplicationEvent(EVENT); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), - not(isEmptyString())); + FileReader reader = new FileReader(file); + assertThat(FileCopyUtils.copyToString(reader)).isNotEmpty(); } @Test @@ -86,9 +84,8 @@ public class ApplicationPidFileWriterTests { System.setProperty("PIDFILE", this.temporaryFolder.newFile().getAbsolutePath()); ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file); listener.onApplicationEvent(EVENT); - assertThat( - FileCopyUtils.copyToString(new FileReader(System.getProperty("PIDFILE"))), - not(isEmptyString())); + FileReader reader = new FileReader(System.getProperty("PIDFILE")); + assertThat(FileCopyUtils.copyToString(reader)).isNotEmpty(); } @Test @@ -98,8 +95,7 @@ public class ApplicationPidFileWriterTests { file.getAbsolutePath()); ApplicationPidFileWriter listener = new ApplicationPidFileWriter(); listener.onApplicationEvent(event); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), - not(isEmptyString())); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty(); } @Test @@ -109,11 +105,10 @@ public class ApplicationPidFileWriterTests { file.getAbsolutePath()); ApplicationPidFileWriter listener = new ApplicationPidFileWriter(); listener.onApplicationEvent(event); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), isEmptyString()); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty(); listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class); listener.onApplicationEvent(event); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), - not(isEmptyString())); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty(); } @Test @@ -123,8 +118,7 @@ public class ApplicationPidFileWriterTests { listener.setTriggerEventType(ApplicationStartedEvent.class); listener.onApplicationEvent( new ApplicationStartedEvent(new SpringApplication(), new String[] {})); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), - not(isEmptyString())); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty(); } @Test @@ -133,7 +127,7 @@ public class ApplicationPidFileWriterTests { file.setReadOnly(); ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file); listener.onApplicationEvent(EVENT); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), isEmptyString()); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty(); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java index 5d5d540b0d1..3c6ae972a98 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/EmbeddedServerPortFileWriterTests.java @@ -33,9 +33,7 @@ import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -62,7 +60,7 @@ public class EmbeddedServerPortFileWriterTests { File file = this.temporaryFolder.newFile(); EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file); listener.onApplicationEvent(mockEvent("", 8080)); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), equalTo("8080")); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEqualTo("8080"); } @Test @@ -70,8 +68,8 @@ public class EmbeddedServerPortFileWriterTests { System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath()); EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(); listener.onApplicationEvent(mockEvent("", 8080)); - assertThat(FileCopyUtils.copyToString( - new FileReader(System.getProperty("PORTFILE"))), equalTo("8080")); + FileReader reader = new FileReader(System.getProperty("PORTFILE")); + assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080"); } @Test @@ -80,8 +78,8 @@ public class EmbeddedServerPortFileWriterTests { System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath()); EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file); listener.onApplicationEvent(mockEvent("", 8080)); - assertThat(FileCopyUtils.copyToString( - new FileReader(System.getProperty("PORTFILE"))), equalTo("8080")); + FileReader reader = new FileReader(System.getProperty("PORTFILE")); + assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080"); } @Test @@ -90,17 +88,16 @@ public class EmbeddedServerPortFileWriterTests { EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file); listener.onApplicationEvent(mockEvent("", 8080)); listener.onApplicationEvent(mockEvent("management", 9090)); - assertThat(FileCopyUtils.copyToString(new FileReader(file)), equalTo("8080")); + assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEqualTo("8080"); String managementFile = file.getName(); managementFile = managementFile.substring(0, managementFile.length() - StringUtils.getFilenameExtension(managementFile).length() - 1); managementFile = managementFile + "-management." + StringUtils.getFilenameExtension(file.getName()); - assertThat( - FileCopyUtils.copyToString( - new FileReader(new File(file.getParentFile(), managementFile))), - equalTo("9090")); - assertThat(collectFileNames(file.getParentFile()), hasItem(managementFile)); + FileReader reader = new FileReader( + new File(file.getParentFile(), managementFile)); + assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("9090"); + assertThat(collectFileNames(file.getParentFile())).contains(managementFile); } @Test @@ -114,11 +111,10 @@ public class EmbeddedServerPortFileWriterTests { - StringUtils.getFilenameExtension(managementFile).length() - 1); managementFile = managementFile + "-MANAGEMENT." + StringUtils.getFilenameExtension(file.getName()); - assertThat( - FileCopyUtils.copyToString( - new FileReader(new File(file.getParentFile(), managementFile))), - equalTo("9090")); - assertThat(collectFileNames(file.getParentFile()), hasItem(managementFile)); + FileReader reader = new FileReader( + new File(file.getParentFile(), managementFile)); + assertThat(FileCopyUtils.copyToString(reader)).isEqualTo("9090"); + assertThat(collectFileNames(file.getParentFile())).contains(managementFile); } private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/InMemoryTraceRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/InMemoryTraceRepositoryTests.java index 091fe9376e1..0d2f8f5ab71 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/InMemoryTraceRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/InMemoryTraceRepositoryTests.java @@ -21,7 +21,7 @@ import java.util.List; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link InMemoryTraceRepository}. @@ -39,9 +39,9 @@ public class InMemoryTraceRepositoryTests { this.repository.add(Collections.singletonMap("bar", "foo")); this.repository.add(Collections.singletonMap("bar", "bar")); List traces = this.repository.findAll(); - assertEquals(2, traces.size()); - assertEquals("bar", traces.get(0).getInfo().get("bar")); - assertEquals("foo", traces.get(1).getInfo().get("bar")); + assertThat(traces).hasSize(2); + assertThat(traces.get(0).getInfo().get("bar")).isEqualTo("bar"); + assertThat(traces.get(1).getInfo().get("bar")).isEqualTo("foo"); } @Test @@ -52,9 +52,9 @@ public class InMemoryTraceRepositoryTests { this.repository.add(Collections.singletonMap("bar", "foo")); this.repository.add(Collections.singletonMap("bar", "bar")); List traces = this.repository.findAll(); - assertEquals(2, traces.size()); - assertEquals("bar", traces.get(1).getInfo().get("bar")); - assertEquals("foo", traces.get(0).getInfo().get("bar")); + assertThat(traces).hasSize(2); + assertThat(traces.get(1).getInfo().get("bar")).isEqualTo("bar"); + assertThat(traces.get(0).getInfo().get("bar")).isEqualTo("foo"); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java index c122f50c255..8a7c6b67649 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/WebRequestTraceFilterTests.java @@ -37,8 +37,7 @@ import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link WebRequestTraceFilter}. @@ -62,10 +61,10 @@ public class WebRequestTraceFilterTests { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); request.addHeader("Accept", "application/json"); Map trace = this.filter.getTrace(request); - assertEquals("GET", trace.get("method")); - assertEquals("/foo", trace.get("path")); + assertThat(trace.get("method")).isEqualTo("GET"); + assertThat(trace.get("path")).isEqualTo("/foo"); Map map = (Map) trace.get("headers"); - assertEquals("{Accept=application/json}", map.get("request").toString()); + assertThat(map.get("request").toString()).isEqualTo("{Accept=application/json}"); } @Test @@ -110,22 +109,23 @@ public class WebRequestTraceFilterTests { } }); - assertEquals(1, this.repository.findAll().size()); + assertThat(this.repository.findAll()).hasSize(1); Map trace = this.repository.findAll().iterator().next().getInfo(); Map map = (Map) trace.get("headers"); - assertEquals("{Content-Type=application/json, status=200}", - map.get("response").toString()); - assertEquals("GET", trace.get("method")); - assertEquals("/foo", trace.get("path")); - assertEquals("paramvalue", - ((String[]) ((Map) trace.get("parameters")).get("param"))[0]); - assertEquals("some.remote.addr", trace.get("remoteAddress")); - assertEquals("some.query.string", trace.get("query")); - assertEquals(principal.getName(), trace.get("userPrincipal")); - assertEquals("some.context.path", trace.get("contextPath")); - assertEquals(url, trace.get("pathInfo")); - assertEquals("authType", trace.get("authType")); - assertEquals("{Accept=application/json}", map.get("request").toString()); + + assertThat(map.get("response").toString()) + .isEqualTo("{Content-Type=application/json, status=200}"); + assertThat(trace.get("method")).isEqualTo("GET"); + assertThat(trace.get("path")).isEqualTo("/foo"); + assertThat(((String[]) ((Map) trace.get("parameters")).get("param"))[0]) + .isEqualTo("paramvalue"); + assertThat(trace.get("remoteAddress")).isEqualTo("some.remote.addr"); + assertThat(trace.get("query")).isEqualTo("some.query.string"); + assertThat(trace.get("userPrincipal")).isEqualTo(principal.getName()); + assertThat(trace.get("contextPath")).isEqualTo("some.context.path"); + assertThat(trace.get("pathInfo")).isEqualTo(url); + assertThat(trace.get("authType")).isEqualTo("authType"); + assertThat(map.get("request").toString()).isEqualTo("{Accept=application/json}"); } @Test @@ -144,7 +144,7 @@ public class WebRequestTraceFilterTests { }); Map info = this.repository.findAll().iterator().next().getInfo(); Map headers = (Map) info.get("headers"); - assertTrue(headers.get("response") == null); + assertThat(headers.get("response") == null).isTrue(); } @Test @@ -158,7 +158,7 @@ public class WebRequestTraceFilterTests { @SuppressWarnings("unchecked") Map map = (Map) ((Map) trace .get("headers")).get("response"); - assertEquals("404", map.get("status").toString()); + assertThat(map.get("status").toString()).isEqualTo("404"); } @Test @@ -175,7 +175,7 @@ public class WebRequestTraceFilterTests { @SuppressWarnings("unchecked") Map map = (Map) trace.get("error"); System.err.println(map); - assertEquals("Foo", map.get("message").toString()); + assertThat(map.get("message").toString()).isEqualTo("Foo"); } }