Commit 94677b35 authored by Phillip Webb's avatar Phillip Webb

Use AssertJ in spring-boot-actuator

See gh-5083
parent a5ae81c1
...@@ -20,8 +20,7 @@ import java.util.Collections; ...@@ -20,8 +20,7 @@ import java.util.Collections;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link AuditEvent}. * Tests for {@link AuditEvent}.
...@@ -34,17 +33,17 @@ public class AuditEventTests { ...@@ -34,17 +33,17 @@ public class AuditEventTests {
public void testNowEvent() throws Exception { public void testNowEvent() throws Exception {
AuditEvent event = new AuditEvent("phil", "UNKNOWN", AuditEvent event = new AuditEvent("phil", "UNKNOWN",
Collections.singletonMap("a", (Object) "b")); Collections.singletonMap("a", (Object) "b"));
assertEquals("b", event.getData().get("a")); assertThat(event.getData().get("a")).isEqualTo("b");
assertEquals("UNKNOWN", event.getType()); assertThat(event.getType()).isEqualTo("UNKNOWN");
assertEquals("phil", event.getPrincipal()); assertThat(event.getPrincipal()).isEqualTo("phil");
assertNotNull(event.getTimestamp()); assertThat(event.getTimestamp()).isNotNull();
} }
@Test @Test
public void testConvertStringsToData() throws Exception { public void testConvertStringsToData() throws Exception {
AuditEvent event = new AuditEvent("phil", "UNKNOWN", "a=b", "c=d"); AuditEvent event = new AuditEvent("phil", "UNKNOWN", "a=b", "c=d");
assertEquals("b", event.getData().get("a")); assertThat(event.getData().get("a")).isEqualTo("b");
assertEquals("d", event.getData().get("c")); assertThat(event.getData().get("c")).isEqualTo("d");
} }
} }
...@@ -24,8 +24,7 @@ import java.util.Map; ...@@ -24,8 +24,7 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link InMemoryAuditEventRepository}. * Tests for {@link InMemoryAuditEventRepository}.
...@@ -41,9 +40,9 @@ public class InMemoryAuditEventRepositoryTests { ...@@ -41,9 +40,9 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "a")); repository.add(new AuditEvent("dave", "a"));
repository.add(new AuditEvent("dave", "b")); repository.add(new AuditEvent("dave", "b"));
List<AuditEvent> events = repository.find("dave", null); List<AuditEvent> events = repository.find("dave", null);
assertThat(events.size(), equalTo(2)); assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType(), equalTo("a")); assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType(), equalTo("b")); assertThat(events.get(1).getType()).isEqualTo("b");
} }
...@@ -54,9 +53,9 @@ public class InMemoryAuditEventRepositoryTests { ...@@ -54,9 +53,9 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "b")); repository.add(new AuditEvent("dave", "b"));
repository.add(new AuditEvent("dave", "c")); repository.add(new AuditEvent("dave", "c"));
List<AuditEvent> events = repository.find("dave", null); List<AuditEvent> events = repository.find("dave", null);
assertThat(events.size(), equalTo(2)); assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType(), equalTo("b")); assertThat(events.get(0).getType()).isEqualTo("b");
assertThat(events.get(1).getType(), equalTo("c")); assertThat(events.get(1).getType()).isEqualTo("c");
} }
@Test @Test
...@@ -67,9 +66,9 @@ public class InMemoryAuditEventRepositoryTests { ...@@ -67,9 +66,9 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "c")); repository.add(new AuditEvent("dave", "c"));
repository.add(new AuditEvent("phil", "d")); repository.add(new AuditEvent("phil", "d"));
List<AuditEvent> events = repository.find("dave", null); List<AuditEvent> events = repository.find("dave", null);
assertThat(events.size(), equalTo(2)); assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType(), equalTo("a")); assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType(), equalTo("c")); assertThat(events.get(1).getType()).isEqualTo("c");
} }
@Test @Test
...@@ -89,12 +88,12 @@ public class InMemoryAuditEventRepositoryTests { ...@@ -89,12 +88,12 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data)); repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data));
calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.add(Calendar.DAY_OF_YEAR, 1);
List<AuditEvent> events = repository.find(null, after); List<AuditEvent> events = repository.find(null, after);
assertThat(events.size(), equalTo(2)); assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType(), equalTo("c")); assertThat(events.get(0).getType()).isEqualTo("c");
assertThat(events.get(1).getType(), equalTo("d")); assertThat(events.get(1).getType()).isEqualTo("d");
events = repository.find("dave", after); events = repository.find("dave", after);
assertThat(events.size(), equalTo(1)); assertThat(events.size()).isEqualTo(1);
assertThat(events.get(0).getType(), equalTo("c")); assertThat(events.get(0).getType()).isEqualTo("c");
} }
} }
...@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.event.AbstractAuthorizationEvent; import org.springframework.security.access.event.AbstractAuthorizationEvent;
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; import org.springframework.security.authentication.event.AbstractAuthenticationEvent;
import static org.hamcrest.Matchers.instanceOf; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link AuditAutoConfiguration}. * Tests for {@link AuditAutoConfiguration}.
...@@ -48,33 +46,33 @@ public class AuditAutoConfigurationTests { ...@@ -48,33 +46,33 @@ public class AuditAutoConfigurationTests {
@Test @Test
public void testTraceConfiguration() throws Exception { public void testTraceConfiguration() throws Exception {
registerAndRefresh(AuditAutoConfiguration.class); registerAndRefresh(AuditAutoConfiguration.class);
assertNotNull(this.context.getBean(AuditEventRepository.class)); assertThat(this.context.getBean(AuditEventRepository.class)).isNotNull();
assertNotNull(this.context.getBean(AuthenticationAuditListener.class)); assertThat(this.context.getBean(AuthenticationAuditListener.class)).isNotNull();
assertNotNull(this.context.getBean(AuthorizationAuditListener.class)); assertThat(this.context.getBean(AuthorizationAuditListener.class)).isNotNull();
} }
@Test @Test
public void ownAutoRepository() throws Exception { public void ownAutoRepository() throws Exception {
registerAndRefresh(CustomAuditEventRepositoryConfiguration.class, registerAndRefresh(CustomAuditEventRepositoryConfiguration.class,
AuditAutoConfiguration.class); AuditAutoConfiguration.class);
assertThat(this.context.getBean(AuditEventRepository.class), assertThat(this.context.getBean(AuditEventRepository.class))
instanceOf(TestAuditEventRepository.class)); .isInstanceOf(TestAuditEventRepository.class);
} }
@Test @Test
public void ownAuthenticationAuditListener() throws Exception { public void ownAuthenticationAuditListener() throws Exception {
registerAndRefresh(CustomAuthenticationAuditListenerConfiguration.class, registerAndRefresh(CustomAuthenticationAuditListenerConfiguration.class,
AuditAutoConfiguration.class); AuditAutoConfiguration.class);
assertThat(this.context.getBean(AbstractAuthenticationAuditListener.class), assertThat(this.context.getBean(AbstractAuthenticationAuditListener.class))
instanceOf(TestAuthenticationAuditListener.class)); .isInstanceOf(TestAuthenticationAuditListener.class);
} }
@Test @Test
public void ownAuthorizationAuditListener() throws Exception { public void ownAuthorizationAuditListener() throws Exception {
registerAndRefresh(CustomAuthorizationAuditListenerConfiguration.class, registerAndRefresh(CustomAuthorizationAuditListenerConfiguration.class,
AuditAutoConfiguration.class); AuditAutoConfiguration.class);
assertThat(this.context.getBean(AbstractAuthorizationAuditListener.class), assertThat(this.context.getBean(AbstractAuthorizationAuditListener.class))
instanceOf(TestAuthorizationAuditListener.class)); .isInstanceOf(TestAuthorizationAuditListener.class);
} }
private void registerAndRefresh(Class<?>... annotatedClasses) { private void registerAndRefresh(Class<?>... annotatedClasses) {
......
...@@ -53,8 +53,8 @@ import org.springframework.core.io.ClassPathResource; ...@@ -53,8 +53,8 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull; import static org.assertj.core.api.Assertions.offset;
/** /**
* Tests for {@link CacheStatisticsAutoConfiguration}. * Tests for {@link CacheStatisticsAutoConfiguration}.
...@@ -160,8 +160,8 @@ public class CacheStatisticsAutoConfigurationTests { ...@@ -160,8 +160,8 @@ public class CacheStatisticsAutoConfigurationTests {
private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio, private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio,
Double missRatio) { Double missRatio) {
assertNotNull("Cache metrics must not be null", metrics); assertThat(metrics).isNotNull();
assertEquals("Wrong size for metrics " + metrics, size, metrics.getSize()); assertThat(metrics.getSize()).isEqualTo(size);
checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio, checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio,
metrics.getHitRatio()); metrics.getHitRatio());
checkRatio("Wrong miss ratio for metrics " + metrics, missRatio, checkRatio("Wrong miss ratio for metrics " + metrics, missRatio,
...@@ -170,10 +170,10 @@ public class CacheStatisticsAutoConfigurationTests { ...@@ -170,10 +170,10 @@ public class CacheStatisticsAutoConfigurationTests {
private void checkRatio(String message, Double expected, Double actual) { private void checkRatio(String message, Double expected, Double actual) {
if (expected == null || actual == null) { if (expected == null || actual == null) {
assertEquals(message, expected, actual); assertThat(actual).as(message).isEqualTo(expected);
} }
else { else {
assertEquals(message, expected, actual, 0.01D); assertThat(actual).as(message).isEqualTo(expected, offset(0.01D));
} }
} }
......
...@@ -47,10 +47,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -47,10 +47,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link EndpointAutoConfiguration}. * Tests for {@link EndpointAutoConfiguration}.
...@@ -76,15 +73,15 @@ public class EndpointAutoConfigurationTests { ...@@ -76,15 +73,15 @@ public class EndpointAutoConfigurationTests {
@Test @Test
public void endpoints() throws Exception { public void endpoints() throws Exception {
load(EndpointAutoConfiguration.class); load(EndpointAutoConfiguration.class);
assertNotNull(this.context.getBean(BeansEndpoint.class)); assertThat(this.context.getBean(BeansEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(DumpEndpoint.class)); assertThat(this.context.getBean(DumpEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(EnvironmentEndpoint.class)); assertThat(this.context.getBean(EnvironmentEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(HealthEndpoint.class)); assertThat(this.context.getBean(HealthEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(InfoEndpoint.class)); assertThat(this.context.getBean(InfoEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(MetricsEndpoint.class)); assertThat(this.context.getBean(MetricsEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(ShutdownEndpoint.class)); assertThat(this.context.getBean(ShutdownEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(TraceEndpoint.class)); assertThat(this.context.getBean(TraceEndpoint.class)).isNotNull();
assertNotNull(this.context.getBean(RequestMappingEndpoint.class)); assertThat(this.context.getBean(RequestMappingEndpoint.class)).isNotNull();
} }
@Test @Test
...@@ -92,19 +89,19 @@ public class EndpointAutoConfigurationTests { ...@@ -92,19 +89,19 @@ public class EndpointAutoConfigurationTests {
load(EmbeddedDataSourceConfiguration.class, EndpointAutoConfiguration.class, load(EmbeddedDataSourceConfiguration.class, EndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class); HealthIndicatorAutoConfiguration.class);
HealthEndpoint bean = this.context.getBean(HealthEndpoint.class); HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
assertNotNull(bean); assertThat(bean).isNotNull();
Health result = bean.invoke(); Health result = bean.invoke();
assertNotNull(result); assertThat(result).isNotNull();
assertTrue("Wrong result: " + result, result.getDetails().containsKey("db")); assertThat(result.getDetails().containsKey("db")).isTrue();
} }
@Test @Test
public void healthEndpointWithDefaultHealthIndicator() { public void healthEndpointWithDefaultHealthIndicator() {
load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
HealthEndpoint bean = this.context.getBean(HealthEndpoint.class); HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
assertNotNull(bean); assertThat(bean).isNotNull();
Health result = bean.invoke(); Health result = bean.invoke();
assertNotNull(result); assertThat(result).isNotNull();
} }
@Test @Test
...@@ -112,8 +109,8 @@ public class EndpointAutoConfigurationTests { ...@@ -112,8 +109,8 @@ public class EndpointAutoConfigurationTests {
load(PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); load(PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class);
MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class);
Map<String, Object> metrics = endpoint.invoke(); Map<String, Object> metrics = endpoint.invoke();
assertTrue(metrics.containsKey("mem")); assertThat(metrics.containsKey("mem")).isTrue();
assertTrue(metrics.containsKey("heap.used")); assertThat(metrics.containsKey("heap.used")).isTrue();
} }
@Test @Test
...@@ -124,18 +121,19 @@ public class EndpointAutoConfigurationTests { ...@@ -124,18 +121,19 @@ public class EndpointAutoConfigurationTests {
Map<String, Object> metrics = endpoint.invoke(); Map<String, Object> metrics = endpoint.invoke();
// Custom metrics // Custom metrics
assertTrue(metrics.containsKey("foo")); assertThat(metrics.containsKey("foo")).isTrue();
// System metrics still available // System metrics still available
assertTrue(metrics.containsKey("mem")); assertThat(metrics.containsKey("mem")).isTrue();
assertTrue(metrics.containsKey("heap.used")); assertThat(metrics.containsKey("heap.used")).isTrue();
} }
@Test @Test
public void autoConfigurationAuditEndpoints() { public void autoConfigurationAuditEndpoints() {
load(EndpointAutoConfiguration.class, ConditionEvaluationReport.class); load(EndpointAutoConfiguration.class, ConditionEvaluationReport.class);
assertNotNull(this.context.getBean(AutoConfigurationReportEndpoint.class)); assertThat(this.context.getBean(AutoConfigurationReportEndpoint.class))
.isNotNull();
} }
@Test @Test
...@@ -145,9 +143,9 @@ public class EndpointAutoConfigurationTests { ...@@ -145,9 +143,9 @@ public class EndpointAutoConfigurationTests {
this.context.register(EndpointAutoConfiguration.class); this.context.register(EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class);
assertNotNull(endpoint); assertThat(endpoint).isNotNull();
assertNotNull(endpoint.invoke().get("git")); assertThat(endpoint.invoke().get("git")).isNotNull();
assertEquals("bar", endpoint.invoke().get("foo")); assertThat(endpoint.invoke().get("foo")).isEqualTo("bar");
} }
@Test @Test
...@@ -158,8 +156,8 @@ public class EndpointAutoConfigurationTests { ...@@ -158,8 +156,8 @@ public class EndpointAutoConfigurationTests {
this.context.register(EndpointAutoConfiguration.class); this.context.register(EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class);
assertNotNull(endpoint); assertThat(endpoint).isNotNull();
assertNull(endpoint.invoke().get("git")); assertThat(endpoint.invoke().get("git")).isNull();
} }
@Test @Test
...@@ -169,8 +167,8 @@ public class EndpointAutoConfigurationTests { ...@@ -169,8 +167,8 @@ public class EndpointAutoConfigurationTests {
FlywayAutoConfiguration.class, EndpointAutoConfiguration.class); FlywayAutoConfiguration.class, EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
FlywayEndpoint endpoint = this.context.getBean(FlywayEndpoint.class); FlywayEndpoint endpoint = this.context.getBean(FlywayEndpoint.class);
assertNotNull(endpoint); assertThat(endpoint).isNotNull();
assertEquals(1, endpoint.invoke().size()); assertThat(endpoint.invoke()).hasSize(1);
} }
@Test @Test
...@@ -180,8 +178,8 @@ public class EndpointAutoConfigurationTests { ...@@ -180,8 +178,8 @@ public class EndpointAutoConfigurationTests {
LiquibaseAutoConfiguration.class, EndpointAutoConfiguration.class); LiquibaseAutoConfiguration.class, EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
LiquibaseEndpoint endpoint = this.context.getBean(LiquibaseEndpoint.class); LiquibaseEndpoint endpoint = this.context.getBean(LiquibaseEndpoint.class);
assertNotNull(endpoint); assertThat(endpoint).isNotNull();
assertEquals(1, endpoint.invoke().size()); assertThat(endpoint.invoke()).hasSize(1);
} }
private void load(Class<?>... config) { private void load(Class<?>... config) {
......
...@@ -43,10 +43,7 @@ import org.springframework.mock.env.MockEnvironment; ...@@ -43,10 +43,7 @@ import org.springframework.mock.env.MockEnvironment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import static org.junit.Assert.assertFalse; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* Tests for {@link EndpointMBeanExportAutoConfiguration}. * Tests for {@link EndpointMBeanExportAutoConfiguration}.
...@@ -71,11 +68,10 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -71,11 +68,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
EndpointMBeanExportAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer()
assertFalse(mbeanExporter.getServer() .queryNames(getObjectName("*", "*,*", this.context), null)).isNotEmpty();
.queryNames(getObjectName("*", "*,*", this.context), null).isEmpty());
} }
@Test @Test
...@@ -86,12 +82,10 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -86,12 +82,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
ManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class, ManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer()
assertTrue(mbeanExporter.getServer() .queryNames(getObjectName("*", "*,*", this.context), null)).isEmpty();
.queryNames(getObjectName("*", "*,*", this.context), null).isEmpty());
} }
@Test @Test
...@@ -102,12 +96,10 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -102,12 +96,10 @@ public class EndpointMBeanExportAutoConfigurationTests {
NestedInManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class, NestedInManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertNotNull(this.context.getBean(EndpointMBeanExporter.class)); assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer()
assertTrue(mbeanExporter.getServer() .queryNames(getObjectName("*", "*,*", this.context), null)).isEmpty();
.queryNames(getObjectName("*", "*,*", this.context), null).isEmpty());
} }
@Test(expected = NoSuchBeanDefinitionException.class) @Test(expected = NoSuchBeanDefinitionException.class)
...@@ -120,7 +112,6 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -120,7 +112,6 @@ public class EndpointMBeanExportAutoConfigurationTests {
EndpointMBeanExportAutoConfiguration.class); EndpointMBeanExportAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
this.context.getBean(EndpointMBeanExporter.class); this.context.getBean(EndpointMBeanExporter.class);
fail();
} }
@Test @Test
...@@ -138,11 +129,9 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -138,11 +129,9 @@ public class EndpointMBeanExportAutoConfigurationTests {
this.context.getBean(EndpointMBeanExporter.class); this.context.getBean(EndpointMBeanExporter.class);
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(
assertNotNull(mbeanExporter.getServer() getObjectName("test-domain", "healthEndpoint", this.context).toString()
.getMBeanInfo(ObjectNameManager.getInstance( + ",key1=value1,key2=value2"))).isNotNull();
getObjectName("test-domain", "healthEndpoint", this.context)
.toString() + ",key1=value1,key2=value2")));
} }
@Test @Test
...@@ -151,15 +140,12 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -151,15 +140,12 @@ public class EndpointMBeanExportAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class,
EndpointMBeanExportAutoConfiguration.class); EndpointMBeanExportAutoConfiguration.class);
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, parent.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class,
EndpointMBeanExportAutoConfiguration.class); EndpointMBeanExportAutoConfiguration.class);
this.context.setParent(parent); this.context.setParent(parent);
parent.refresh(); parent.refresh();
this.context.refresh(); this.context.refresh();
parent.close(); parent.close();
} }
...@@ -178,9 +164,7 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -178,9 +164,7 @@ public class EndpointMBeanExportAutoConfigurationTests {
return ObjectNameManager.getInstance(String.format(name, domain, beanKey, return ObjectNameManager.getInstance(String.format(name, domain, beanKey,
ObjectUtils.getIdentityHexString(applicationContext))); ObjectUtils.getIdentityHexString(applicationContext)));
} }
else { return ObjectNameManager.getInstance(String.format(name, domain, beanKey));
return ObjectNameManager.getInstance(String.format(name, domain, beanKey));
}
} }
@Configuration @Configuration
...@@ -223,6 +207,7 @@ public class EndpointMBeanExportAutoConfigurationTests { ...@@ -223,6 +207,7 @@ public class EndpointMBeanExportAutoConfigurationTests {
public Boolean invoke() { public Boolean invoke() {
return true; return true;
} }
} }
} }
......
...@@ -64,8 +64,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -64,8 +64,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import static org.junit.Assert.assertNotNull; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for MVC {@link Endpoint}s. * Integration tests for MVC {@link Endpoint}s.
...@@ -89,18 +88,16 @@ public class EndpointMvcIntegrationTests { ...@@ -89,18 +88,16 @@ public class EndpointMvcIntegrationTests {
public void envEndpointHidden() throws InterruptedException { public void envEndpointHidden() throws InterruptedException {
String body = new TestRestTemplate().getForObject( String body = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/env/user.dir", String.class); "http://localhost:" + this.port + "/env/user.dir", String.class);
assertNotNull(body); assertThat(body).isNotNull().contains("spring-boot-actuator");
assertTrue("Wrong body: \n" + body, body.contains("spring-boot-actuator")); assertThat(this.interceptor.invoked()).isTrue();
assertTrue(this.interceptor.invoked());
} }
@Test @Test
public void healthEndpointNotHidden() throws InterruptedException { public void healthEndpointNotHidden() throws InterruptedException {
String body = new TestRestTemplate() String body = new TestRestTemplate()
.getForObject("http://localhost:" + this.port + "/health", String.class); .getForObject("http://localhost:" + this.port + "/health", String.class);
assertNotNull(body); assertThat(body).isNotNull().contains("status");
assertTrue("Wrong body: \n" + body, body.contains("status")); assertThat(this.interceptor.invoked()).isTrue();
assertTrue(this.interceptor.invoked());
} }
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
......
...@@ -60,6 +60,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti ...@@ -60,6 +60,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.boot.test.assertj.Matched;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -79,16 +80,9 @@ import org.springframework.web.servlet.ModelAndView; ...@@ -79,16 +80,9 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; 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.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.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.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -136,8 +130,10 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -136,8 +130,10 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent("/endpoint", ports.get().server, "endpointoutput"); assertContent("/endpoint", ports.get().server, "endpointoutput");
assertContent("/controller", ports.get().management, null); assertContent("/controller", ports.get().management, null);
assertContent("/endpoint", ports.get().management, null); assertContent("/endpoint", ports.get().management, null);
assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); assertThat(hasHeader("/endpoint", ports.get().server, "X-Application-Context"))
assertTrue(this.applicationContext.containsBean("applicationContextIdFilter")); .isTrue();
assertThat(this.applicationContext.containsBean("applicationContextIdFilter"))
.isTrue();
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -150,8 +146,10 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -150,8 +146,10 @@ public class EndpointWebMvcAutoConfigurationTests {
BaseConfiguration.class, ServerPortConfig.class, BaseConfiguration.class, ServerPortConfig.class,
EndpointWebMvcAutoConfiguration.class); EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh(); this.applicationContext.refresh();
assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); assertThat(hasHeader("/endpoint", ports.get().server, "X-Application-Context"))
assertFalse(this.applicationContext.containsBean("applicationContextIdFilter")); .isFalse();
assertThat(this.applicationContext.containsBean("applicationContextIdFilter"))
.isFalse();
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -171,7 +169,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -171,7 +169,7 @@ public class EndpointWebMvcAutoConfigurationTests {
.getBean(ManagementContextResolver.class).getApplicationContext(); .getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField( List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors"); managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertEquals(1, interceptors.size()); assertThat(interceptors).hasSize(1);
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -244,7 +242,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -244,7 +242,7 @@ public class EndpointWebMvcAutoConfigurationTests {
this.applicationContext.addApplicationListener(grabManagementPort); this.applicationContext.addApplicationListener(grabManagementPort);
this.applicationContext.refresh(); this.applicationContext.refresh();
int managementPort = grabManagementPort.getServletContainer().getPort(); 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("/controller", ports.get().server, "controlleroutput");
assertContent("/endpoint", ports.get().server, null); assertContent("/endpoint", ports.get().server, null);
assertContent("/controller", managementPort, null); assertContent("/controller", managementPort, null);
...@@ -337,8 +335,9 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -337,8 +335,9 @@ public class EndpointWebMvcAutoConfigurationTests {
EndpointWebMvcAutoConfiguration.class); EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh(); this.applicationContext.refresh();
assertContent("/controller", ports.get().server, "controlleroutput"); assertContent("/controller", ports.get().server, "controlleroutput");
assertEquals("foo", ServerProperties serverProperties = this.applicationContext
this.applicationContext.getBean(ServerProperties.class).getDisplayName()); .getBean(ServerProperties.class);
assertThat(serverProperties.getDisplayName()).isEqualTo("foo");
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -354,9 +353,9 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -354,9 +353,9 @@ public class EndpointWebMvcAutoConfigurationTests {
.getProperty("local.server.port", Integer.class); .getProperty("local.server.port", Integer.class);
Integer localManagementPort = this.applicationContext.getEnvironment() Integer localManagementPort = this.applicationContext.getEnvironment()
.getProperty("local.management.port", Integer.class); .getProperty("local.management.port", Integer.class);
assertThat(localServerPort, notNullValue()); assertThat(localServerPort).isNotNull();
assertThat(localManagementPort, notNullValue()); assertThat(localManagementPort).isNotNull();
assertThat(localServerPort, equalTo(localManagementPort)); assertThat(localServerPort).isEqualTo(localManagementPort);
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -373,11 +372,11 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -373,11 +372,11 @@ public class EndpointWebMvcAutoConfigurationTests {
.getProperty("local.server.port", Integer.class); .getProperty("local.server.port", Integer.class);
Integer localManagementPort = this.applicationContext.getEnvironment() Integer localManagementPort = this.applicationContext.getEnvironment()
.getProperty("local.management.port", Integer.class); .getProperty("local.management.port", Integer.class);
assertThat(localServerPort, notNullValue()); assertThat(localServerPort).isNotNull();
assertThat(localManagementPort, notNullValue()); assertThat(localManagementPort).isNotNull();
assertThat(localServerPort, not(equalTo(localManagementPort))); assertThat(localServerPort).isNotEqualTo(localManagementPort);
assertThat(this.applicationContext.getBean(ServerPortConfig.class).getCount(), assertThat(this.applicationContext.getBean(ServerPortConfig.class).getCount())
equalTo(2)); .isEqualTo(2);
this.applicationContext.close(); this.applicationContext.close();
assertAllClosed(); assertAllClosed();
} }
...@@ -389,7 +388,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -389,7 +388,7 @@ public class EndpointWebMvcAutoConfigurationTests {
this.applicationContext.refresh(); this.applicationContext.refresh();
RequestMappingInfoHandlerMapping mapping = this.applicationContext RequestMappingInfoHandlerMapping mapping = this.applicationContext
.getBean(RequestMappingInfoHandlerMapping.class); .getBean(RequestMappingInfoHandlerMapping.class);
assertThat(mapping, not(instanceOf(EndpointHandlerMapping.class))); assertThat(mapping).isNotEqualTo(instanceOf(EndpointHandlerMapping.class));
} }
@Test @Test
...@@ -398,8 +397,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -398,8 +397,7 @@ public class EndpointWebMvcAutoConfigurationTests {
ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh(); this.applicationContext.refresh();
// /health, /metrics, /env, /actuator (/shutdown is disabled by default) // /health, /metrics, /env, /actuator (/shutdown is disabled by default)
assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).hasSize(4);
is(equalTo(4)));
} }
@Test @Test
...@@ -409,8 +407,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -409,8 +407,7 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.applicationContext, EnvironmentTestUtils.addEnvironment(this.applicationContext,
"ENDPOINTS_ENABLED:false"); "ENDPOINTS_ENABLED:false");
this.applicationContext.refresh(); this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).isEmpty();
is(equalTo(0)));
} }
@Test @Test
...@@ -450,9 +447,8 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -450,9 +447,8 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.applicationContext, EnvironmentTestUtils.addEnvironment(this.applicationContext,
"endpoints.shutdown.enabled:true"); "endpoints.shutdown.enabled:true");
this.applicationContext.refresh(); this.applicationContext.refresh();
assertThat( assertThat(this.applicationContext.getBeansOfType(ShutdownMvcEndpoint.class))
this.applicationContext.getBeansOfType(ShutdownMvcEndpoint.class).size(), .hasSize(1);
is(equalTo(1)));
} }
private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) { private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) {
...@@ -461,7 +457,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -461,7 +457,7 @@ public class EndpointWebMvcAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.applicationContext, EnvironmentTestUtils.addEnvironment(this.applicationContext,
String.format("endpoints.%s.enabled:false", name)); String.format("endpoints.%s.enabled:false", name));
this.applicationContext.refresh(); this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(0))); assertThat(this.applicationContext.getBeansOfType(type)).isEmpty();
} }
private void endpointEnabledOverride(String name, Class<? extends MvcEndpoint> type) private void endpointEnabledOverride(String name, Class<? extends MvcEndpoint> type)
...@@ -472,7 +468,7 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -472,7 +468,7 @@ public class EndpointWebMvcAutoConfigurationTests {
"endpoints.enabled:false", "endpoints.enabled:false",
String.format("endpoints_%s_enabled:true", name)); String.format("endpoints_%s_enabled:true", name));
this.applicationContext.refresh(); this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(1))); assertThat(this.applicationContext.getBeansOfType(type)).hasSize(1);
} }
private void assertAllClosed() throws Exception { private void assertAllClosed() throws Exception {
...@@ -482,7 +478,6 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -482,7 +478,6 @@ public class EndpointWebMvcAutoConfigurationTests {
assertContent("/endpoint", ports.get().management, null); assertContent("/endpoint", ports.get().management, null);
} }
@SuppressWarnings("unchecked")
public void assertContent(String url, int port, Object expected) throws Exception { public void assertContent(String url, int port, Object expected) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory ClientHttpRequest request = clientHttpRequestFactory
...@@ -493,10 +488,10 @@ public class EndpointWebMvcAutoConfigurationTests { ...@@ -493,10 +488,10 @@ public class EndpointWebMvcAutoConfigurationTests {
String actual = StreamUtils.copyToString(response.getBody(), String actual = StreamUtils.copyToString(response.getBody(),
Charset.forName("UTF-8")); Charset.forName("UTF-8"));
if (expected instanceof Matcher) { if (expected instanceof Matcher) {
assertThat(actual, is((Matcher<String>) expected)); assertThat(actual).is(Matched.by((Matcher<?>) expected));
} }
else { else {
assertThat(actual, equalTo(expected)); assertThat(actual).isEqualTo(expected);
} }
} }
finally { finally {
......
...@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 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}. * Tests for {@link EndpointWebMvcAutoConfiguration} of the {@link HealthMvcEndpoint}.
...@@ -62,8 +62,8 @@ public class HealthMvcEndpointAutoConfigurationTests { ...@@ -62,8 +62,8 @@ public class HealthMvcEndpointAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
Health health = (Health) this.context.getBean(HealthMvcEndpoint.class) Health health = (Health) this.context.getBean(HealthMvcEndpoint.class)
.invoke(null); .invoke(null);
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals(null, health.getDetails().get("foo")); assertThat(health.getDetails().get("foo")).isNull();
} }
@Test @Test
...@@ -76,9 +76,9 @@ public class HealthMvcEndpointAutoConfigurationTests { ...@@ -76,9 +76,9 @@ public class HealthMvcEndpointAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
Health health = (Health) this.context.getBean(HealthMvcEndpoint.class) Health health = (Health) this.context.getBean(HealthMvcEndpoint.class)
.invoke(null); .invoke(null);
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
Health map = (Health) health.getDetails().get("test"); Health map = (Health) health.getDetails().get("test");
assertEquals("bar", map.getDetails().get("foo")); assertThat(map.getDetails().get("foo")).isEqualTo("bar");
} }
@Configuration @Configuration
......
...@@ -41,7 +41,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; ...@@ -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.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; 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}. * Tests for {@link JolokiaAutoConfiguration}.
...@@ -74,8 +74,7 @@ public class JolokiaAutoConfigurationTests { ...@@ -74,8 +74,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
JolokiaAutoConfiguration.class); JolokiaAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(1, assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
} }
@Test @Test
...@@ -89,8 +88,7 @@ public class JolokiaAutoConfigurationTests { ...@@ -89,8 +88,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
JolokiaAutoConfiguration.class); JolokiaAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(1, assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar")) mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
.andExpect(MockMvcResultMatchers.content() .andExpect(MockMvcResultMatchers.content()
...@@ -122,8 +120,7 @@ public class JolokiaAutoConfigurationTests { ...@@ -122,8 +120,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
JolokiaAutoConfiguration.class); JolokiaAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(0, assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).isEmpty();
this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
} }
private void assertEndpointEnabled(String... pairs) { private void assertEndpointEnabled(String... pairs) {
...@@ -135,8 +132,7 @@ public class JolokiaAutoConfigurationTests { ...@@ -135,8 +132,7 @@ public class JolokiaAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
JolokiaAutoConfiguration.class); JolokiaAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(1, assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
} }
@Configuration @Configuration
......
...@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure; ...@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.autoconfigure;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ManagementServerPropertiesAutoConfiguration}. * Tests for {@link ManagementServerPropertiesAutoConfiguration}.
...@@ -33,8 +31,8 @@ public class ManagementServerPropertiesAutoConfigurationTests { ...@@ -33,8 +31,8 @@ public class ManagementServerPropertiesAutoConfigurationTests {
@Test @Test
public void defaultManagementServerProperties() { public void defaultManagementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties(); ManagementServerProperties properties = new ManagementServerProperties();
assertThat(properties.getPort(), nullValue()); assertThat(properties.getPort()).isNull();
assertThat(properties.getContextPath(), equalTo("")); assertThat(properties.getContextPath()).isEqualTo("");
} }
@Test @Test
...@@ -42,22 +40,22 @@ public class ManagementServerPropertiesAutoConfigurationTests { ...@@ -42,22 +40,22 @@ public class ManagementServerPropertiesAutoConfigurationTests {
ManagementServerProperties properties = new ManagementServerProperties(); ManagementServerProperties properties = new ManagementServerProperties();
properties.setPort(123); properties.setPort(123);
properties.setContextPath("/foo"); properties.setContextPath("/foo");
assertThat(properties.getPort(), equalTo(123)); assertThat(properties.getPort()).isEqualTo(123);
assertThat(properties.getContextPath(), equalTo("/foo")); assertThat(properties.getContextPath()).isEqualTo("/foo");
} }
@Test @Test
public void trailingSlashOfContextPathIsRemoved() { public void trailingSlashOfContextPathIsRemoved() {
ManagementServerProperties properties = new ManagementServerProperties(); ManagementServerProperties properties = new ManagementServerProperties();
properties.setContextPath("/foo/"); properties.setContextPath("/foo/");
assertThat(properties.getContextPath(), equalTo("/foo")); assertThat(properties.getContextPath()).isEqualTo("/foo");
} }
@Test @Test
public void slashOfContextPathIsDefaultValue() { public void slashOfContextPathIsDefaultValue() {
ManagementServerProperties properties = new ManagementServerProperties(); ManagementServerProperties properties = new ManagementServerProperties();
properties.setContextPath("/"); properties.setContextPath("/");
assertThat(properties.getContextPath(), equalTo("")); assertThat(properties.getContextPath()).isEqualTo("");
} }
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.autoconfigure; package org.springframework.boot.actuate.autoconfigure;
import java.util.ArrayList;
import javax.servlet.Filter; import javax.servlet.Filter;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
...@@ -42,6 +44,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au ...@@ -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.config.annotation.authentication.configuration.EnableGlobalAuthentication;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
...@@ -55,12 +58,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; ...@@ -55,12 +58,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import static org.hamcrest.Matchers.greaterThan; import static org.assertj.core.api.Assertions.assertThat;
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.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -96,21 +94,20 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -96,21 +94,20 @@ public class ManagementWebSecurityAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false"); EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
this.context.refresh(); this.context.refresh();
assertNotNull(this.context.getBean(AuthenticationManagerBuilder.class)); assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class); FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
// 1 for static resources, one for management endpoints and one for the rest // 1 for static resources, one for management endpoints and one for the rest
assertThat(filterChainProxy.getFilterChains(), hasSize(3)); assertThat(filterChainProxy.getFilterChains()).hasSize(3);
assertThat(filterChainProxy.getFilters("/beans"), hasSize(greaterThan(0))); assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/"), hasSize(greaterThan(0))); assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans.foo"), hasSize(greaterThan(0))); assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/foo/bar"), assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
hasSize(greaterThan(0)));
} }
@Test @Test
public void testPathNormalization() throws Exception { public void testPathNormalization() throws Exception {
String path = "admin/./error"; String path = "admin/./error";
assertEquals("admin/error", StringUtils.cleanPath(path)); assertThat(StringUtils.cleanPath(path)).isEqualTo("admin/error");
} }
@Test @Test
...@@ -120,8 +117,10 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -120,8 +117,10 @@ public class ManagementWebSecurityAutoConfigurationTests {
this.context.register(WebConfiguration.class); this.context.register(WebConfiguration.class);
this.context.refresh(); this.context.refresh();
UserDetails user = getUser(); UserDetails user = getUser();
assertTrue(user.getAuthorities().containsAll(AuthorityUtils ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN"))); user.getAuthorities());
assertThat(authorities).containsAll(AuthorityUtils
.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN"));
} }
private UserDetails getUser() { private UserDetails getUser() {
...@@ -147,8 +146,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -147,8 +146,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none"); EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
this.context.refresh(); this.context.refresh();
// Just the application and management endpoints now // Just the application and management endpoints now
assertEquals(2, assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
this.context.getBean(FilterChainProxy.class).getFilterChains().size()); .hasSize(2);
} }
@Test @Test
...@@ -160,8 +159,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -160,8 +159,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
// Just the management endpoints (one filter) and ignores now plus the backup // Just the management endpoints (one filter) and ignores now plus the backup
// filter on app endpoints // filter on app endpoints
assertEquals(3, assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
this.context.getBean(FilterChainProxy.class).getFilterChains().size()); .hasSize(3);
} }
@Test @Test
...@@ -174,8 +173,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -174,8 +173,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(this.context.getBean(TestConfiguration.class).authenticationManager, assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo(
this.context.getBean(AuthenticationManager.class)); this.context.getBean(TestConfiguration.class).authenticationManager);
} }
@Test @Test
...@@ -188,8 +187,8 @@ public class ManagementWebSecurityAutoConfigurationTests { ...@@ -188,8 +187,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(this.context.getBean(TestConfiguration.class).authenticationManager, assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo(
this.context.getBean(AuthenticationManager.class)); this.context.getBean(TestConfiguration.class).authenticationManager);
} }
// gh-2466 // gh-2466
......
...@@ -42,9 +42,7 @@ import org.springframework.messaging.MessageHandler; ...@@ -42,9 +42,7 @@ import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException; import org.springframework.messaging.MessagingException;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
import static org.hamcrest.Matchers.notNullValue; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link MetricExportAutoConfiguration}. * Tests for {@link MetricExportAutoConfiguration}.
...@@ -76,7 +74,7 @@ public class MetricExportAutoConfigurationTests { ...@@ -76,7 +74,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration.class, MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
MetricExporters exporter = this.context.getBean(MetricExporters.class); MetricExporters exporter = this.context.getBean(MetricExporters.class);
assertNotNull(exporter); assertThat(exporter).isNotNull();
} }
@Test @Test
...@@ -86,7 +84,7 @@ public class MetricExportAutoConfigurationTests { ...@@ -86,7 +84,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration.class, MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class); GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertNotNull(gaugeService); assertThat(gaugeService).isNotNull();
gaugeService.submit("foo", 2.7); gaugeService.submit("foo", 2.7);
MetricExporters exporters = this.context.getBean(MetricExporters.class); MetricExporters exporters = this.context.getBean(MetricExporters.class);
MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters() MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters()
...@@ -132,7 +130,7 @@ public class MetricExportAutoConfigurationTests { ...@@ -132,7 +130,7 @@ public class MetricExportAutoConfigurationTests {
MetricExportAutoConfiguration.class, MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertThat(this.context.getBean(StatsdMetricWriter.class), notNullValue()); assertThat(this.context.getBean(StatsdMetricWriter.class)).isNotNull();
} }
@Configuration @Configuration
......
...@@ -53,11 +53,10 @@ import org.springframework.web.context.request.async.DeferredResult; ...@@ -53,11 +53,10 @@ import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.NestedServletException; 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.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
...@@ -173,7 +172,7 @@ public class MetricFilterAutoConfigurationTests { ...@@ -173,7 +172,7 @@ public class MetricFilterAutoConfigurationTests {
public void skipsFilterIfMissingServices() throws Exception { public void skipsFilterIfMissingServices() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
MetricFilterAutoConfiguration.class); MetricFilterAutoConfiguration.class);
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0)); assertThat(context.getBeansOfType(Filter.class).size()).isEqualTo(0);
context.close(); context.close();
} }
...@@ -184,7 +183,7 @@ public class MetricFilterAutoConfigurationTests { ...@@ -184,7 +183,7 @@ public class MetricFilterAutoConfigurationTests {
"endpoints.metrics.filter.enabled:false"); "endpoints.metrics.filter.enabled:false");
context.register(Config.class, MetricFilterAutoConfiguration.class); context.register(Config.class, MetricFilterAutoConfiguration.class);
context.refresh(); context.refresh();
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0)); assertThat(context.getBeansOfType(Filter.class).size()).isEqualTo(0);
context.close(); context.close();
} }
...@@ -269,7 +268,7 @@ public class MetricFilterAutoConfigurationTests { ...@@ -269,7 +268,7 @@ public class MetricFilterAutoConfigurationTests {
fail(); fail();
} }
catch (Exception ex) { catch (Exception ex) {
assertThat(result.getRequest().getAttribute(attributeName), is(nullValue())); assertThat(result.getRequest().getAttribute(attributeName)).isNull();
verify(context.getBean(CounterService.class)) verify(context.getBean(CounterService.class))
.increment("status.500.createFailure"); .increment("status.500.createFailure");
} }
......
...@@ -33,10 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -33,10 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
...@@ -61,12 +58,12 @@ public class MetricRepositoryAutoConfigurationTests { ...@@ -61,12 +58,12 @@ public class MetricRepositoryAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
MetricRepositoryAutoConfiguration.class); MetricRepositoryAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(BufferGaugeService.class); GaugeService gaugeService = this.context.getBean(BufferGaugeService.class);
assertNotNull(gaugeService); assertThat(gaugeService).isNotNull();
assertNotNull(this.context.getBean(BufferCounterService.class)); assertThat(this.context.getBean(BufferCounterService.class)).isNotNull();
assertNotNull(this.context.getBean(PrefixMetricReader.class)); assertThat(this.context.getBean(PrefixMetricReader.class)).isNotNull();
gaugeService.submit("foo", 2.7); gaugeService.submit("foo", 2.7);
assertEquals(2.7, MetricReader bean = this.context.getBean(MetricReader.class);
this.context.getBean(MetricReader.class).findOne("gauge.foo").getValue()); assertThat(bean.findOne("gauge.foo").getValue()).isEqualTo(2.7);
} }
@Test @Test
...@@ -75,25 +72,23 @@ public class MetricRepositoryAutoConfigurationTests { ...@@ -75,25 +72,23 @@ public class MetricRepositoryAutoConfigurationTests {
MetricsDropwizardAutoConfiguration.class, MetricsDropwizardAutoConfiguration.class,
MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class); MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class);
GaugeService gaugeService = this.context.getBean(GaugeService.class); GaugeService gaugeService = this.context.getBean(GaugeService.class);
assertNotNull(gaugeService); assertThat(gaugeService).isNotNull();
gaugeService.submit("foo", 2.7); gaugeService.submit("foo", 2.7);
DropwizardMetricServices exporter = this.context DropwizardMetricServices exporter = this.context
.getBean(DropwizardMetricServices.class); .getBean(DropwizardMetricServices.class);
assertEquals(gaugeService, exporter); assertThat(exporter).isEqualTo(gaugeService);
MetricRegistry registry = this.context.getBean(MetricRegistry.class); MetricRegistry registry = this.context.getBean(MetricRegistry.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo"); Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo");
assertEquals(new Double(2.7), gauge.getValue()); assertThat(gauge.getValue()).isEqualTo(new Double(2.7));
} }
@Test @Test
public void skipsIfBeansExist() throws Exception { public void skipsIfBeansExist() throws Exception {
this.context = new AnnotationConfigApplicationContext(Config.class, this.context = new AnnotationConfigApplicationContext(Config.class,
MetricRepositoryAutoConfiguration.class); MetricRepositoryAutoConfiguration.class);
assertThat(this.context.getBeansOfType(BufferGaugeService.class).size(), assertThat(this.context.getBeansOfType(BufferGaugeService.class)).isEmpty();
equalTo(0)); assertThat(this.context.getBeansOfType(BufferCounterService.class)).isEmpty();
assertThat(this.context.getBeansOfType(BufferCounterService.class).size(),
equalTo(0));
} }
@Configuration @Configuration
......
...@@ -59,10 +59,7 @@ import org.springframework.jdbc.core.ConnectionCallback; ...@@ -59,10 +59,7 @@ import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.SocketUtils; import org.springframework.util.SocketUtils;
import static org.hamcrest.Matchers.hasKey; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -88,14 +85,14 @@ public class PublicMetricsAutoConfigurationTests { ...@@ -88,14 +85,14 @@ public class PublicMetricsAutoConfigurationTests {
@Test @Test
public void systemPublicMetrics() throws Exception { public void systemPublicMetrics() throws Exception {
load(); load();
assertEquals(1, this.context.getBeansOfType(SystemPublicMetrics.class).size()); assertThat(this.context.getBeansOfType(SystemPublicMetrics.class)).hasSize(1);
} }
@Test @Test
public void metricReaderPublicMetrics() throws Exception { public void metricReaderPublicMetrics() throws Exception {
load(); load();
assertEquals(1, assertThat(this.context.getBeansOfType(MetricReaderPublicMetrics.class))
this.context.getBeansOfType(MetricReaderPublicMetrics.class).size()); .hasSize(1);
} }
@Test @Test
...@@ -104,15 +101,15 @@ public class PublicMetricsAutoConfigurationTests { ...@@ -104,15 +101,15 @@ public class PublicMetricsAutoConfigurationTests {
RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class,
PublicMetricsAutoConfiguration.class); PublicMetricsAutoConfiguration.class);
RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class); RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class);
assertNotNull(richGaugeReader); assertThat(richGaugeReader).isNotNull();
given(richGaugeReader.findAll()) given(richGaugeReader.findAll())
.willReturn(Collections.singletonList(new RichGauge("bar", 3.7d))); .willReturn(Collections.singletonList(new RichGauge("bar", 3.7d)));
RichGaugeReaderPublicMetrics publicMetrics = context RichGaugeReaderPublicMetrics publicMetrics = context
.getBean(RichGaugeReaderPublicMetrics.class); .getBean(RichGaugeReaderPublicMetrics.class);
assertNotNull(publicMetrics); assertThat(publicMetrics).isNotNull();
Collection<Metric<?>> metrics = publicMetrics.metrics(); Collection<Metric<?>> metrics = publicMetrics.metrics();
assertNotNull(metrics); assertThat(metrics).isNotNull();
assertEquals(metrics.size(), 6); assertThat(6).isEqualTo(metrics.size());
assertHasMetric(metrics, new Metric<Double>("bar.val", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.val", 3.7d));
assertHasMetric(metrics, new Metric<Double>("bar.avg", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.avg", 3.7d));
assertHasMetric(metrics, new Metric<Double>("bar.min", 3.7d)); assertHasMetric(metrics, new Metric<Double>("bar.min", 3.7d));
...@@ -125,8 +122,7 @@ public class PublicMetricsAutoConfigurationTests { ...@@ -125,8 +122,7 @@ public class PublicMetricsAutoConfigurationTests {
@Test @Test
public void noDataSource() { public void noDataSource() {
load(); load();
assertEquals(0, assertThat(this.context.getBeansOfType(DataSourcePublicMetrics.class)).isEmpty();
this.context.getBeansOfType(DataSourcePublicMetrics.class).size());
} }
@Test @Test
...@@ -194,13 +190,13 @@ public class PublicMetricsAutoConfigurationTests { ...@@ -194,13 +190,13 @@ public class PublicMetricsAutoConfigurationTests {
@Test @Test
public void tomcatMetrics() throws Exception { public void tomcatMetrics() throws Exception {
loadWeb(TomcatConfiguration.class); loadWeb(TomcatConfiguration.class);
assertEquals(1, this.context.getBeansOfType(TomcatPublicMetrics.class).size()); assertThat(this.context.getBeansOfType(TomcatPublicMetrics.class)).hasSize(1);
} }
@Test @Test
public void noCacheMetrics() { public void noCacheMetrics() {
load(); load();
assertEquals(0, this.context.getBeansOfType(CachePublicMetrics.class).size()); assertThat(this.context.getBeansOfType(CachePublicMetrics.class)).isEmpty();
} }
@Test @Test
...@@ -236,7 +232,7 @@ public class PublicMetricsAutoConfigurationTests { ...@@ -236,7 +232,7 @@ public class PublicMetricsAutoConfigurationTests {
content.put(metric.getName(), metric.getValue()); content.put(metric.getName(), metric.getValue());
} }
for (String key : keys) { for (String key : keys) {
assertThat(content, hasKey(key)); assertThat(content).containsKey(key);
} }
} }
......
...@@ -24,9 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -24,9 +24,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
...@@ -40,7 +38,7 @@ public class TraceRepositoryAutoConfigurationTests { ...@@ -40,7 +38,7 @@ public class TraceRepositoryAutoConfigurationTests {
public void configuresInMemoryTraceRepository() throws Exception { public void configuresInMemoryTraceRepository() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
TraceRepositoryAutoConfiguration.class); TraceRepositoryAutoConfiguration.class);
assertNotNull(context.getBean(InMemoryTraceRepository.class)); assertThat(context.getBean(InMemoryTraceRepository.class)).isNotNull();
context.close(); context.close();
} }
...@@ -48,9 +46,8 @@ public class TraceRepositoryAutoConfigurationTests { ...@@ -48,9 +46,8 @@ public class TraceRepositoryAutoConfigurationTests {
public void skipsIfRepositoryExists() throws Exception { public void skipsIfRepositoryExists() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
Config.class, TraceRepositoryAutoConfiguration.class); Config.class, TraceRepositoryAutoConfiguration.class);
assertThat(context.getBeansOfType(InMemoryTraceRepository.class).size(), assertThat(context.getBeansOfType(InMemoryTraceRepository.class)).isEmpty();
equalTo(0)); assertThat(context.getBeansOfType(TraceRepository.class)).hasSize(1);
assertThat(context.getBeansOfType(TraceRepository.class).size(), equalTo(1));
context.close(); context.close();
} }
......
...@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.trace.WebRequestTraceFilter; ...@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.junit.Assert.assertNotNull; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link TraceWebFilterAutoConfiguration}. * Tests for {@link TraceWebFilterAutoConfiguration}.
...@@ -37,7 +37,7 @@ public class TraceWebFilterAutoConfigurationTests { ...@@ -37,7 +37,7 @@ public class TraceWebFilterAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
TraceRepositoryAutoConfiguration.class, TraceRepositoryAutoConfiguration.class,
TraceWebFilterAutoConfiguration.class); TraceWebFilterAutoConfiguration.class);
assertNotNull(context.getBean(WebRequestTraceFilter.class)); assertThat(context.getBean(WebRequestTraceFilter.class)).isNotNull();
context.close(); context.close();
} }
......
...@@ -31,8 +31,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -31,8 +31,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Abstract base class for endpoint tests. * Abstract base class for endpoint tests.
...@@ -79,12 +78,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -79,12 +78,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
@Test @Test
public void getId() throws Exception { public void getId() throws Exception {
assertThat(getEndpointBean().getId(), equalTo(this.id)); assertThat(getEndpointBean().getId()).isEqualTo(this.id);
} }
@Test @Test
public void isSensitive() throws Exception { public void isSensitive() throws Exception {
assertThat(getEndpointBean().isSensitive(), equalTo(this.sensitive)); assertThat(getEndpointBean().isSensitive()).isEqualTo(this.sensitive);
} }
@Test @Test
...@@ -93,7 +92,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -93,7 +92,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
EnvironmentTestUtils.addEnvironment(this.context, this.property + ".id:myid"); EnvironmentTestUtils.addEnvironment(this.context, this.property + ".id:myid");
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().getId(), equalTo("myid")); assertThat(getEndpointBean().getId()).isEqualTo("myid");
} }
@Test @Test
...@@ -105,7 +104,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -105,7 +104,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isSensitive(), equalTo(!this.sensitive)); assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive);
} }
@Test @Test
...@@ -118,12 +117,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -118,12 +117,12 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isSensitive(), equalTo(!this.sensitive)); assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive);
} }
@Test @Test
public void isEnabledByDefault() throws Exception { public void isEnabledByDefault() throws Exception {
assertThat(getEndpointBean().isEnabled(), equalTo(true)); assertThat(getEndpointBean().isEnabled()).isTrue();
} }
@Test @Test
...@@ -134,7 +133,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -134,7 +133,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isEnabled(), equalTo(false)); assertThat(getEndpointBean().isEnabled()).isFalse();
} }
@Test @Test
...@@ -147,7 +146,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -147,7 +146,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
((AbstractEndpoint) getEndpointBean()).setEnabled(true); ((AbstractEndpoint) getEndpointBean()).setEnabled(true);
assertThat(getEndpointBean().isEnabled(), equalTo(true)); assertThat(getEndpointBean().isEnabled()).isTrue();
} }
@Test @Test
...@@ -158,7 +157,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -158,7 +157,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isEnabled(), equalTo(false)); assertThat(getEndpointBean().isEnabled()).isFalse();
} }
@Test @Test
...@@ -171,7 +170,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -171,7 +170,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isEnabled(), equalTo(true)); assertThat(getEndpointBean().isEnabled()).isTrue();
} }
@Test @Test
...@@ -199,7 +198,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -199,7 +198,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
this.context.getEnvironment().getPropertySources().addFirst(propertySource); this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().isSensitive(), equalTo(sensitive)); assertThat(getEndpointBean().isSensitive()).isEqualTo(sensitive);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
...@@ -33,7 +33,7 @@ import org.springframework.context.annotation.Bean; ...@@ -33,7 +33,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.Configuration; 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; import static org.mockito.Mockito.mock;
/** /**
...@@ -57,9 +57,9 @@ public class AutoConfigurationReportEndpointTests ...@@ -57,9 +57,9 @@ public class AutoConfigurationReportEndpointTests
this.context.register(this.configClass); this.context.register(this.configClass);
this.context.refresh(); this.context.refresh();
Report report = getEndpointBean().invoke(); Report report = getEndpointBean().invoke();
assertTrue(report.getPositiveMatches().isEmpty()); assertThat(report.getPositiveMatches()).isEmpty();
assertTrue(report.getNegativeMatches().containsKey("a")); assertThat(report.getNegativeMatches()).containsKey("a");
assertTrue(report.getExclusions().contains("com.foo.Bar")); assertThat(report.getExclusions()).contains("com.foo.Bar");
} }
@Configuration @Configuration
......
...@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link BeansEndpoint}. * Tests for {@link BeansEndpoint}.
...@@ -42,8 +41,8 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> { ...@@ -42,8 +41,8 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
List<Object> result = getEndpointBean().invoke(); List<Object> result = getEndpointBean().invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
assertTrue(result.get(0) instanceof Map); assertThat(result.get(0)).isInstanceOf(Map.class);
} }
@Configuration @Configuration
...@@ -56,4 +55,5 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> { ...@@ -56,4 +55,5 @@ public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
} }
} }
} }
...@@ -29,8 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -29,8 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used with bean methods. * Tests for {@link ConfigurationPropertiesReportEndpoint} when used with bean methods.
...@@ -65,9 +64,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests { ...@@ -65,9 +64,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("other"); .get("other");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("other", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("other");
assertNotNull(nestedProperties.get("properties")); assertThat(nestedProperties.get("properties")).isNotNull();
} }
@Test @Test
...@@ -81,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests { ...@@ -81,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("bar"); .get("bar");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("other", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("other");
assertNotNull(nestedProperties.get("properties")); assertThat(nestedProperties.get("properties")).isNotNull();
} }
@Configuration @Configuration
......
...@@ -28,8 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -28,8 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used with a parent * Tests for {@link ConfigurationPropertiesReportEndpoint} when used with a parent
...@@ -63,8 +62,8 @@ public class ConfigurationPropertiesReportEndpointParentTests { ...@@ -63,8 +62,8 @@ public class ConfigurationPropertiesReportEndpointParentTests {
ConfigurationPropertiesReportEndpoint endpoint = this.context ConfigurationPropertiesReportEndpoint endpoint = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class); .getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> result = endpoint.invoke(); Map<String, Object> result = endpoint.invoke();
assertTrue(result.containsKey("parent")); assertThat(result).containsKey("parent");
assertEquals(3, result.size()); // the endpoint, the test props and the parent assertThat(result).hasSize(3); // the endpoint, the test props and the parent
// System.err.println(result); // System.err.println(result);
} }
...@@ -80,8 +79,8 @@ public class ConfigurationPropertiesReportEndpointParentTests { ...@@ -80,8 +79,8 @@ public class ConfigurationPropertiesReportEndpointParentTests {
ConfigurationPropertiesReportEndpoint endpoint = this.context ConfigurationPropertiesReportEndpoint endpoint = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class); .getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> result = endpoint.invoke(); Map<String, Object> result = endpoint.invoke();
assertTrue(result.containsKey("parent")); assertThat(result.containsKey("parent")).isTrue();
assertEquals(3, result.size()); // the endpoint, the test props and the parent assertThat(result).hasSize(3); // the endpoint, the test props and the parent
// System.err.println(result); // System.err.println(result);
} }
......
...@@ -38,8 +38,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -38,8 +38,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used against a proxy * Tests for {@link ConfigurationPropertiesReportEndpoint} when used against a proxy
...@@ -69,7 +68,7 @@ public class ConfigurationPropertiesReportEndpointProxyTests { ...@@ -69,7 +68,7 @@ public class ConfigurationPropertiesReportEndpointProxyTests {
this.context.refresh(); this.context.refresh();
Map<String, Object> report = this.context Map<String, Object> report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class).invoke(); .getBean(ConfigurationPropertiesReportEndpoint.class).invoke();
assertThat(report.toString(), containsString("prefix=executor.sql")); assertThat(report.toString()).contains("prefix=executor.sql");
} }
@Configuration @Configuration
......
...@@ -32,8 +32,7 @@ import org.springframework.context.annotation.Bean; ...@@ -32,8 +32,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint} serialization. * Tests for {@link ConfigurationPropertiesReportEndpoint} serialization.
...@@ -67,13 +66,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -67,13 +66,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(2, map.size()); assertThat(map).hasSize(2);
assertEquals("foo", map.get("name")); assertThat(map.get("name")).isEqualTo("foo");
} }
@Test @Test
...@@ -87,12 +86,12 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -87,12 +86,12 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(2, map.size()); assertThat(map).hasSize(2);
assertEquals("foo", ((Map<String, Object>) map.get("bar")).get("name")); assertThat(((Map<String, Object>) map.get("bar")).get("name")).isEqualTo("foo");
} }
@Test @Test
...@@ -106,13 +105,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -106,13 +105,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(1, map.size()); assertThat(map).hasSize(1);
assertEquals("Cannot serialize 'foo'", map.get("error")); assertThat(map.get("error")).isEqualTo("Cannot serialize 'foo'");
} }
@Test @Test
...@@ -126,13 +125,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -126,13 +125,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(3, map.size()); assertThat(map).hasSize(3);
assertEquals("foo", ((Map<String, Object>) map.get("map")).get("name")); assertThat(((Map<String, Object>) map.get("map")).get("name")).isEqualTo("foo");
} }
@Test @Test
...@@ -145,14 +144,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -145,14 +144,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
System.err.println(nestedProperties); System.err.println(nestedProperties);
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(3, map.size()); assertThat(map).hasSize(3);
assertEquals(null, (map.get("map"))); assertThat((map.get("map"))).isNull();
} }
@Test @Test
...@@ -166,13 +165,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -166,13 +165,13 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(3, map.size()); assertThat(map).hasSize(3);
assertEquals("foo", ((List<String>) map.get("list")).get(0)); assertThat(((List<String>) map.get("list")).get(0)).isEqualTo("foo");
} }
@Test @Test
...@@ -186,14 +185,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { ...@@ -186,14 +185,14 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo"); .get("foo");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
System.err.println(nestedProperties); System.err.println(nestedProperties);
assertEquals("foo", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("foo");
Map<String, Object> map = (Map<String, Object>) nestedProperties Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertNotNull(map); assertThat(map).isNotNull();
assertEquals(3, map.size()); assertThat(map).hasSize(3);
assertEquals("192.168.1.10", map.get("address")); assertThat(map.get("address")).isEqualTo("192.168.1.10");
} }
@Configuration @Configuration
......
...@@ -28,11 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -28,11 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ConfigurationPropertiesReportEndpoint}. * Tests for {@link ConfigurationPropertiesReportEndpoint}.
...@@ -49,7 +45,7 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -49,7 +45,7 @@ public class ConfigurationPropertiesReportEndpointTests
@Test @Test
public void testInvoke() throws Exception { public void testInvoke() throws Exception {
assertThat(getEndpointBean().invoke().size(), greaterThan(0)); assertThat(getEndpointBean().invoke().size()).isGreaterThan(0);
} }
@Test @Test
...@@ -59,9 +55,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -59,9 +55,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("testProperties"); .get("testProperties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("test", nestedProperties.get("prefix")); assertThat(nestedProperties.get("prefix")).isEqualTo("test");
assertNotNull(nestedProperties.get("properties")); assertThat(nestedProperties.get("properties")).isNotNull();
} }
@Test @Test
...@@ -71,9 +67,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -71,9 +67,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("******", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("******");
assertEquals("654321", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321");
} }
@Test @Test
...@@ -84,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -84,9 +80,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("123456", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("123456");
assertEquals("******", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -97,9 +93,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -97,9 +93,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("******", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("******");
assertEquals("654321", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -114,9 +110,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -114,9 +110,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("123456", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("123456");
assertEquals("******", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -131,9 +127,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -131,9 +127,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("******", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("******");
assertEquals("654321", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("654321");
} }
@Test @Test
...@@ -149,9 +145,9 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -149,9 +145,9 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
assertEquals("******", nestedProperties.get("dbPassword")); assertThat(nestedProperties.get("dbPassword")).isEqualTo("******");
assertEquals("******", nestedProperties.get("myTestProperty")); assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******");
} }
@Test @Test
...@@ -168,13 +164,13 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -168,13 +164,13 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertNotNull(nestedProperties); assertThat(nestedProperties).isNotNull();
Map<String, Object> secrets = (Map<String, Object>) nestedProperties Map<String, Object> secrets = (Map<String, Object>) nestedProperties
.get("secrets"); .get("secrets");
Map<String, Object> hidden = (Map<String, Object>) nestedProperties.get("hidden"); Map<String, Object> hidden = (Map<String, Object>) nestedProperties.get("hidden");
assertEquals("******", secrets.get("mine")); assertThat(secrets.get("mine")).isEqualTo("******");
assertEquals("******", secrets.get("yours")); assertThat(secrets.get("yours")).isEqualTo("******");
assertEquals("******", hidden.get("mine")); assertThat(hidden.get("mine")).isEqualTo("******");
} }
@Test @Test
...@@ -184,7 +180,7 @@ public class ConfigurationPropertiesReportEndpointTests ...@@ -184,7 +180,7 @@ public class ConfigurationPropertiesReportEndpointTests
Map<String, Object> properties = report.invoke(); Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties"); .get("testProperties")).get("properties");
assertThat(nestedProperties.get("mixedBoolean"), equalTo((Object) true)); assertThat(nestedProperties.get("mixedBoolean")).isEqualTo(true);
} }
@Configuration @Configuration
......
...@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -25,8 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.greaterThan; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link DumpEndpoint}. * Tests for {@link DumpEndpoint}.
...@@ -42,7 +41,7 @@ public class DumpEndpointTests extends AbstractEndpointTests<DumpEndpoint> { ...@@ -42,7 +41,7 @@ public class DumpEndpointTests extends AbstractEndpointTests<DumpEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
List<ThreadInfo> threadInfo = getEndpointBean().invoke(); List<ThreadInfo> threadInfo = getEndpointBean().invoke();
assertThat(threadInfo.size(), greaterThan(0)); assertThat(threadInfo.size()).isGreaterThan(0);
} }
@Configuration @Configuration
......
...@@ -29,9 +29,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -29,9 +29,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import static org.hamcrest.Matchers.greaterThan; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link EnvironmentEndpoint}. * Tests for {@link EnvironmentEndpoint}.
...@@ -49,7 +47,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -49,7 +47,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
assertThat(getEndpointBean().invoke().size(), greaterThan(0)); assertThat(getEndpointBean().invoke()).isNotEmpty();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -63,7 +61,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -63,7 +61,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
Collections.singletonMap("foo", (Object) "spam"))); Collections.singletonMap("foo", (Object) "spam")));
this.context.getEnvironment().getPropertySources().addFirst(source); this.context.getEnvironment().getPropertySources().addFirst(source);
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("bar", ((Map<String, Object>) env.get("composite:one")).get("foo")); assertThat(((Map<String, Object>) env.get("composite:one")).get("foo"))
.isEqualTo("bar");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -76,16 +75,13 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -76,16 +75,13 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System.setProperty("VCAP_SERVICES", "123456"); System.setProperty("VCAP_SERVICES", "123456");
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("******", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("******", assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("******");
assertEquals("******", assertThat(systemProperties.get("mySecret")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("mySecret")); assertThat(systemProperties.get("myCredentials")).isEqualTo("******");
assertEquals("******", assertThat(systemProperties.get("VCAP_SERVICES")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("myCredentials"));
assertEquals("******",
((Map<String, Object>) env.get("systemProperties")).get("VCAP_SERVICES"));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -97,14 +93,14 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -97,14 +93,14 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System.setProperty("foo.mycredentials.uri", "123456"); System.setProperty("foo.mycredentials.uri", "123456");
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("******", ((Map<String, Object>) env.get("systemProperties")) Map<String, Object> systemProperties = (Map<String, Object>) env
.get("my.services.amqp-free.credentials.uri")); .get("systemProperties");
assertEquals("******", ((Map<String, Object>) env.get("systemProperties")) assertThat(systemProperties.get("my.services.amqp-free.credentials.uri"))
.get("credentials.http_api_uri")); .isEqualTo("******");
assertEquals("******", ((Map<String, Object>) env.get("systemProperties")) assertThat(systemProperties.get("credentials.http_api_uri")).isEqualTo("******");
.get("my.services.cleardb-free.credentials")); assertThat(systemProperties.get("my.services.cleardb-free.credentials"))
assertEquals("******", ((Map<String, Object>) env.get("systemProperties")) .isEqualTo("******");
.get("foo.mycredentials.uri")); assertThat(systemProperties.get("foo.mycredentials.uri")).isEqualTo("******");
} }
...@@ -116,10 +112,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -116,10 +112,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
report.setKeysToSanitize("key"); report.setKeysToSanitize("key");
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("123456", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("******", assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("******");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -130,10 +126,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -130,10 +126,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
report.setKeysToSanitize(".*pass.*"); report.setKeysToSanitize(".*pass.*");
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("******", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("123456", assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -148,10 +144,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -148,10 +144,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System.setProperty("apiKey", "123456"); System.setProperty("apiKey", "123456");
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("123456", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("******", assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("******");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -166,10 +162,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -166,10 +162,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System.setProperty("apiKey", "123456"); System.setProperty("apiKey", "123456");
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("******", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("123456", assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -185,10 +181,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE ...@@ -185,10 +181,10 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
System.setProperty("apiKey", "123456"); System.setProperty("apiKey", "123456");
EnvironmentEndpoint report = getEndpointBean(); EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke(); Map<String, Object> env = report.invoke();
assertEquals("******", Map<String, Object> systemProperties = (Map<String, Object>) env
((Map<String, Object>) env.get("systemProperties")).get("dbPassword")); .get("systemProperties");
assertEquals("******", assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
((Map<String, Object>) env.get("systemProperties")).get("apiKey")); assertThat(systemProperties.get("apiKey")).isEqualTo("******");
} }
@Configuration @Configuration
......
...@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean; ...@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import static org.hamcrest.Matchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link FlywayEndpoint}. * Tests for {@link FlywayEndpoint}.
...@@ -42,7 +41,7 @@ public class FlywayEndpointTests extends AbstractEndpointTests<FlywayEndpoint> { ...@@ -42,7 +41,7 @@ public class FlywayEndpointTests extends AbstractEndpointTests<FlywayEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
assertThat(getEndpointBean().invoke().size(), is(1)); assertThat(getEndpointBean().invoke()).hasSize(1);
} }
@Configuration @Configuration
......
...@@ -29,8 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -29,8 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link HealthEndpoint}. * Tests for {@link HealthEndpoint}.
...@@ -47,7 +46,7 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> { ...@@ -47,7 +46,7 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
// As FINE isn't configured in the order we get UNKNOWN // 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 @Configuration
......
...@@ -24,8 +24,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -24,8 +24,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link InfoEndpoint}. * Tests for {@link InfoEndpoint}.
...@@ -41,7 +40,7 @@ public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> { ...@@ -41,7 +40,7 @@ public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) "b")); assertThat(getEndpointBean().invoke().get("a")).isEqualTo("b");
} }
@Configuration @Configuration
......
...@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean; ...@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import static org.hamcrest.Matchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link LiquibaseEndpoint}. * Tests for {@link LiquibaseEndpoint}.
...@@ -43,7 +42,7 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo ...@@ -43,7 +42,7 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
assertThat(getEndpointBean().invoke().size(), is(1)); assertThat(getEndpointBean().invoke()).hasSize(1);
} }
@Configuration @Configuration
......
...@@ -24,7 +24,7 @@ import org.junit.Test; ...@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.reader.MetricReader; import org.springframework.boot.actuate.metrics.reader.MetricReader;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -43,7 +43,7 @@ public class MetricReaderPublicMetricsTests { ...@@ -43,7 +43,7 @@ public class MetricReaderPublicMetricsTests {
MetricReader reader = mock(MetricReader.class); MetricReader reader = mock(MetricReader.class);
given(reader.findAll()).willReturn(metrics); given(reader.findAll()).willReturn(metrics);
MetricReaderPublicMetrics publicMetrics = new MetricReaderPublicMetrics(reader); MetricReaderPublicMetrics publicMetrics = new MetricReaderPublicMetrics(reader);
assertEquals(metrics, publicMetrics.metrics()); assertThat(publicMetrics.metrics()).isEqualTo(metrics);
} }
} }
...@@ -33,10 +33,7 @@ import org.springframework.context.annotation.Bean; ...@@ -33,10 +33,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link MetricsEndpoint}. * Tests for {@link MetricsEndpoint}.
...@@ -57,7 +54,7 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint> ...@@ -57,7 +54,7 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) 0.5f)); assertThat(getEndpointBean().invoke().get("a")).isEqualTo(0.5f);
} }
@Test @Test
...@@ -68,10 +65,10 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint> ...@@ -68,10 +65,10 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
publicMetrics.add(new TestPublicMetrics(1, this.metric1)); publicMetrics.add(new TestPublicMetrics(1, this.metric1));
Map<String, Object> metrics = new MetricsEndpoint(publicMetrics).invoke(); Map<String, Object> metrics = new MetricsEndpoint(publicMetrics).invoke();
Iterator<Entry<String, Object>> iterator = metrics.entrySet().iterator(); Iterator<Entry<String, Object>> iterator = metrics.entrySet().iterator();
assertEquals("a", iterator.next().getKey()); assertThat(iterator.next().getKey()).isEqualTo("a");
assertEquals("b", iterator.next().getKey()); assertThat(iterator.next().getKey()).isEqualTo("b");
assertEquals("c", iterator.next().getKey()); assertThat(iterator.next().getKey()).isEqualTo("c");
assertFalse(iterator.hasNext()); assertThat(iterator.hasNext()).isFalse();
} }
private static class TestPublicMetrics implements PublicMetrics, Ordered { private static class TestPublicMetrics implements PublicMetrics, Ordered {
......
...@@ -35,8 +35,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping; ...@@ -35,8 +35,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping; import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link RequestMappingEndpoint}. * Tests for {@link RequestMappingEndpoint}.
...@@ -56,10 +55,10 @@ public class RequestMappingEndpointTests { ...@@ -56,10 +55,10 @@ public class RequestMappingEndpointTests {
this.endpoint.setHandlerMappings( this.endpoint.setHandlerMappings(
Collections.<AbstractUrlHandlerMapping>singletonList(mapping)); Collections.<AbstractUrlHandlerMapping>singletonList(mapping));
Map<String, Object> result = this.endpoint.invoke(); Map<String, Object> result = this.endpoint.invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) result.get("/foo"); Map<String, Object> map = (Map<String, Object>) result.get("/foo");
assertEquals("java.lang.Object", map.get("type")); assertThat(map.get("type")).isEqualTo("java.lang.Object");
} }
@Test @Test
...@@ -72,10 +71,10 @@ public class RequestMappingEndpointTests { ...@@ -72,10 +71,10 @@ public class RequestMappingEndpointTests {
context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
this.endpoint.setApplicationContext(context); this.endpoint.setApplicationContext(context);
Map<String, Object> result = this.endpoint.invoke(); Map<String, Object> result = this.endpoint.invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) result.get("/foo"); Map<String, Object> map = (Map<String, Object>) result.get("/foo");
assertEquals("mapping", map.get("bean")); assertThat(map.get("bean")).isEqualTo("mapping");
} }
@Test @Test
...@@ -84,10 +83,10 @@ public class RequestMappingEndpointTests { ...@@ -84,10 +83,10 @@ public class RequestMappingEndpointTests {
MappingConfiguration.class); MappingConfiguration.class);
this.endpoint.setApplicationContext(context); this.endpoint.setApplicationContext(context);
Map<String, Object> result = this.endpoint.invoke(); Map<String, Object> result = this.endpoint.invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) result.get("/foo"); Map<String, Object> map = (Map<String, Object>) result.get("/foo");
assertEquals("scopedTarget.mapping", map.get("bean")); assertThat(map.get("bean")).isEqualTo("scopedTarget.mapping");
} }
@Test @Test
...@@ -100,12 +99,12 @@ public class RequestMappingEndpointTests { ...@@ -100,12 +99,12 @@ public class RequestMappingEndpointTests {
context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
this.endpoint.setApplicationContext(context); this.endpoint.setApplicationContext(context);
Map<String, Object> result = this.endpoint.invoke(); Map<String, Object> result = this.endpoint.invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
assertTrue(result.keySet().iterator().next().contains("/dump")); assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> handler = (Map<String, Object>) result.values().iterator() Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
.next(); .next();
assertTrue(handler.containsKey("method")); assertThat(handler.containsKey("method")).isTrue();
} }
@Test @Test
...@@ -117,12 +116,12 @@ public class RequestMappingEndpointTests { ...@@ -117,12 +116,12 @@ public class RequestMappingEndpointTests {
this.endpoint.setMethodMappings( this.endpoint.setMethodMappings(
Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping)); Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping));
Map<String, Object> result = this.endpoint.invoke(); Map<String, Object> result = this.endpoint.invoke();
assertEquals(1, result.size()); assertThat(result).hasSize(1);
assertTrue(result.keySet().iterator().next().contains("/dump")); assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> handler = (Map<String, Object>) result.values().iterator() Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
.next(); .next();
assertTrue(handler.containsKey("method")); assertThat(handler.containsKey("method")).isTrue();
} }
@Configuration @Configuration
......
...@@ -25,9 +25,7 @@ import org.junit.Test; ...@@ -25,9 +25,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository; import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link RichGaugeReaderPublicMetrics}. * Tests for {@link RichGaugeReaderPublicMetrics}.
...@@ -50,23 +48,23 @@ public class RichGaugeReaderPublicMetricsTests { ...@@ -50,23 +48,23 @@ public class RichGaugeReaderPublicMetricsTests {
for (Metric<?> metric : metrics.metrics()) { for (Metric<?> metric : metrics.metrics()) {
results.put(metric.getName(), metric); results.put(metric.getName(), metric);
} }
assertTrue(results.containsKey("a.val")); assertThat(results.containsKey("a.val")).isTrue();
assertThat(results.get("a.val").getValue().doubleValue(), equalTo(0.5d)); assertThat(results.get("a.val").getValue().doubleValue()).isEqualTo(0.5d);
assertTrue(results.containsKey("a.avg")); assertThat(results.containsKey("a.avg")).isTrue();
assertThat(results.get("a.avg").getValue().doubleValue(), equalTo(0.25d)); assertThat(results.get("a.avg").getValue().doubleValue()).isEqualTo(0.25d);
assertTrue(results.containsKey("a.min")); assertThat(results.containsKey("a.min")).isTrue();
assertThat(results.get("a.min").getValue().doubleValue(), equalTo(0.0d)); assertThat(results.get("a.min").getValue().doubleValue()).isEqualTo(0.0d);
assertTrue(results.containsKey("a.max")); assertThat(results.containsKey("a.max")).isTrue();
assertThat(results.get("a.max").getValue().doubleValue(), equalTo(0.5d)); assertThat(results.get("a.max").getValue().doubleValue()).isEqualTo(0.5d);
assertTrue(results.containsKey("a.count")); assertThat(results.containsKey("a.count")).isTrue();
assertThat(results.get("a.count").getValue().longValue(), equalTo(2L)); assertThat(results.get("a.count").getValue().longValue()).isEqualTo(2L);
assertTrue(results.containsKey("a.alpha")); assertThat(results.containsKey("a.alpha")).isTrue();
assertThat(results.get("a.alpha").getValue().doubleValue(), equalTo(-1.d)); assertThat(results.get("a.alpha").getValue().doubleValue()).isEqualTo(-1.d);
} }
} }
...@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.endpoint; ...@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.endpoint;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link Sanitizer}. * Tests for {@link Sanitizer}.
...@@ -27,23 +27,22 @@ import static org.junit.Assert.assertEquals; ...@@ -27,23 +27,22 @@ import static org.junit.Assert.assertEquals;
*/ */
public class SanitizerTests { public class SanitizerTests {
private Sanitizer sanitizer = new Sanitizer();
@Test @Test
public void defaults() throws Exception { public void defaults() throws Exception {
assertEquals(this.sanitizer.sanitize("password", "secret"), "******"); Sanitizer sanitizer = new Sanitizer();
assertEquals(this.sanitizer.sanitize("my-password", "secret"), "******"); assertThat(sanitizer.sanitize("password", "secret")).isEqualTo("******");
assertEquals(this.sanitizer.sanitize("my-OTHER.paSSword", "secret"), "******"); assertThat(sanitizer.sanitize("my-password", "secret")).isEqualTo("******");
assertEquals(this.sanitizer.sanitize("somesecret", "secret"), "******"); assertThat(sanitizer.sanitize("my-OTHER.paSSword", "secret")).isEqualTo("******");
assertEquals(this.sanitizer.sanitize("somekey", "secret"), "******"); assertThat(sanitizer.sanitize("somesecret", "secret")).isEqualTo("******");
assertEquals(this.sanitizer.sanitize("find", "secret"), "secret"); assertThat(sanitizer.sanitize("somekey", "secret")).isEqualTo("******");
assertThat(sanitizer.sanitize("find", "secret")).isEqualTo("secret");
} }
@Test @Test
public void regex() throws Exception { public void regex() throws Exception {
this.sanitizer.setKeysToSanitize(".*lock.*"); Sanitizer sanitizer = new Sanitizer(".*lock.*");
assertEquals(this.sanitizer.sanitize("verylOCkish", "secret"), "******"); assertThat(sanitizer.sanitize("verylOCkish", "secret")).isEqualTo("******");
assertEquals(this.sanitizer.sanitize("veryokish", "secret"), "secret"); assertThat(sanitizer.sanitize("veryokish", "secret")).isEqualTo("secret");
} }
} }
...@@ -27,10 +27,7 @@ import org.springframework.context.annotation.Bean; ...@@ -27,10 +27,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link ShutdownEndpoint}. * Tests for {@link ShutdownEndpoint}.
...@@ -48,16 +45,16 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin ...@@ -48,16 +45,16 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
@Override @Override
public void isEnabledByDefault() throws Exception { public void isEnabledByDefault() throws Exception {
// Shutdown is dangerous so is disabled by default // Shutdown is dangerous so is disabled by default
assertThat(getEndpointBean().isEnabled(), equalTo(false)); assertThat(getEndpointBean().isEnabled()).isFalse();
} }
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
CountDownLatch latch = this.context.getBean(Config.class).latch; CountDownLatch latch = this.context.getBean(Config.class).latch;
assertThat((String) getEndpointBean().invoke().get("message"), assertThat((String) getEndpointBean().invoke().get("message"))
startsWith("Shutting down")); .startsWith("Shutting down");
assertTrue(this.context.isActive()); assertThat(this.context.isActive()).isTrue();
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
} }
@Configuration @Configuration
......
...@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Bean; ...@@ -31,9 +31,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import static org.hamcrest.Matchers.startsWith; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link ShutdownEndpoint}. * Tests for {@link ShutdownEndpoint}.
...@@ -54,10 +52,10 @@ public class ShutdownParentEndpointTests { ...@@ -54,10 +52,10 @@ public class ShutdownParentEndpointTests {
this.context = new SpringApplicationBuilder(Config.class).child(Empty.class) this.context = new SpringApplicationBuilder(Config.class).child(Empty.class)
.web(false).run(); .web(false).run();
CountDownLatch latch = this.context.getBean(Config.class).latch; CountDownLatch latch = this.context.getBean(Config.class).latch;
assertThat((String) getEndpointBean().invoke().get("message"), assertThat((String) getEndpointBean().invoke().get("message"))
startsWith("Shutting down")); .startsWith("Shutting down");
assertTrue(this.context.isActive()); assertThat(this.context.isActive()).isTrue();
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
} }
@Test @Test
...@@ -65,10 +63,10 @@ public class ShutdownParentEndpointTests { ...@@ -65,10 +63,10 @@ public class ShutdownParentEndpointTests {
this.context = new SpringApplicationBuilder(Empty.class).child(Config.class) this.context = new SpringApplicationBuilder(Empty.class).child(Config.class)
.web(false).run(); .web(false).run();
CountDownLatch latch = this.context.getBean(Config.class).latch; CountDownLatch latch = this.context.getBean(Config.class).latch;
assertThat((String) getEndpointBean().invoke().get("message"), assertThat((String) getEndpointBean().invoke().get("message"))
startsWith("Shutting down")); .startsWith("Shutting down");
assertTrue(this.context.isActive()); assertThat(this.context.isActive()).isTrue();
assertTrue(latch.await(10, TimeUnit.SECONDS)); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
} }
private ShutdownEndpoint getEndpointBean() { private ShutdownEndpoint getEndpointBean() {
......
...@@ -23,7 +23,7 @@ import org.junit.Test; ...@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SystemPublicMetrics} * Tests for {@link SystemPublicMetrics}
...@@ -39,30 +39,26 @@ public class SystemPublicMetricsTests { ...@@ -39,30 +39,26 @@ public class SystemPublicMetricsTests {
for (Metric<?> metric : publicMetrics.metrics()) { for (Metric<?> metric : publicMetrics.metrics()) {
results.put(metric.getName(), metric); results.put(metric.getName(), metric);
} }
assertTrue(results.containsKey("mem")); assertThat(results).containsKey("mem");
assertTrue(results.containsKey("mem.free")); assertThat(results).containsKey("mem.free");
assertTrue(results.containsKey("processors")); assertThat(results).containsKey("processors");
assertTrue(results.containsKey("uptime")); assertThat(results).containsKey("uptime");
assertTrue(results.containsKey("systemload.average")); assertThat(results).containsKey("systemload.average");
assertThat(results).containsKey("heap.committed");
assertTrue(results.containsKey("heap.committed")); assertThat(results).containsKey("heap.init");
assertTrue(results.containsKey("heap.init")); assertThat(results).containsKey("heap.used");
assertTrue(results.containsKey("heap.used")); assertThat(results).containsKey("heap");
assertTrue(results.containsKey("heap")); assertThat(results).containsKey("nonheap.committed");
assertThat(results).containsKey("nonheap.init");
assertTrue(results.containsKey("nonheap.committed")); assertThat(results).containsKey("nonheap.used");
assertTrue(results.containsKey("nonheap.init")); assertThat(results).containsKey("nonheap");
assertTrue(results.containsKey("nonheap.used")); assertThat(results).containsKey("threads.peak");
assertTrue(results.containsKey("nonheap")); assertThat(results).containsKey("threads.daemon");
assertThat(results).containsKey("threads.totalStarted");
assertTrue(results.containsKey("threads.peak")); assertThat(results).containsKey("threads");
assertTrue(results.containsKey("threads.daemon")); assertThat(results).containsKey("classes.loaded");
assertTrue(results.containsKey("threads.totalStarted")); assertThat(results).containsKey("classes.unloaded");
assertTrue(results.containsKey("threads")); assertThat(results).containsKey("classes");
assertTrue(results.containsKey("classes.loaded"));
assertTrue(results.containsKey("classes.unloaded"));
assertTrue(results.containsKey("classes"));
} }
} }
...@@ -27,8 +27,7 @@ import org.springframework.context.annotation.Bean; ...@@ -27,8 +27,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.SocketUtils; import org.springframework.util.SocketUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link TomcatPublicMetrics} * Tests for {@link TomcatPublicMetrics}
...@@ -46,9 +45,9 @@ public class TomcatPublicMetricsTests { ...@@ -46,9 +45,9 @@ public class TomcatPublicMetricsTests {
TomcatPublicMetrics tomcatMetrics = context TomcatPublicMetrics tomcatMetrics = context
.getBean(TomcatPublicMetrics.class); .getBean(TomcatPublicMetrics.class);
Iterator<Metric<?>> metrics = tomcatMetrics.metrics().iterator(); Iterator<Metric<?>> metrics = tomcatMetrics.metrics().iterator();
assertThat(metrics.next().getName(), equalTo("httpsessions.max")); assertThat(metrics.next().getName()).isEqualTo("httpsessions.max");
assertThat(metrics.next().getName(), equalTo("httpsessions.active")); assertThat(metrics.next().getName()).isEqualTo("httpsessions.active");
assertThat(metrics.hasNext(), equalTo(false)); assertThat(metrics.hasNext()).isFalse();
} }
finally { finally {
context.close(); context.close();
......
...@@ -27,8 +27,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -27,8 +27,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link TraceEndpoint}. * Tests for {@link TraceEndpoint}.
...@@ -44,7 +43,7 @@ public class TraceEndpointTests extends AbstractEndpointTests<TraceEndpoint> { ...@@ -44,7 +43,7 @@ public class TraceEndpointTests extends AbstractEndpointTests<TraceEndpoint> {
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
Trace trace = getEndpointBean().invoke().get(0); Trace trace = getEndpointBean().invoke().get(0);
assertThat(trace.getInfo().get("a"), equalTo((Object) "b")); assertThat(trace.getInfo().get("a")).isEqualTo("b");
} }
@Configuration @Configuration
......
...@@ -42,13 +42,7 @@ import org.springframework.jmx.export.MBeanExporter; ...@@ -42,13 +42,7 @@ import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.support.ObjectNameManager; import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import static org.hamcrest.Matchers.instanceOf; import static org.assertj.core.api.Assertions.assertThat;
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;
/** /**
* Tests for {@link EndpointMBeanExporter} * Tests for {@link EndpointMBeanExporter}
...@@ -78,9 +72,9 @@ public class EndpointMBeanExporterTests { ...@@ -78,9 +72,9 @@ public class EndpointMBeanExporterTests {
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
MBeanInfo mbeanInfo = mbeanExporter.getServer() MBeanInfo mbeanInfo = mbeanExporter.getServer()
.getMBeanInfo(getObjectName("endpoint1", this.context)); .getMBeanInfo(getObjectName("endpoint1", this.context));
assertNotNull(mbeanInfo); assertThat(mbeanInfo).isNotNull();
assertEquals(3, mbeanInfo.getOperations().length); assertThat(mbeanInfo.getOperations().length).isEqualTo(3);
assertEquals(3, mbeanInfo.getAttributes().length); assertThat(mbeanInfo.getAttributes().length).isEqualTo(3);
} }
@Test @Test
...@@ -94,8 +88,8 @@ public class EndpointMBeanExporterTests { ...@@ -94,8 +88,8 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class, null, mpv)); new RootBeanDefinition(TestEndpoint.class, null, mpv));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertFalse(mbeanExporter.getServer() assertThat(mbeanExporter.getServer()
.isRegistered(getObjectName("endpoint1", this.context))); .isRegistered(getObjectName("endpoint1", this.context))).isFalse();
} }
@Test @Test
...@@ -109,8 +103,8 @@ public class EndpointMBeanExporterTests { ...@@ -109,8 +103,8 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class, null, mpv)); new RootBeanDefinition(TestEndpoint.class, null, mpv));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertTrue(mbeanExporter.getServer() assertThat(mbeanExporter.getServer()
.isRegistered(getObjectName("endpoint1", this.context))); .isRegistered(getObjectName("endpoint1", this.context))).isTrue();
} }
@Test @Test
...@@ -124,10 +118,10 @@ public class EndpointMBeanExporterTests { ...@@ -124,10 +118,10 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class)); new RootBeanDefinition(TestEndpoint.class));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertNotNull(mbeanExporter.getServer() assertThat(mbeanExporter.getServer()
.getMBeanInfo(getObjectName("endpoint1", this.context))); .getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull();
assertNotNull(mbeanExporter.getServer() assertThat(mbeanExporter.getServer()
.getMBeanInfo(getObjectName("endpoint2", this.context))); .getMBeanInfo(getObjectName("endpoint2", this.context))).isNotNull();
} }
@Test @Test
...@@ -141,8 +135,9 @@ public class EndpointMBeanExporterTests { ...@@ -141,8 +135,9 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class)); new RootBeanDefinition(TestEndpoint.class));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertNotNull(mbeanExporter.getServer().getMBeanInfo( assertThat(mbeanExporter.getServer().getMBeanInfo(
getObjectName("test-domain", "endpoint1", false, this.context))); getObjectName("test-domain", "endpoint1", false, this.context)))
.isNotNull();
} }
@Test @Test
...@@ -158,8 +153,9 @@ public class EndpointMBeanExporterTests { ...@@ -158,8 +153,9 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class)); new RootBeanDefinition(TestEndpoint.class));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertNotNull(mbeanExporter.getServer().getMBeanInfo( assertThat(mbeanExporter.getServer().getMBeanInfo(
getObjectName("test-domain", "endpoint1", true, this.context))); getObjectName("test-domain", "endpoint1", true, this.context)))
.isNotNull();
} }
@Test @Test
...@@ -180,10 +176,9 @@ public class EndpointMBeanExporterTests { ...@@ -180,10 +176,9 @@ public class EndpointMBeanExporterTests {
new RootBeanDefinition(TestEndpoint.class)); new RootBeanDefinition(TestEndpoint.class));
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertNotNull(mbeanExporter.getServer() assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(
.getMBeanInfo(ObjectNameManager.getInstance( getObjectName("test-domain", "endpoint1", true, this.context).toString()
getObjectName("test-domain", "endpoint1", true, this.context) + ",key1=value1,key2=value2"))).isNotNull();
.toString() + ",key1=value1,key2=value2")));
} }
@Test @Test
...@@ -198,9 +193,8 @@ public class EndpointMBeanExporterTests { ...@@ -198,9 +193,8 @@ public class EndpointMBeanExporterTests {
parent.refresh(); parent.refresh();
this.context.refresh(); this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class); MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertNotNull(mbeanExporter.getServer() assertThat(mbeanExporter.getServer()
.getMBeanInfo(getObjectName("endpoint1", this.context))); .getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull();
parent.close(); parent.close();
} }
...@@ -216,8 +210,8 @@ public class EndpointMBeanExporterTests { ...@@ -216,8 +210,8 @@ public class EndpointMBeanExporterTests {
Object response = mbeanExporter.getServer().invoke( Object response = mbeanExporter.getServer().invoke(
getObjectName("endpoint1", this.context), "getData", new Object[0], getObjectName("endpoint1", this.context), "getData", new Object[0],
new String[0]); new String[0]);
assertThat(response, is(instanceOf(Map.class))); assertThat(response).isInstanceOf(Map.class);
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(Long.class))); assertThat(((Map<?, ?>) response).get("date")).isInstanceOf(Long.class);
} }
@Test @Test
...@@ -237,8 +231,8 @@ public class EndpointMBeanExporterTests { ...@@ -237,8 +231,8 @@ public class EndpointMBeanExporterTests {
Object response = mbeanExporter.getServer().invoke( Object response = mbeanExporter.getServer().invoke(
getObjectName("endpoint1", this.context), "getData", new Object[0], getObjectName("endpoint1", this.context), "getData", new Object[0],
new String[0]); new String[0]);
assertThat(response, is(instanceOf(Map.class))); assertThat(response).isInstanceOf(Map.class);
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(String.class))); assertThat(((Map<?, ?>) response).get("date")).isInstanceOf(String.class);
} }
private ObjectName getObjectName(String beanKey, GenericApplicationContext context) private ObjectName getObjectName(String beanKey, GenericApplicationContext context)
......
...@@ -31,11 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -31,11 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link EndpointHandlerMapping}. * Tests for {@link EndpointHandlerMapping}.
...@@ -61,14 +57,11 @@ public class EndpointHandlerMappingTests { ...@@ -61,14 +57,11 @@ public class EndpointHandlerMappingTests {
Arrays.asList(endpointA, endpointB)); Arrays.asList(endpointA, endpointB));
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertThat( assertThat(mapping.getHandler(request("GET", "/a")).getHandler())
mapping.getHandler(new MockHttpServletRequest("GET", "/a")).getHandler(), .isEqualTo(new HandlerMethod(endpointA, this.method));
equalTo((Object) new HandlerMethod(endpointA, this.method))); assertThat(mapping.getHandler(request("GET", "/b")).getHandler())
assertThat( .isEqualTo(new HandlerMethod(endpointB, this.method));
mapping.getHandler(new MockHttpServletRequest("GET", "/b")).getHandler(), assertThat(mapping.getHandler(request("GET", "/c"))).isNull();
equalTo((Object) new HandlerMethod(endpointB, this.method)));
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/c")),
nullValue());
} }
@Test @Test
...@@ -80,16 +73,11 @@ public class EndpointHandlerMappingTests { ...@@ -80,16 +73,11 @@ public class EndpointHandlerMappingTests {
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.setPrefix("/a"); mapping.setPrefix("/a");
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertThat( assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/a"))
mapping.getHandler(new MockHttpServletRequest("GET", "/a/a")) .getHandler()).isEqualTo(new HandlerMethod(endpointA, this.method));
.getHandler(), assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/b"))
equalTo((Object) new HandlerMethod(endpointA, this.method))); .getHandler()).isEqualTo(new HandlerMethod(endpointB, this.method));
assertThat( assertThat(mapping.getHandler(request("GET", "/a"))).isNull();
mapping.getHandler(new MockHttpServletRequest("GET", "/a/b"))
.getHandler(),
equalTo((Object) new HandlerMethod(endpointB, this.method)));
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")),
nullValue());
} }
@Test(expected = HttpRequestMethodNotSupportedException.class) @Test(expected = HttpRequestMethodNotSupportedException.class)
...@@ -99,8 +87,8 @@ public class EndpointHandlerMappingTests { ...@@ -99,8 +87,8 @@ public class EndpointHandlerMappingTests {
Arrays.asList(endpoint)); Arrays.asList(endpoint));
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertNotNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a"))); assertThat(mapping.getHandler(request("GET", "/a"))).isNotNull();
assertNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); assertThat(mapping.getHandler(request("POST", "/a"))).isNull();
} }
@Test @Test
...@@ -110,7 +98,7 @@ public class EndpointHandlerMappingTests { ...@@ -110,7 +98,7 @@ public class EndpointHandlerMappingTests {
Arrays.asList(endpoint)); Arrays.asList(endpoint));
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertNotNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); assertThat(mapping.getHandler(request("POST", "/a"))).isNotNull();
} }
@Test(expected = HttpRequestMethodNotSupportedException.class) @Test(expected = HttpRequestMethodNotSupportedException.class)
...@@ -120,8 +108,8 @@ public class EndpointHandlerMappingTests { ...@@ -120,8 +108,8 @@ public class EndpointHandlerMappingTests {
Arrays.asList(endpoint)); Arrays.asList(endpoint));
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertNotNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a"))); assertThat(mapping.getHandler(request("POST", "/a"))).isNotNull();
assertNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a"))); assertThat(mapping.getHandler(request("GET", "/a"))).isNull();
} }
@Test @Test
...@@ -132,8 +120,7 @@ public class EndpointHandlerMappingTests { ...@@ -132,8 +120,7 @@ public class EndpointHandlerMappingTests {
mapping.setDisabled(true); mapping.setDisabled(true);
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")), assertThat(mapping.getHandler(request("GET", "/a"))).isNull();
nullValue());
} }
@Test @Test
...@@ -145,10 +132,12 @@ public class EndpointHandlerMappingTests { ...@@ -145,10 +132,12 @@ public class EndpointHandlerMappingTests {
mapping.setDisabled(true); mapping.setDisabled(true);
mapping.setApplicationContext(this.context); mapping.setApplicationContext(this.context);
mapping.afterPropertiesSet(); mapping.afterPropertiesSet();
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")), assertThat(mapping.getHandler(request("GET", "/a"))).isNull();
nullValue()); assertThat(mapping.getHandler(request("POST", "/a"))).isNull();
assertThat(mapping.getHandler(new MockHttpServletRequest("POST", "/a")), }
nullValue());
private MockHttpServletRequest request(String method, String requestURI) {
return new MockHttpServletRequest(method, requestURI);
} }
private static class TestEndpoint extends AbstractEndpoint<Object> { private static class TestEndpoint extends AbstractEndpoint<Object> {
......
...@@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult; ...@@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -68,7 +68,8 @@ public class HalBrowserMvcEndpointBrowserPathIntegrationTests { ...@@ -68,7 +68,8 @@ public class HalBrowserMvcEndpointBrowserPathIntegrationTests {
MvcResult response = this.mockMvc MvcResult response = this.mockMvc
.perform(get("/actuator/").accept(MediaType.TEXT_HTML)) .perform(get("/actuator/").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk()).andReturn(); .andExpect(status().isOk()).andReturn();
assertEquals("/actuator/browser.html", response.getResponse().getForwardedUrl()); assertThat(response.getResponse().getForwardedUrl())
.isEqualTo("/actuator/browser.html");
} }
@Test @Test
......
...@@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult; ...@@ -35,7 +35,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
...@@ -78,7 +78,8 @@ public class HalBrowserMvcEndpointDisabledIntegrationTests { ...@@ -78,7 +78,8 @@ public class HalBrowserMvcEndpointDisabledIntegrationTests {
MvcResult response = this.mockMvc MvcResult response = this.mockMvc
.perform(get("/actuator/").accept(MediaType.TEXT_HTML)) .perform(get("/actuator/").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk()).andReturn(); .andExpect(status().isOk()).andReturn();
assertEquals("/actuator/browser.html", response.getResponse().getForwardedUrl()); assertThat(response.getResponse().getForwardedUrl())
.isEqualTo("/actuator/browser.html");
} }
@Test @Test
......
...@@ -34,8 +34,7 @@ import org.springframework.test.web.servlet.MockMvc; ...@@ -34,8 +34,7 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.hamcrest.Matchers.empty; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -91,7 +90,7 @@ public class HalBrowserMvcEndpointEndpointsDisabledIntegrationTests { ...@@ -91,7 +90,7 @@ public class HalBrowserMvcEndpointEndpointsDisabledIntegrationTests {
@Test @Test
public void endpointsAllDisabled() throws Exception { public void endpointsAllDisabled() throws Exception {
assertThat(this.mvcEndpoints.getEndpoints(), empty()); assertThat(this.mvcEndpoints.getEndpoints()).isEmpty();
} }
@MinimalActuatorHypermediaApplication @MinimalActuatorHypermediaApplication
......
...@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/** /**
...@@ -68,9 +67,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ...@@ -68,9 +67,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/", HttpMethod.GET, "http://localhost:" + this.port + "/spring/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"_links\":");
entity.getBody().contains("\"_links\":"));
} }
@Test @Test
...@@ -80,9 +78,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ...@@ -80,9 +78,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET, "http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("<title");
entity.getBody().contains("<title"));
} }
@Test @Test
...@@ -92,9 +89,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ...@@ -92,9 +89,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator", HttpMethod.GET, "http://localhost:" + this.port + "/spring/actuator", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"_links\":");
entity.getBody().contains("\"_links\":"));
} }
@Test @Test
...@@ -104,9 +100,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests { ...@@ -104,9 +100,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET, "http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"_links\":");
entity.getBody().contains("\"_links\":"));
} }
@MinimalActuatorHypermediaApplication @MinimalActuatorHypermediaApplication
......
...@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -40,8 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/** /**
...@@ -68,11 +67,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ...@@ -68,11 +67,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator", HttpMethod.GET, "http://localhost:" + this.port + "/actuator", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"_links\":");
entity.getBody().contains("\"_links\":")); assertThat(entity.getBody()).contains(":" + this.port);
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains(":" + this.port));
} }
@Test @Test
...@@ -82,11 +79,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ...@@ -82,11 +79,9 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator/", HttpMethod.GET, "http://localhost:" + this.port + "/actuator/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"_links\":");
entity.getBody().contains("\"_links\":")); assertThat(entity.getBody()).contains(":" + this.port);
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains(":" + this.port));
} }
@Test @Test
...@@ -96,9 +91,8 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests { ...@@ -96,9 +91,8 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator/", HttpMethod.GET, "http://localhost:" + this.port + "/actuator/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class); new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("<title");
entity.getBody().contains("<title"));
} }
@MinimalActuatorHypermediaApplication @MinimalActuatorHypermediaApplication
......
...@@ -39,7 +39,7 @@ import org.springframework.test.web.servlet.MvcResult; ...@@ -39,7 +39,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; 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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
...@@ -90,7 +90,8 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests { ...@@ -90,7 +90,8 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests {
MvcResult response = this.mockMvc MvcResult response = this.mockMvc
.perform(get("/actuator/").accept(MediaType.TEXT_HTML)) .perform(get("/actuator/").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk()).andReturn(); .andExpect(status().isOk()).andReturn();
assertEquals("/actuator/browser.html", response.getResponse().getForwardedUrl()); assertThat(response.getResponse().getForwardedUrl())
.isEqualTo("/actuator/browser.html");
} }
@Test @Test
......
...@@ -32,12 +32,7 @@ import org.springframework.mock.env.MockEnvironment; ...@@ -32,12 +32,7 @@ import org.springframework.mock.env.MockEnvironment;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.authority.AuthorityUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -81,8 +76,8 @@ public class HealthMvcEndpointTests { ...@@ -81,8 +76,8 @@ public class HealthMvcEndpointTests {
public void up() { public void up() {
given(this.endpoint.invoke()).willReturn(new Health.Builder().up().build()); given(this.endpoint.invoke()).willReturn(new Health.Builder().up().build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -90,10 +85,10 @@ public class HealthMvcEndpointTests { ...@@ -90,10 +85,10 @@ public class HealthMvcEndpointTests {
public void down() { public void down() {
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof ResponseEntity); assertThat(result instanceof ResponseEntity).isTrue();
ResponseEntity<Health> response = (ResponseEntity<Health>) result; ResponseEntity<Health> response = (ResponseEntity<Health>) result;
assertTrue(response.getBody().getStatus() == Status.DOWN); assertThat(response.getBody().getStatus() == Status.DOWN).isTrue();
assertEquals(HttpStatus.SERVICE_UNAVAILABLE, response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
} }
@Test @Test
...@@ -104,10 +99,10 @@ public class HealthMvcEndpointTests { ...@@ -104,10 +99,10 @@ public class HealthMvcEndpointTests {
this.mvc.setStatusMapping( this.mvc.setStatusMapping(
Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR)); Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR));
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof ResponseEntity); assertThat(result instanceof ResponseEntity).isTrue();
ResponseEntity<Health> response = (ResponseEntity<Health>) result; ResponseEntity<Health> response = (ResponseEntity<Health>) result;
assertTrue(response.getBody().getStatus().equals(new Status("OK"))); assertThat(response.getBody().getStatus().equals(new Status("OK"))).isTrue();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
} }
@Test @Test
...@@ -118,10 +113,10 @@ public class HealthMvcEndpointTests { ...@@ -118,10 +113,10 @@ public class HealthMvcEndpointTests {
this.mvc.setStatusMapping(Collections.singletonMap("out-of-service", this.mvc.setStatusMapping(Collections.singletonMap("out-of-service",
HttpStatus.INTERNAL_SERVER_ERROR)); HttpStatus.INTERNAL_SERVER_ERROR));
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof ResponseEntity); assertThat(result instanceof ResponseEntity).isTrue();
ResponseEntity<Health> response = (ResponseEntity<Health>) result; ResponseEntity<Health> response = (ResponseEntity<Health>) result;
assertTrue(response.getBody().getStatus().equals(Status.OUT_OF_SERVICE)); assertThat(response.getBody().getStatus().equals(Status.OUT_OF_SERVICE)).isTrue();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
} }
@Test @Test
...@@ -130,9 +125,9 @@ public class HealthMvcEndpointTests { ...@@ -130,9 +125,9 @@ public class HealthMvcEndpointTests {
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
given(this.endpoint.isSensitive()).willReturn(false); given(this.endpoint.isSensitive()).willReturn(false);
Object result = this.mvc.invoke(this.admin); Object result = this.mvc.invoke(this.admin);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertEquals("bar", ((Health) result).getDetails().get("foo")); assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar");
} }
@Test @Test
...@@ -140,9 +135,9 @@ public class HealthMvcEndpointTests { ...@@ -140,9 +135,9 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(this.user); Object result = this.mvc.invoke(this.user);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertNull(((Health) result).getDetails().get("foo")); assertThat(((Health) result).getDetails().get("foo")).isNull();
} }
@Test @Test
...@@ -152,19 +147,19 @@ public class HealthMvcEndpointTests { ...@@ -152,19 +147,19 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(this.admin); Object result = this.mvc.invoke(this.admin);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
Health health = (Health) result; Health health = (Health) result;
assertTrue(health.getStatus() == Status.UP); assertThat(health.getStatus() == Status.UP).isTrue();
assertThat(health.getDetails().size(), is(equalTo(1))); assertThat(health.getDetails()).hasSize(1);
assertThat(health.getDetails().get("foo"), is(equalTo((Object) "bar"))); assertThat(health.getDetails().get("foo")).isEqualTo("bar");
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
result = this.mvc.invoke(null); // insecure now result = this.mvc.invoke(null); // insecure now
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
health = (Health) result; health = (Health) result;
// so the result is cached // so the result is cached
assertTrue(health.getStatus() == Status.UP); assertThat(health.getStatus() == Status.UP).isTrue();
// but the details are hidden // but the details are hidden
assertThat(health.getDetails().size(), is(equalTo(0))); assertThat(health.getDetails()).isEmpty();
} }
@Test @Test
...@@ -174,9 +169,9 @@ public class HealthMvcEndpointTests { ...@@ -174,9 +169,9 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertEquals("bar", ((Health) result).getDetails().get("foo")); assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar");
} }
@Test @Test
...@@ -185,9 +180,9 @@ public class HealthMvcEndpointTests { ...@@ -185,9 +180,9 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertNull(((Health) result).getDetails().get("foo")); assertThat(((Health) result).getDetails().get("foo")).isNull();
} }
@Test @Test
...@@ -198,9 +193,9 @@ public class HealthMvcEndpointTests { ...@@ -198,9 +193,9 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertEquals("bar", ((Health) result).getDetails().get("foo")); assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar");
} }
@Test @Test
...@@ -209,13 +204,13 @@ public class HealthMvcEndpointTests { ...@@ -209,13 +204,13 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
result = this.mvc.invoke(null); result = this.mvc.invoke(null);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Health health = ((ResponseEntity<Health>) result).getBody(); Health health = ((ResponseEntity<Health>) result).getBody();
assertTrue(health.getStatus() == Status.DOWN); assertThat(health.getStatus() == Status.DOWN).isTrue();
} }
@Test @Test
...@@ -225,14 +220,14 @@ public class HealthMvcEndpointTests { ...@@ -225,14 +220,14 @@ public class HealthMvcEndpointTests {
given(this.endpoint.invoke()) given(this.endpoint.invoke())
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); .willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(null); Object result = this.mvc.invoke(null);
assertTrue(result instanceof Health); assertThat(result instanceof Health).isTrue();
assertTrue(((Health) result).getStatus() == Status.UP); assertThat(((Health) result).getStatus() == Status.UP).isTrue();
Thread.sleep(100); Thread.sleep(100);
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build()); given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
result = this.mvc.invoke(null); result = this.mvc.invoke(null);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Health health = ((ResponseEntity<Health>) result).getBody(); Health health = ((ResponseEntity<Health>) result).getBody();
assertTrue(health.getStatus() == Status.DOWN); assertThat(health.getStatus() == Status.DOWN).isTrue();
} }
} }
...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc; ...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc;
import java.util.Set; import java.util.Set;
import org.hamcrest.Matcher;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -43,10 +42,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; ...@@ -43,10 +42,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 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.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.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -78,10 +75,9 @@ public class JolokiaMvcEndpointTests { ...@@ -78,10 +75,9 @@ public class JolokiaMvcEndpointTests {
} }
@Test @Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void endpointRegistered() throws Exception { public void endpointRegistered() throws Exception {
Set<? extends MvcEndpoint> values = this.endpoints.getEndpoints(); Set<? extends MvcEndpoint> values = this.endpoints.getEndpoints();
assertThat(values, (Matcher) hasItem(instanceOf(JolokiaMvcEndpoint.class))); assertThat(values).hasAtLeastOneElementOfType(JolokiaMvcEndpoint.class);
} }
@Test @Test
......
...@@ -31,9 +31,7 @@ import org.springframework.mock.web.MockHttpServletRequest; ...@@ -31,9 +31,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link LogFileMvcEndpoint}. * Tests for {@link LogFileMvcEndpoint}.
...@@ -67,7 +65,7 @@ public class LogFileMvcEndpointTests { ...@@ -67,7 +65,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest request = new MockHttpServletRequest( MockHttpServletRequest request = new MockHttpServletRequest(
HttpMethod.HEAD.name(), "/logfile"); HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response); this.mvc.invoke(request, response);
assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
} }
@Test @Test
...@@ -77,7 +75,7 @@ public class LogFileMvcEndpointTests { ...@@ -77,7 +75,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest request = new MockHttpServletRequest( MockHttpServletRequest request = new MockHttpServletRequest(
HttpMethod.HEAD.name(), "/logfile"); HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response); this.mvc.invoke(request, response);
assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
} }
@Test @Test
...@@ -87,7 +85,7 @@ public class LogFileMvcEndpointTests { ...@@ -87,7 +85,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest request = new MockHttpServletRequest( MockHttpServletRequest request = new MockHttpServletRequest(
HttpMethod.HEAD.name(), "/logfile"); HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response); this.mvc.invoke(request, response);
assertThat(response.getStatus(), equalTo(HttpStatus.OK.value())); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
} }
@Test @Test
...@@ -98,7 +96,7 @@ public class LogFileMvcEndpointTests { ...@@ -98,7 +96,7 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest request = new MockHttpServletRequest( MockHttpServletRequest request = new MockHttpServletRequest(
HttpMethod.HEAD.name(), "/logfile"); HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response); this.mvc.invoke(request, response);
assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value())); assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
} }
@Test @Test
...@@ -108,8 +106,8 @@ public class LogFileMvcEndpointTests { ...@@ -108,8 +106,8 @@ public class LogFileMvcEndpointTests {
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(),
"/logfile"); "/logfile");
this.mvc.invoke(request, response); this.mvc.invoke(request, response);
assertThat(response.getStatus(), equalTo(HttpStatus.OK.value())); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertEquals("--TEST--", response.getContentAsString()); assertThat(response.getContentAsString()).isEqualTo("--TEST--");
} }
} }
...@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.endpoint.AbstractEndpoint; ...@@ -22,7 +22,7 @@ import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link MvcEndpoints}. * Tests for {@link MvcEndpoints}.
...@@ -41,7 +41,7 @@ public class MvcEndpointsTests { ...@@ -41,7 +41,7 @@ public class MvcEndpointsTests {
new TestEndpoint()); new TestEndpoint());
this.endpoints.setApplicationContext(this.context); this.endpoints.setApplicationContext(this.context);
this.endpoints.afterPropertiesSet(); this.endpoints.afterPropertiesSet();
assertEquals(1, this.endpoints.getEndpoints().size()); assertThat(this.endpoints.getEndpoints()).hasSize(1);
} }
@Test @Test
...@@ -52,7 +52,7 @@ public class MvcEndpointsTests { ...@@ -52,7 +52,7 @@ public class MvcEndpointsTests {
new TestEndpoint()); new TestEndpoint());
this.endpoints.setApplicationContext(this.context); this.endpoints.setApplicationContext(this.context);
this.endpoints.afterPropertiesSet(); this.endpoints.afterPropertiesSet();
assertEquals(1, this.endpoints.getEndpoints().size()); assertThat(this.endpoints.getEndpoints()).hasSize(1);
} }
@Test @Test
...@@ -61,7 +61,7 @@ public class MvcEndpointsTests { ...@@ -61,7 +61,7 @@ public class MvcEndpointsTests {
new EndpointMvcAdapter(new TestEndpoint())); new EndpointMvcAdapter(new TestEndpoint()));
this.endpoints.setApplicationContext(this.context); this.endpoints.setApplicationContext(this.context);
this.endpoints.afterPropertiesSet(); this.endpoints.afterPropertiesSet();
assertEquals(1, this.endpoints.getEndpoints().size()); assertThat(this.endpoints.getEndpoints()).hasSize(1);
} }
@Test @Test
...@@ -72,9 +72,9 @@ public class MvcEndpointsTests { ...@@ -72,9 +72,9 @@ public class MvcEndpointsTests {
new TestEndpoint()); new TestEndpoint());
this.endpoints.setApplicationContext(this.context); this.endpoints.setApplicationContext(this.context);
this.endpoints.afterPropertiesSet(); this.endpoints.afterPropertiesSet();
assertEquals(1, this.endpoints.getEndpoints().size()); assertThat(this.endpoints.getEndpoints()).hasSize(1);
assertEquals("/foo/bar", assertThat(this.endpoints.getEndpoints().iterator().next().getPath())
this.endpoints.getEndpoints().iterator().next().getPath()); .isEqualTo("/foo/bar");
} }
protected static class TestEndpoint extends AbstractEndpoint<String> { protected static class TestEndpoint extends AbstractEndpoint<String> {
......
...@@ -20,11 +20,7 @@ import java.util.Map; ...@@ -20,11 +20,7 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link NamePatternFilter}. * Tests for {@link NamePatternFilter}.
...@@ -37,54 +33,54 @@ public class NamePatternFilterTests { ...@@ -37,54 +33,54 @@ public class NamePatternFilterTests {
@Test @Test
public void nonRegex() throws Exception { public void nonRegex() throws Exception {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
assertThat(filter.getResults("not.a.regex"), assertThat(filter.getResults("not.a.regex")).containsEntry("not.a.regex",
hasEntry("not.a.regex", (Object) "not.a.regex")); "not.a.regex");
assertThat(filter.isGetNamesCalled(), equalTo(false)); assertThat(filter.isGetNamesCalled()).isFalse();
} }
@Test @Test
public void regexRepetitionZeroOrMore() { public void regexRepetitionZeroOrMore() {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
Map<String, Object> results = filter.getResults("fo.*"); Map<String, Object> results = filter.getResults("fo.*");
assertThat(results.get("foo"), equalTo((Object) "foo")); assertThat(results.get("foo")).isEqualTo("foo");
assertThat(results.get("fool"), equalTo((Object) "fool")); assertThat(results.get("fool")).isEqualTo("fool");
assertThat(filter.isGetNamesCalled(), equalTo(true)); assertThat(filter.isGetNamesCalled()).isTrue();
} }
@Test @Test
public void regexRepetitionOneOrMore() { public void regexRepetitionOneOrMore() {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
Map<String, Object> results = filter.getResults("fo.+"); Map<String, Object> results = filter.getResults("fo.+");
assertThat(results.get("foo"), equalTo((Object) "foo")); assertThat(results.get("foo")).isEqualTo("foo");
assertThat(results.get("fool"), equalTo((Object) "fool")); assertThat(results.get("fool")).isEqualTo("fool");
assertThat(filter.isGetNamesCalled(), equalTo(true)); assertThat(filter.isGetNamesCalled()).isTrue();
} }
@Test @Test
public void regexEndAnchor() { public void regexEndAnchor() {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
Map<String, Object> results = filter.getResults("foo$"); Map<String, Object> results = filter.getResults("foo$");
assertThat(results.get("foo"), equalTo((Object) "foo")); assertThat(results.get("foo")).isEqualTo("foo");
assertThat(results.get("fool"), is(nullValue())); assertThat(results.get("fool")).isNull();
assertThat(filter.isGetNamesCalled(), equalTo(true)); assertThat(filter.isGetNamesCalled()).isTrue();
} }
@Test @Test
public void regexStartAnchor() { public void regexStartAnchor() {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
Map<String, Object> results = filter.getResults("^foo"); Map<String, Object> results = filter.getResults("^foo");
assertThat(results.get("foo"), equalTo((Object) "foo")); assertThat(results.get("foo")).isEqualTo("foo");
assertThat(results.get("fool"), is(nullValue())); assertThat(results.get("fool")).isNull();
assertThat(filter.isGetNamesCalled(), equalTo(true)); assertThat(filter.isGetNamesCalled()).isTrue();
} }
@Test @Test
public void regexCharacterClass() { public void regexCharacterClass() {
MockNamePatternFilter filter = new MockNamePatternFilter(); MockNamePatternFilter filter = new MockNamePatternFilter();
Map<String, Object> results = filter.getResults("fo[a-z]l"); Map<String, Object> results = filter.getResults("fo[a-z]l");
assertThat(results.get("foo"), is(nullValue())); assertThat(results.get("foo")).isNull();
assertThat(results.get("fool"), equalTo((Object) "fool")); assertThat(results.get("fool")).isEqualTo("fool");
assertThat(filter.isGetNamesCalled(), equalTo(true)); assertThat(filter.isGetNamesCalled()).isTrue();
} }
private static class MockNamePatternFilter extends NamePatternFilter<Object> { private static class MockNamePatternFilter extends NamePatternFilter<Object> {
......
...@@ -24,7 +24,7 @@ import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; ...@@ -24,7 +24,7 @@ import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; 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; import static org.mockito.Mockito.mock;
/** /**
...@@ -43,7 +43,7 @@ public class ShutdownMvcEndpointTests { ...@@ -43,7 +43,7 @@ public class ShutdownMvcEndpointTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ResponseEntity<Map<String, String>> response = (ResponseEntity<Map<String, String>>) this.mvc ResponseEntity<Map<String, String>> response = (ResponseEntity<Map<String, String>>) this.mvc
.invoke(); .invoke();
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
} }
} }
...@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health; ...@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.health;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link ApplicationHealthIndicator}. * Tests for {@link ApplicationHealthIndicator}.
...@@ -30,7 +30,7 @@ public class ApplicationHealthIndicatorTests { ...@@ -30,7 +30,7 @@ public class ApplicationHealthIndicatorTests {
@Test @Test
public void indicatesUp() throws Exception { public void indicatesUp() throws Exception {
ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator(); ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator();
assertEquals(Status.UP, healthIndicator.health().getStatus()); assertThat(healthIndicator.health().getStatus()).isEqualTo(Status.UP);
} }
} }
...@@ -25,10 +25,7 @@ import org.junit.Test; ...@@ -25,10 +25,7 @@ import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
/** /**
...@@ -72,11 +69,11 @@ public class CompositeHealthIndicatorTests { ...@@ -72,11 +69,11 @@ public class CompositeHealthIndicatorTests {
CompositeHealthIndicator composite = new CompositeHealthIndicator( CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator, indicators); this.healthAggregator, indicators);
Health result = composite.health(); Health result = composite.health();
assertThat(result.getDetails().size(), equalTo(2)); assertThat(result.getDetails()).hasSize(2);
assertThat(result.getDetails(), hasEntry("one", assertThat(result.getDetails()).containsEntry("one",
(Object) new Health.Builder().unknown().withDetail("1", "1").build())); new Health.Builder().unknown().withDetail("1", "1").build());
assertThat(result.getDetails(), hasEntry("two", assertThat(result.getDetails()).containsEntry("two",
(Object) new Health.Builder().unknown().withDetail("2", "2").build())); new Health.Builder().unknown().withDetail("2", "2").build());
} }
@Test @Test
...@@ -88,13 +85,13 @@ public class CompositeHealthIndicatorTests { ...@@ -88,13 +85,13 @@ public class CompositeHealthIndicatorTests {
this.healthAggregator, indicators); this.healthAggregator, indicators);
composite.addHealthIndicator("three", this.three); composite.addHealthIndicator("three", this.three);
Health result = composite.health(); Health result = composite.health();
assertThat(result.getDetails().size(), equalTo(3)); assertThat(result.getDetails()).hasSize(3);
assertThat(result.getDetails(), hasEntry("one", assertThat(result.getDetails()).containsEntry("one",
(Object) new Health.Builder().unknown().withDetail("1", "1").build())); new Health.Builder().unknown().withDetail("1", "1").build());
assertThat(result.getDetails(), hasEntry("two", assertThat(result.getDetails()).containsEntry("two",
(Object) new Health.Builder().unknown().withDetail("2", "2").build())); new Health.Builder().unknown().withDetail("2", "2").build());
assertThat(result.getDetails(), hasEntry("three", assertThat(result.getDetails()).containsEntry("three",
(Object) new Health.Builder().unknown().withDetail("3", "3").build())); new Health.Builder().unknown().withDetail("3", "3").build());
} }
@Test @Test
...@@ -104,11 +101,11 @@ public class CompositeHealthIndicatorTests { ...@@ -104,11 +101,11 @@ public class CompositeHealthIndicatorTests {
composite.addHealthIndicator("one", this.one); composite.addHealthIndicator("one", this.one);
composite.addHealthIndicator("two", this.two); composite.addHealthIndicator("two", this.two);
Health result = composite.health(); Health result = composite.health();
assertThat(result.getDetails().size(), equalTo(2)); assertThat(result.getDetails().size()).isEqualTo(2);
assertThat(result.getDetails(), hasEntry("one", assertThat(result.getDetails()).containsEntry("one",
(Object) new Health.Builder().unknown().withDetail("1", "1").build())); new Health.Builder().unknown().withDetail("1", "1").build());
assertThat(result.getDetails(), hasEntry("two", assertThat(result.getDetails()).containsEntry("two",
(Object) new Health.Builder().unknown().withDetail("2", "2").build())); new Health.Builder().unknown().withDetail("2", "2").build());
} }
@Test @Test
...@@ -121,15 +118,12 @@ public class CompositeHealthIndicatorTests { ...@@ -121,15 +118,12 @@ public class CompositeHealthIndicatorTests {
CompositeHealthIndicator composite = new CompositeHealthIndicator( CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator); this.healthAggregator);
composite.addHealthIndicator("db", innerComposite); composite.addHealthIndicator("db", innerComposite);
Health result = composite.health(); Health result = composite.health();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
assertEquals( assertThat(mapper.writeValueAsString(result))
"{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\"" .isEqualTo("{\"status\":\"UNKNOWN\",\"db\":{\"status\":\"UNKNOWN\""
+ ",\"db1\":{\"status\":\"UNKNOWN\",\"1\":\"1\"}," + ",\"db1\":{\"status\":\"UNKNOWN\",\"1\":\"1\"},"
+ "\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}", + "\"db2\":{\"status\":\"UNKNOWN\",\"2\":\"2\"}}}");
mapper.writeValueAsString(result));
} }
} }
...@@ -29,12 +29,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection; ...@@ -29,12 +29,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource; import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
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.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
...@@ -70,8 +65,8 @@ public class DataSourceHealthIndicatorTests { ...@@ -70,8 +65,8 @@ public class DataSourceHealthIndicatorTests {
public void database() { public void database() {
this.indicator.setDataSource(this.dataSource); this.indicator.setDataSource(this.dataSource);
Health health = this.indicator.health(); Health health = this.indicator.health();
assertNotNull(health.getDetails().get("database")); assertThat(health.getDetails().get("database")).isNotNull();
assertNotNull(health.getDetails().get("hello")); assertThat(health.getDetails().get("hello")).isNotNull();
} }
@Test @Test
...@@ -82,9 +77,9 @@ public class DataSourceHealthIndicatorTests { ...@@ -82,9 +77,9 @@ public class DataSourceHealthIndicatorTests {
this.indicator.setQuery("SELECT COUNT(*) from FOO"); this.indicator.setQuery("SELECT COUNT(*) from FOO");
Health health = this.indicator.health(); Health health = this.indicator.health();
System.err.println(health); System.err.println(health);
assertNotNull(health.getDetails().get("database")); assertThat(health.getDetails().get("database")).isNotNull();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertNotNull(health.getDetails().get("hello")); assertThat(health.getDetails().get("hello")).isNotNull();
} }
@Test @Test
...@@ -92,8 +87,8 @@ public class DataSourceHealthIndicatorTests { ...@@ -92,8 +87,8 @@ public class DataSourceHealthIndicatorTests {
this.indicator.setDataSource(this.dataSource); this.indicator.setDataSource(this.dataSource);
this.indicator.setQuery("SELECT COUNT(*) from BAR"); this.indicator.setQuery("SELECT COUNT(*) from BAR");
Health health = this.indicator.health(); Health health = this.indicator.health();
assertThat(health.getDetails().get("database"), notNullValue()); assertThat(health.getDetails().get("database")).isNotNull();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
} }
@Test @Test
...@@ -105,24 +100,24 @@ public class DataSourceHealthIndicatorTests { ...@@ -105,24 +100,24 @@ public class DataSourceHealthIndicatorTests {
given(dataSource.getConnection()).willReturn(connection); given(dataSource.getConnection()).willReturn(connection);
this.indicator.setDataSource(dataSource); this.indicator.setDataSource(dataSource);
Health health = this.indicator.health(); Health health = this.indicator.health();
assertNotNull(health.getDetails().get("database")); assertThat(health.getDetails().get("database")).isNotNull();
verify(connection, times(2)).close(); verify(connection, times(2)).close();
} }
@Test @Test
public void productLookups() throws Exception { public void productLookups() throws Exception {
assertThat(Product.forProduct("newone"), nullValue()); assertThat(Product.forProduct("newone")).isNull();
assertThat(Product.forProduct("HSQL Database Engine"), equalTo(Product.HSQLDB)); assertThat(Product.forProduct("HSQL Database Engine")).isEqualTo(Product.HSQLDB);
assertThat(Product.forProduct("Oracle"), equalTo(Product.ORACLE)); assertThat(Product.forProduct("Oracle")).isEqualTo(Product.ORACLE);
assertThat(Product.forProduct("Apache Derby"), equalTo(Product.DERBY)); assertThat(Product.forProduct("Apache Derby")).isEqualTo(Product.DERBY);
assertThat(Product.forProduct("DB2"), equalTo(Product.DB2)); assertThat(Product.forProduct("DB2")).isEqualTo(Product.DB2);
assertThat(Product.forProduct("DB2/LINUXX8664"), equalTo(Product.DB2)); assertThat(Product.forProduct("DB2/LINUXX8664")).isEqualTo(Product.DB2);
assertThat(Product.forProduct("DB2 UDB for AS/400"), equalTo(Product.DB2_AS400)); assertThat(Product.forProduct("DB2 UDB for AS/400")).isEqualTo(Product.DB2_AS400);
assertThat(Product.forProduct("DB3 XDB for AS/400"), equalTo(Product.DB2_AS400)); assertThat(Product.forProduct("DB3 XDB for AS/400")).isEqualTo(Product.DB2_AS400);
assertThat(Product.forProduct("Informix Dynamic Server"), assertThat(Product.forProduct("Informix Dynamic Server"))
equalTo(Product.INFORMIX)); .isEqualTo(Product.INFORMIX);
assertThat(Product.forProduct("Firebird 2.5.WI"), equalTo(Product.FIREBIRD)); assertThat(Product.forProduct("Firebird 2.5.WI")).isEqualTo(Product.FIREBIRD);
assertThat(Product.forProduct("Firebird 2.1.LI"), equalTo(Product.FIREBIRD)); assertThat(Product.forProduct("Firebird 2.1.LI")).isEqualTo(Product.FIREBIRD);
} }
} }
...@@ -26,7 +26,7 @@ import org.junit.runner.RunWith; ...@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; 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; import static org.mockito.BDDMockito.given;
/** /**
...@@ -60,10 +60,10 @@ public class DiskSpaceHealthIndicatorTests { ...@@ -60,10 +60,10 @@ public class DiskSpaceHealthIndicatorTests {
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10); given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10);
given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10);
Health health = this.healthIndicator.health(); Health health = this.healthIndicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD_BYTES);
assertEquals(THRESHOLD_BYTES + 10, health.getDetails().get("free")); assertThat(health.getDetails().get("free")).isEqualTo(THRESHOLD_BYTES + 10);
assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); assertThat(health.getDetails().get("total")).isEqualTo(THRESHOLD_BYTES * 10);
} }
@Test @Test
...@@ -71,10 +71,10 @@ public class DiskSpaceHealthIndicatorTests { ...@@ -71,10 +71,10 @@ public class DiskSpaceHealthIndicatorTests {
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10); given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10);
given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10); given(this.fileMock.getTotalSpace()).willReturn(THRESHOLD_BYTES * 10);
Health health = this.healthIndicator.health(); Health health = this.healthIndicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold")); assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD_BYTES);
assertEquals(THRESHOLD_BYTES - 10, health.getDetails().get("free")); assertThat(health.getDetails().get("free")).isEqualTo(THRESHOLD_BYTES - 10);
assertEquals(THRESHOLD_BYTES * 10, health.getDetails().get("total")); assertThat(health.getDetails().get("total")).isEqualTo(THRESHOLD_BYTES * 10);
} }
private DiskSpaceHealthIndicatorProperties createProperties(File path, private DiskSpaceHealthIndicatorProperties createProperties(File path,
......
...@@ -39,11 +39,7 @@ import org.mockito.ArgumentCaptor; ...@@ -39,11 +39,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import static org.hamcrest.Matchers.arrayContaining; import static org.assertj.core.api.Assertions.assertThat;
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.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
...@@ -84,9 +80,9 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -84,9 +80,9 @@ public class ElasticsearchHealthIndicatorTests {
.forClass(ClusterHealthRequest.class); .forClass(ClusterHealthRequest.class);
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture); given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
Health health = this.indicator.health(); Health health = this.indicator.health();
assertThat(responseFuture.getTimeout, is(100L)); assertThat(responseFuture.getTimeout).isEqualTo(100L);
assertThat(requestCaptor.getValue().indices(), is(arrayContaining("_all"))); assertThat(requestCaptor.getValue().indices()).contains("_all");
assertThat(health.getStatus(), is(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
} }
@Test @Test
...@@ -99,9 +95,9 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -99,9 +95,9 @@ public class ElasticsearchHealthIndicatorTests {
this.properties.getIndices() this.properties.getIndices()
.addAll(Arrays.asList("test-index-1", "test-index-2")); .addAll(Arrays.asList("test-index-1", "test-index-2"));
Health health = this.indicator.health(); Health health = this.indicator.health();
assertThat(requestCaptor.getValue().indices(), assertThat(requestCaptor.getValue().indices()).contains("test-index-1",
is(arrayContaining("test-index-1", "test-index-2"))); "test-index-2");
assertThat(health.getStatus(), is(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
} }
@Test @Test
...@@ -113,7 +109,7 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -113,7 +109,7 @@ public class ElasticsearchHealthIndicatorTests {
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture); given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
this.properties.setResponseTimeout(1000L); this.properties.setResponseTimeout(1000L);
this.indicator.health(); this.indicator.health();
assertThat(responseFuture.getTimeout, is(1000L)); assertThat(responseFuture.getTimeout).isEqualTo(1000L);
} }
@Test @Test
...@@ -123,7 +119,7 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -123,7 +119,7 @@ public class ElasticsearchHealthIndicatorTests {
given(this.cluster.health(any(ClusterHealthRequest.class))) given(this.cluster.health(any(ClusterHealthRequest.class)))
.willReturn(responseFuture); .willReturn(responseFuture);
Health health = this.indicator.health(); Health health = this.indicator.health();
assertThat(health.getStatus(), is(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
Map<String, Object> details = health.getDetails(); Map<String, Object> details = health.getDetails();
assertDetail(details, "clusterName", "test-cluster"); assertDetail(details, "clusterName", "test-cluster");
assertDetail(details, "activeShards", 1); assertDetail(details, "activeShards", 1);
...@@ -141,7 +137,7 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -141,7 +137,7 @@ public class ElasticsearchHealthIndicatorTests {
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED)); responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED));
given(this.cluster.health(any(ClusterHealthRequest.class))) given(this.cluster.health(any(ClusterHealthRequest.class)))
.willReturn(responseFuture); .willReturn(responseFuture);
assertThat(this.indicator.health().getStatus(), is(Status.DOWN)); assertThat(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
} }
@Test @Test
...@@ -151,7 +147,7 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -151,7 +147,7 @@ public class ElasticsearchHealthIndicatorTests {
.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW)); .onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW));
given(this.cluster.health(any(ClusterHealthRequest.class))) given(this.cluster.health(any(ClusterHealthRequest.class)))
.willReturn(responseFuture); .willReturn(responseFuture);
assertThat(this.indicator.health().getStatus(), is(Status.UP)); assertThat(this.indicator.health().getStatus()).isEqualTo(Status.UP);
} }
@Test @Test
...@@ -160,14 +156,14 @@ public class ElasticsearchHealthIndicatorTests { ...@@ -160,14 +156,14 @@ public class ElasticsearchHealthIndicatorTests {
given(this.cluster.health(any(ClusterHealthRequest.class))) given(this.cluster.health(any(ClusterHealthRequest.class)))
.willReturn(responseFuture); .willReturn(responseFuture);
Health health = this.indicator.health(); Health health = this.indicator.health();
assertThat(health.getStatus(), is(Status.DOWN)); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error"), assertThat((String) health.getDetails().get("error"))
containsString(ElasticsearchTimeoutException.class.getName())); .contains(ElasticsearchTimeoutException.class.getName());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> void assertDetail(Map<String, Object> details, String detail, T value) { private <T> void assertDetail(Map<String, Object> 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 { private final static class StubClusterHealthResponse extends ClusterHealthResponse {
......
...@@ -22,9 +22,7 @@ import org.junit.Rule; ...@@ -22,9 +22,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link Health}. * Tests for {@link Health}.
...@@ -46,16 +44,16 @@ public class HealthTests { ...@@ -46,16 +44,16 @@ public class HealthTests {
@Test @Test
public void createWithStatus() throws Exception { public void createWithStatus() throws Exception {
Health health = Health.status(Status.UP).build(); Health health = Health.status(Status.UP).build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void createWithDetails() throws Exception { public void createWithDetails() throws Exception {
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b"))
.build(); .build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("a"), equalTo((Object) "b")); assertThat(health.getDetails().get("a")).isEqualTo("b");
} }
@Test @Test
...@@ -65,12 +63,12 @@ public class HealthTests { ...@@ -65,12 +63,12 @@ public class HealthTests {
Health h2 = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) Health h2 = new Health.Builder(Status.UP, Collections.singletonMap("a", "b"))
.build(); .build();
Health h3 = new Health.Builder(Status.UP).build(); Health h3 = new Health.Builder(Status.UP).build();
assertThat(h1, equalTo(h1)); assertThat(h1).isEqualTo(h1);
assertThat(h1, equalTo(h2)); assertThat(h1).isEqualTo(h2);
assertThat(h1, not(equalTo(h3))); assertThat(h1).isNotEqualTo(h3);
assertThat(h1.hashCode(), equalTo(h1.hashCode())); assertThat(h1.hashCode()).isEqualTo(h1.hashCode());
assertThat(h1.hashCode(), equalTo(h2.hashCode())); assertThat(h1.hashCode()).isEqualTo(h2.hashCode());
assertThat(h1.hashCode(), not(equalTo(h3.hashCode()))); assertThat(h1.hashCode()).isNotEqualTo(h3.hashCode());
} }
@Test @Test
...@@ -78,82 +76,82 @@ public class HealthTests { ...@@ -78,82 +76,82 @@ public class HealthTests {
RuntimeException ex = new RuntimeException("bang"); RuntimeException ex = new RuntimeException("bang");
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b"))
.withException(ex).build(); .withException(ex).build();
assertThat(health.getDetails().get("a"), equalTo((Object) "b")); assertThat(health.getDetails().get("a")).isEqualTo("b");
assertThat(health.getDetails().get("error"), assertThat(health.getDetails().get("error"))
equalTo((Object) "java.lang.RuntimeException: bang")); .isEqualTo("java.lang.RuntimeException: bang");
} }
@Test @Test
public void withDetails() throws Exception { public void withDetails() throws Exception {
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b"))
.withDetail("c", "d").build(); .withDetail("c", "d").build();
assertThat(health.getDetails().get("a"), equalTo((Object) "b")); assertThat(health.getDetails().get("a")).isEqualTo("b");
assertThat(health.getDetails().get("c"), equalTo((Object) "d")); assertThat(health.getDetails().get("c")).isEqualTo("d");
} }
@Test @Test
public void unknownWithDetails() throws Exception { public void unknownWithDetails() throws Exception {
Health health = new Health.Builder().unknown().withDetail("a", "b").build(); Health health = new Health.Builder().unknown().withDetail("a", "b").build();
assertThat(health.getStatus(), equalTo(Status.UNKNOWN)); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN);
assertThat(health.getDetails().get("a"), equalTo((Object) "b")); assertThat(health.getDetails().get("a")).isEqualTo("b");
} }
@Test @Test
public void unknown() throws Exception { public void unknown() throws Exception {
Health health = new Health.Builder().unknown().build(); Health health = new Health.Builder().unknown().build();
assertThat(health.getStatus(), equalTo(Status.UNKNOWN)); assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void upWithDetails() throws Exception { public void upWithDetails() throws Exception {
Health health = new Health.Builder().up().withDetail("a", "b").build(); Health health = new Health.Builder().up().withDetail("a", "b").build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("a"), equalTo((Object) "b")); assertThat(health.getDetails().get("a")).isEqualTo("b");
} }
@Test @Test
public void up() throws Exception { public void up() throws Exception {
Health health = new Health.Builder().up().build(); Health health = new Health.Builder().up().build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void downWithException() throws Exception { public void downWithException() throws Exception {
RuntimeException ex = new RuntimeException("bang"); RuntimeException ex = new RuntimeException("bang");
Health health = Health.down(ex).build(); Health health = Health.down(ex).build();
assertThat(health.getStatus(), equalTo(Status.DOWN)); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("error"), assertThat(health.getDetails().get("error"))
equalTo((Object) "java.lang.RuntimeException: bang")); .isEqualTo("java.lang.RuntimeException: bang");
} }
@Test @Test
public void down() throws Exception { public void down() throws Exception {
Health health = Health.down().build(); Health health = Health.down().build();
assertThat(health.getStatus(), equalTo(Status.DOWN)); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void outOfService() throws Exception { public void outOfService() throws Exception {
Health health = Health.outOfService().build(); Health health = Health.outOfService().build();
assertThat(health.getStatus(), equalTo(Status.OUT_OF_SERVICE)); assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void statusCode() throws Exception { public void statusCode() throws Exception {
Health health = Health.status("UP").build(); Health health = Health.status("UP").build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
@Test @Test
public void status() throws Exception { public void status() throws Exception {
Health health = Health.status(Status.UP).build(); Health health = Health.status(Status.UP).build();
assertThat(health.getStatus(), equalTo(Status.UP)); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().size(), equalTo(0)); assertThat(health.getDetails().size()).isEqualTo(0);
} }
} }
...@@ -23,7 +23,7 @@ import javax.jms.JMSException; ...@@ -23,7 +23,7 @@ import javax.jms.JMSException;
import org.junit.Test; 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.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
...@@ -46,8 +46,8 @@ public class JmsHealthIndicatorTests { ...@@ -46,8 +46,8 @@ public class JmsHealthIndicatorTests {
given(connectionFactory.createConnection()).willReturn(connection); given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health(); Health health = indicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals("JMS test provider", health.getDetails().get("provider")); assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
verify(connection, times(1)).close(); verify(connection, times(1)).close();
} }
...@@ -58,8 +58,8 @@ public class JmsHealthIndicatorTests { ...@@ -58,8 +58,8 @@ public class JmsHealthIndicatorTests {
.willThrow(new JMSException("test", "123")); .willThrow(new JMSException("test", "123"));
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health(); Health health = indicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertEquals(null, health.getDetails().get("provider")); assertThat(health.getDetails().get("provider")).isNull();
} }
@Test @Test
...@@ -73,8 +73,8 @@ public class JmsHealthIndicatorTests { ...@@ -73,8 +73,8 @@ public class JmsHealthIndicatorTests {
given(connectionFactory.createConnection()).willReturn(connection); given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health(); Health health = indicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertEquals(null, health.getDetails().get("provider")); assertThat(health.getDetails().get("provider")).isNull();
verify(connection, times(1)).close(); verify(connection, times(1)).close();
} }
......
...@@ -32,9 +32,7 @@ import org.junit.Test; ...@@ -32,9 +32,7 @@ import org.junit.Test;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -67,8 +65,8 @@ public class MailHealthIndicatorTests { ...@@ -67,8 +65,8 @@ public class MailHealthIndicatorTests {
public void smtpIsUp() { public void smtpIsUp() {
given(this.mailSender.getProtocol()).willReturn("success"); given(this.mailSender.getProtocol()).willReturn("success");
Health health = this.indicator.health(); Health health = this.indicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals("smtp.acme.org:25", health.getDetails().get("location")); assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25");
} }
@Test @Test
...@@ -76,11 +74,11 @@ public class MailHealthIndicatorTests { ...@@ -76,11 +74,11 @@ public class MailHealthIndicatorTests {
willThrow(new MessagingException("A test exception")).given(this.mailSender) willThrow(new MessagingException("A test exception")).given(this.mailSender)
.testConnection(); .testConnection();
Health health = this.indicator.health(); Health health = this.indicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertEquals("smtp.acme.org:25", health.getDetails().get("location")); assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25");
Object errorMessage = health.getDetails().get("error"); Object errorMessage = health.getDetails().get("error");
assertNotNull(errorMessage); assertThat(errorMessage).isNotNull();
assertTrue(errorMessage.toString().contains("A test exception")); assertThat(errorMessage.toString().contains("A test exception")).isTrue();
} }
public static class SuccessTransport extends Transport { public static class SuccessTransport extends Transport {
......
...@@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; ...@@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -58,10 +56,11 @@ public class MongoHealthIndicatorTests { ...@@ -58,10 +56,11 @@ public class MongoHealthIndicatorTests {
PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class, EndpointAutoConfiguration.class, MongoDataAutoConfiguration.class, EndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class); HealthIndicatorAutoConfiguration.class);
assertEquals(1, this.context.getBeanNamesForType(MongoTemplate.class).length); assertThat(this.context.getBeanNamesForType(MongoTemplate.class).length)
.isEqualTo(1);
MongoHealthIndicator healthIndicator = this.context MongoHealthIndicator healthIndicator = this.context
.getBean(MongoHealthIndicator.class); .getBean(MongoHealthIndicator.class);
assertNotNull(healthIndicator); assertThat(healthIndicator).isNotNull();
} }
@Test @Test
...@@ -71,11 +70,9 @@ public class MongoHealthIndicatorTests { ...@@ -71,11 +70,9 @@ public class MongoHealthIndicatorTests {
MongoTemplate mongoTemplate = mock(MongoTemplate.class); MongoTemplate mongoTemplate = mock(MongoTemplate.class);
given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult); given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult);
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals("2.6.4", health.getDetails().get("version")); assertThat(health.getDetails().get("version")).isEqualTo("2.6.4");
verify(commandResult).getString("version"); verify(commandResult).getString("version");
verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
} }
...@@ -86,12 +83,11 @@ public class MongoHealthIndicatorTests { ...@@ -86,12 +83,11 @@ public class MongoHealthIndicatorTests {
given(mongoTemplate.executeCommand("{ buildInfo: 1 }")) given(mongoTemplate.executeCommand("{ buildInfo: 1 }"))
.willThrow(new MongoException("Connection failed")); .willThrow(new MongoException("Connection failed"));
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertTrue(((String) health.getDetails().get("error")) assertThat(((String) health.getDetails().get("error"))
.contains("Connection failed")); .contains("Connection failed"));
verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
} }
} }
...@@ -23,7 +23,7 @@ import java.util.Map; ...@@ -23,7 +23,7 @@ import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link OrderedHealthAggregator}. * Tests for {@link OrderedHealthAggregator}.
...@@ -46,7 +46,8 @@ public class OrderedHealthAggregatorTests { ...@@ -46,7 +46,8 @@ public class OrderedHealthAggregatorTests {
healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h2", new Health.Builder().status(Status.UP).build());
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).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 @Test
...@@ -58,8 +59,8 @@ public class OrderedHealthAggregatorTests { ...@@ -58,8 +59,8 @@ public class OrderedHealthAggregatorTests {
healths.put("h2", new Health.Builder().status(Status.UP).build()); healths.put("h2", new Health.Builder().status(Status.UP).build());
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
assertEquals(Status.UNKNOWN, assertThat(this.healthAggregator.aggregate(healths).getStatus())
this.healthAggregator.aggregate(healths).getStatus()); .isEqualTo(Status.UNKNOWN);
} }
@Test @Test
...@@ -70,7 +71,8 @@ public class OrderedHealthAggregatorTests { ...@@ -70,7 +71,8 @@ public class OrderedHealthAggregatorTests {
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).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 @Test
...@@ -83,7 +85,8 @@ public class OrderedHealthAggregatorTests { ...@@ -83,7 +85,8 @@ public class OrderedHealthAggregatorTests {
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build()); healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build()); healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).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);
} }
} }
...@@ -26,8 +26,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -26,8 +26,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link RabbitHealthIndicator}. * Tests for {@link RabbitHealthIndicator}.
...@@ -50,10 +49,11 @@ public class RabbitHealthIndicatorTests { ...@@ -50,10 +49,11 @@ public class RabbitHealthIndicatorTests {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, RabbitAutoConfiguration.class,
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.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 RabbitHealthIndicator healthIndicator = this.context
.getBean(RabbitHealthIndicator.class); .getBean(RabbitHealthIndicator.class);
assertNotNull(healthIndicator); assertThat(healthIndicator).isNotNull();
} }
} }
...@@ -30,9 +30,7 @@ import org.springframework.data.redis.RedisConnectionFailureException; ...@@ -30,9 +30,7 @@ import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -58,18 +56,17 @@ public class RedisHealthIndicatorTests { ...@@ -58,18 +56,17 @@ public class RedisHealthIndicatorTests {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
PropertyPlaceholderAutoConfiguration.class, RedisAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, RedisAutoConfiguration.class,
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
assertEquals(1, assertThat(this.context.getBeanNamesForType(RedisConnectionFactory.class))
this.context.getBeanNamesForType(RedisConnectionFactory.class).length); .hasSize(1);
RedisHealthIndicator healthIndicator = this.context RedisHealthIndicator healthIndicator = this.context
.getBean(RedisHealthIndicator.class); .getBean(RedisHealthIndicator.class);
assertNotNull(healthIndicator); assertThat(healthIndicator).isNotNull();
} }
@Test @Test
public void redisIsUp() throws Exception { public void redisIsUp() throws Exception {
Properties info = new Properties(); Properties info = new Properties();
info.put("redis_version", "2.8.9"); info.put("redis_version", "2.8.9");
RedisConnection redisConnection = mock(RedisConnection.class); RedisConnection redisConnection = mock(RedisConnection.class);
RedisConnectionFactory redisConnectionFactory = mock( RedisConnectionFactory redisConnectionFactory = mock(
RedisConnectionFactory.class); RedisConnectionFactory.class);
...@@ -77,11 +74,9 @@ public class RedisHealthIndicatorTests { ...@@ -77,11 +74,9 @@ public class RedisHealthIndicatorTests {
given(redisConnection.info()).willReturn(info); given(redisConnection.info()).willReturn(info);
RedisHealthIndicator healthIndicator = new RedisHealthIndicator( RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
redisConnectionFactory); redisConnectionFactory);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals("2.8.9", health.getDetails().get("version")); assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
verify(redisConnectionFactory).getConnection(); verify(redisConnectionFactory).getConnection();
verify(redisConnection).info(); verify(redisConnection).info();
} }
...@@ -96,13 +91,12 @@ public class RedisHealthIndicatorTests { ...@@ -96,13 +91,12 @@ public class RedisHealthIndicatorTests {
.willThrow(new RedisConnectionFailureException("Connection failed")); .willThrow(new RedisConnectionFailureException("Connection failed"));
RedisHealthIndicator healthIndicator = new RedisHealthIndicator( RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
redisConnectionFactory); redisConnectionFactory);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertTrue(((String) health.getDetails().get("error")) assertThat(((String) health.getDetails().get("error"))
.contains("Connection failed")); .contains("Connection failed"));
verify(redisConnectionFactory).getConnection(); verify(redisConnectionFactory).getConnection();
verify(redisConnection).info(); verify(redisConnection).info();
} }
} }
...@@ -30,9 +30,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati ...@@ -30,9 +30,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration; import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -57,10 +55,11 @@ public class SolrHealthIndicatorTests { ...@@ -57,10 +55,11 @@ public class SolrHealthIndicatorTests {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
PropertyPlaceholderAutoConfiguration.class, SolrAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, SolrAutoConfiguration.class,
EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.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 SolrHealthIndicator healthIndicator = this.context
.getBean(SolrHealthIndicator.class); .getBean(SolrHealthIndicator.class);
assertNotNull(healthIndicator); assertThat(healthIndicator).isNotNull();
} }
@Test @Test
...@@ -71,22 +70,21 @@ public class SolrHealthIndicatorTests { ...@@ -71,22 +70,21 @@ public class SolrHealthIndicatorTests {
response.add("status", "OK"); response.add("status", "OK");
pingResponse.setResponse(response); pingResponse.setResponse(response);
given(solrServer.ping()).willReturn(pingResponse); given(solrServer.ping()).willReturn(pingResponse);
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.UP, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertEquals("OK", health.getDetails().get("solrStatus")); assertThat(health.getDetails().get("solrStatus")).isEqualTo("OK");
} }
@Test @Test
public void solrIsDown() throws Exception { public void solrIsDown() throws Exception {
SolrServer solrServer = mock(SolrServer.class); SolrServer solrServer = mock(SolrServer.class);
given(solrServer.ping()).willThrow(new IOException("Connection failed")); given(solrServer.ping()).willThrow(new IOException("Connection failed"));
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrServer);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertEquals(Status.DOWN, health.getStatus()); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertTrue(((String) health.getDetails().get("error")) assertThat(((String) health.getDetails().get("error"))
.contains("Connection failed")); .contains("Connection failed"));
} }
} }
...@@ -24,8 +24,7 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -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.repository.InMemoryMetricRepository;
import org.springframework.boot.actuate.metrics.writer.Delta; 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.junit.Assert.assertNull;
/** /**
* Tests for {@link AggregateMetricReader}. * Tests for {@link AggregateMetricReader}.
...@@ -41,20 +40,21 @@ public class AggregateMetricReaderTests { ...@@ -41,20 +40,21 @@ public class AggregateMetricReaderTests {
@Test @Test
public void writeAndReadDefaults() { public void writeAndReadDefaults() {
this.source.set(new Metric<Double>("foo.bar.spam", 2.3)); this.source.set(new Metric<Double>("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 @Test
public void defaultKeyPattern() { public void defaultKeyPattern() {
this.source.set(new Metric<Double>("foo.bar.spam.bucket.wham", 2.3)); this.source.set(new Metric<Double>("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 @Test
public void addKeyPattern() { public void addKeyPattern() {
this.source.set(new Metric<Double>("foo.bar.spam.bucket.wham", 2.3)); this.source.set(new Metric<Double>("foo.bar.spam.bucket.wham", 2.3));
this.reader.setKeyPattern("d.d.k.d"); 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 @Test
...@@ -63,42 +63,43 @@ public class AggregateMetricReaderTests { ...@@ -63,42 +63,43 @@ public class AggregateMetricReaderTests {
this.source.set(new Metric<Double>("off.bar.spam.bucket.wham", 2.4)); this.source.set(new Metric<Double>("off.bar.spam.bucket.wham", 2.4));
this.reader.setPrefix("www"); this.reader.setPrefix("www");
this.reader.setKeyPattern("k.d.k.d"); this.reader.setKeyPattern("k.d.k.d");
assertEquals(2.3, this.reader.findOne("www.foo.spam.wham").getValue()); assertThat(this.reader.findOne("www.foo.spam.wham").getValue()).isEqualTo(2.3);
assertEquals(2, this.reader.count()); assertThat(this.reader.count()).isEqualTo(2);
} }
@Test @Test
public void writeAndReadExtraLong() { public void writeAndReadExtraLong() {
this.source.set(new Metric<Double>("blee.foo.bar.spam", 2.3)); this.source.set(new Metric<Double>("blee.foo.bar.spam", 2.3));
this.reader.setKeyPattern("d.d.d.k"); 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 @Test
public void writeAndReadLatestValue() { public void writeAndReadLatestValue() {
this.source.set(new Metric<Double>("foo.bar.spam", 2.3, new Date(100L))); this.source.set(new Metric<Double>("foo.bar.spam", 2.3, new Date(100L)));
this.source.set(new Metric<Double>("oof.rab.spam", 2.4, new Date(0L))); this.source.set(new Metric<Double>("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 @Test
public void onlyPrefixed() { public void onlyPrefixed() {
this.source.set(new Metric<Double>("foo.bar.spam", 2.3)); this.source.set(new Metric<Double>("foo.bar.spam", 2.3));
assertNull(this.reader.findOne("spam")); assertThat(this.reader.findOne("spam")).isNull();
} }
@Test @Test
public void incrementCounter() { public void incrementCounter() {
this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L)); this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L)); this.source.increment(new Delta<Long>("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 @Test
public void countGauges() { public void countGauges() {
this.source.set(new Metric<Double>("foo.bar.spam", 2.3)); this.source.set(new Metric<Double>("foo.bar.spam", 2.3));
this.source.set(new Metric<Double>("oof.rab.spam", 2.4)); this.source.set(new Metric<Double>("oof.rab.spam", 2.4));
assertEquals(1, this.reader.count()); assertThat(this.reader.count()).isEqualTo(1);
} }
@Test @Test
...@@ -107,7 +108,7 @@ public class AggregateMetricReaderTests { ...@@ -107,7 +108,7 @@ public class AggregateMetricReaderTests {
this.source.set(new Metric<Double>("oof.rab.spam", 2.4)); this.source.set(new Metric<Double>("oof.rab.spam", 2.4));
this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L)); this.source.increment(new Delta<Long>("foo.bar.counter.spam", 2L));
this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L)); this.source.increment(new Delta<Long>("oof.rab.counter.spam", 3L));
assertEquals(2, this.reader.count()); assertThat(this.reader.count()).isEqualTo(2);
} }
} }
...@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.lang.UsesJava8; import org.springframework.lang.UsesJava8;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Speed tests for {@link BufferGaugeService}. * Speed tests for {@link BufferGaugeService}.
...@@ -117,7 +117,7 @@ public class BufferGaugeServiceSpeedTests { ...@@ -117,7 +117,7 @@ public class BufferGaugeServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertTrue(number * threadCount < total.longValue()); assertThat(number * threadCount < total.longValue()).isTrue();
} }
@Theory @Theory
...@@ -141,7 +141,7 @@ public class BufferGaugeServiceSpeedTests { ...@@ -141,7 +141,7 @@ public class BufferGaugeServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertTrue(0 < total.longValue()); assertThat(0 < total.longValue()).isTrue();
} }
private void iterate(String taskName) throws Exception { private void iterate(String taskName) throws Exception {
......
...@@ -18,8 +18,7 @@ package org.springframework.boot.actuate.metrics.buffer; ...@@ -18,8 +18,7 @@ package org.springframework.boot.actuate.metrics.buffer;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link BufferMetricReader}. * Tests for {@link BufferMetricReader}.
...@@ -39,21 +38,21 @@ public class BufferMetricReaderTests { ...@@ -39,21 +38,21 @@ public class BufferMetricReaderTests {
public void countReflectsNumberOfMetrics() { public void countReflectsNumberOfMetrics() {
this.gauges.set("foo", 1); this.gauges.set("foo", 1);
this.counters.increment("bar", 2); this.counters.increment("bar", 2);
assertEquals(2, this.reader.count()); assertThat(this.reader.count()).isEqualTo(2);
} }
@Test @Test
public void findGauge() { public void findGauge() {
this.gauges.set("foo", 1); this.gauges.set("foo", 1);
assertNotNull(this.reader.findOne("foo")); assertThat(this.reader.findOne("foo")).isNotNull();
assertEquals(1, this.reader.count()); assertThat(this.reader.count()).isEqualTo(1);
} }
@Test @Test
public void findCounter() { public void findCounter() {
this.counters.increment("foo", 1); this.counters.increment("foo", 1);
assertNotNull(this.reader.findOne("foo")); assertThat(this.reader.findOne("foo")).isNotNull();
assertEquals(1, this.reader.count()); assertThat(this.reader.count()).isEqualTo(1);
} }
} }
...@@ -20,8 +20,7 @@ import java.util.function.Consumer; ...@@ -20,8 +20,7 @@ import java.util.function.Consumer;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;
/** /**
* Tests for {@link CounterBuffers}. * Tests for {@link CounterBuffers}.
...@@ -43,7 +42,7 @@ public class CounterBuffersTests { ...@@ -43,7 +42,7 @@ public class CounterBuffersTests {
CounterBuffersTests.this.value = buffer.getValue(); CounterBuffersTests.this.value = buffer.getValue();
} }
}); });
assertEquals(2, this.value); assertThat(this.value).isEqualTo(2);
} }
@Test @Test
...@@ -54,12 +53,12 @@ public class CounterBuffersTests { ...@@ -54,12 +53,12 @@ public class CounterBuffersTests {
CounterBuffersTests.this.value = buffer.getValue(); CounterBuffersTests.this.value = buffer.getValue();
} }
}); });
assertEquals(0, this.value); assertThat(this.value).isEqualTo(0);
} }
@Test @Test
public void findNonExistent() { public void findNonExistent() {
assertNull(this.buffers.find("foo")); assertThat(this.buffers.find("foo")).isNull();
} }
} }
...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.lang.UsesJava8; import org.springframework.lang.UsesJava8;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Speed tests for {@link CounterService}. * Speed tests for {@link CounterService}.
...@@ -116,7 +116,7 @@ public class CounterServiceSpeedTests { ...@@ -116,7 +116,7 @@ public class CounterServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertEquals(number * threadCount, total.longValue()); assertThat(total.longValue()).isEqualTo(number * threadCount);
} }
@Theory @Theory
...@@ -140,7 +140,7 @@ public class CounterServiceSpeedTests { ...@@ -140,7 +140,7 @@ public class CounterServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); 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 { private void iterate(String taskName) throws Exception {
......
...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultCounterService; ...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultCounterService;
import org.springframework.lang.UsesJava8; import org.springframework.lang.UsesJava8;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Speed tests for {@link DefaultCounterService}. * Speed tests for {@link DefaultCounterService}.
...@@ -124,7 +124,7 @@ public class DefaultCounterServiceSpeedTests { ...@@ -124,7 +124,7 @@ public class DefaultCounterServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertEquals(number * threadCount, total.longValue()); assertThat(total.longValue()).isEqualTo(number * threadCount);
} }
} }
...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultGaugeService; ...@@ -41,7 +41,7 @@ import org.springframework.boot.actuate.metrics.writer.DefaultGaugeService;
import org.springframework.lang.UsesJava8; import org.springframework.lang.UsesJava8;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Speed tests for {@link DefaultGaugeService}. * Speed tests for {@link DefaultGaugeService}.
...@@ -125,7 +125,7 @@ public class DefaultGaugeServiceSpeedTests { ...@@ -125,7 +125,7 @@ public class DefaultGaugeServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertTrue(0 < total.longValue()); assertThat(0 < total.longValue()).isTrue();
} }
} }
...@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReade ...@@ -42,7 +42,7 @@ import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReade
import org.springframework.lang.UsesJava8; import org.springframework.lang.UsesJava8;
import org.springframework.util.StopWatch; 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'} * Speeds tests for {@link DropwizardMetricServices DropwizardMetricServices'}
...@@ -127,7 +127,7 @@ public class DropwizardCounterServiceSpeedTests { ...@@ -127,7 +127,7 @@ public class DropwizardCounterServiceSpeedTests {
}); });
watch.stop(); watch.stop();
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms"); System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
assertEquals(number * threadCount, total.longValue()); assertThat(total.longValue()).isEqualTo(number * threadCount);
} }
} }
...@@ -23,8 +23,7 @@ import com.codahale.metrics.Gauge; ...@@ -23,8 +23,7 @@ import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistry;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
/** /**
* Tests for {@link DropwizardMetricServices}. * Tests for {@link DropwizardMetricServices}.
...@@ -42,7 +41,7 @@ public class DropwizardMetricServicesTests { ...@@ -42,7 +41,7 @@ public class DropwizardMetricServicesTests {
this.writer.increment("foo"); this.writer.increment("foo");
this.writer.increment("foo"); 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 @Test
...@@ -50,7 +49,7 @@ public class DropwizardMetricServicesTests { ...@@ -50,7 +49,7 @@ public class DropwizardMetricServicesTests {
this.writer.increment("meter.foo"); this.writer.increment("meter.foo");
this.writer.increment("meter.foo"); 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 @Test
...@@ -58,7 +57,7 @@ public class DropwizardMetricServicesTests { ...@@ -58,7 +57,7 @@ public class DropwizardMetricServicesTests {
this.writer.increment("counter.foo"); this.writer.increment("counter.foo");
this.writer.increment("counter.foo"); 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 @Test
...@@ -66,23 +65,23 @@ public class DropwizardMetricServicesTests { ...@@ -66,23 +65,23 @@ public class DropwizardMetricServicesTests {
this.writer.submit("foo", 2.1); this.writer.submit("foo", 2.1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Gauge<Double> gauge = (Gauge<Double>) this.registry.getMetrics().get("gauge.foo"); Gauge<Double> gauge = (Gauge<Double>) 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); this.writer.submit("foo", 2.3);
assertEquals(new Double(2.3), gauge.getValue()); assertThat(gauge.getValue()).isEqualTo(new Double(2.3));
} }
@Test @Test
public void setPredefinedTimer() { public void setPredefinedTimer() {
this.writer.submit("timer.foo", 200); this.writer.submit("timer.foo", 200);
this.writer.submit("timer.foo", 300); this.writer.submit("timer.foo", 300);
assertEquals(2, this.registry.timer("timer.foo").getCount()); assertThat(this.registry.timer("timer.foo").getCount()).isEqualTo(2);
} }
@Test @Test
public void setPredefinedHistogram() { public void setPredefinedHistogram() {
this.writer.submit("histogram.foo", 2.1); this.writer.submit("histogram.foo", 2.1);
this.writer.submit("histogram.foo", 2.3); 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 { ...@@ -108,7 +107,8 @@ public class DropwizardMetricServicesTests {
} }
for (WriterThread thread : threads) { for (WriterThread thread : threads) {
assertFalse("expected thread caused unexpected exception", thread.isFailed()); assertThat(thread.isFailed())
.as("expected thread caused unexpected exception").isFalse();
} }
} }
......
...@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit ...@@ -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.Delta;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter; 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}. * Tests for {@link MetricCopyExporter}.
...@@ -45,18 +45,18 @@ public class MetricCopyExporterTests { ...@@ -45,18 +45,18 @@ public class MetricCopyExporterTests {
public void export() { public void export() {
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
} }
@Test @Test
public void counter() { public void counter() {
this.reader.increment(new Delta<Number>("counter.foo", 2)); this.reader.increment(new Delta<Number>("counter.foo", 2));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
this.reader.increment(new Delta<Number>("counter.foo", 3)); this.reader.increment(new Delta<Number>("counter.foo", 3));
this.exporter.export(); this.exporter.export();
this.exporter.flush(); this.exporter.flush();
assertEquals(5L, this.writer.findOne("counter.foo").getValue()); assertThat(this.writer.findOne("counter.foo").getValue()).isEqualTo(5L);
} }
@Test @Test
...@@ -68,7 +68,7 @@ public class MetricCopyExporterTests { ...@@ -68,7 +68,7 @@ public class MetricCopyExporterTests {
this.reader.increment(new Delta<Number>("counter.foo", 3)); this.reader.increment(new Delta<Number>("counter.foo", 3));
exporter.export(); exporter.export();
exporter.flush(); exporter.flush();
assertEquals(5L, writer.getValue().getValue()); assertThat(writer.getValue().getValue()).isEqualTo(5L);
} }
@Test @Test
...@@ -76,7 +76,7 @@ public class MetricCopyExporterTests { ...@@ -76,7 +76,7 @@ public class MetricCopyExporterTests {
this.exporter.setIncludes("*"); this.exporter.setIncludes("*");
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
} }
@Test @Test
...@@ -86,7 +86,7 @@ public class MetricCopyExporterTests { ...@@ -86,7 +86,7 @@ public class MetricCopyExporterTests {
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.reader.set(new Metric<Number>("bar", 2.4)); this.reader.set(new Metric<Number>("bar", 2.4));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
} }
@Test @Test
...@@ -95,7 +95,7 @@ public class MetricCopyExporterTests { ...@@ -95,7 +95,7 @@ public class MetricCopyExporterTests {
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.reader.set(new Metric<Number>("bar", 2.4)); this.reader.set(new Metric<Number>("bar", 2.4));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
} }
@Test @Test
...@@ -103,7 +103,7 @@ public class MetricCopyExporterTests { ...@@ -103,7 +103,7 @@ public class MetricCopyExporterTests {
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000)); this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000));
this.exporter.export(); this.exporter.export();
assertEquals(0, this.writer.count()); assertThat(this.writer.count()).isEqualTo(0);
} }
@Test @Test
...@@ -112,7 +112,7 @@ public class MetricCopyExporterTests { ...@@ -112,7 +112,7 @@ public class MetricCopyExporterTests {
this.exporter.setIgnoreTimestamps(true); this.exporter.setIgnoreTimestamps(true);
this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000)); this.exporter.setEarliestTimestamp(new Date(System.currentTimeMillis() + 10000));
this.exporter.export(); this.exporter.export();
assertEquals(1, this.writer.count()); assertThat(this.writer.count()).isEqualTo(1);
} }
private static class SimpleGaugeWriter implements GaugeWriter { private static class SimpleGaugeWriter implements GaugeWriter {
......
...@@ -23,7 +23,7 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -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.repository.InMemoryMetricRepository;
import org.springframework.boot.actuate.metrics.rich.InMemoryRichGaugeRepository; 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}. * Tests for {@link RichGaugeExporter}.
...@@ -43,7 +43,7 @@ public class RichGaugeExporterTests { ...@@ -43,7 +43,7 @@ public class RichGaugeExporterTests {
public void prefixedMetricsCopied() { public void prefixedMetricsCopied() {
this.reader.set(new Metric<Number>("foo", 2.3)); this.reader.set(new Metric<Number>("foo", 2.3));
this.exporter.export(); this.exporter.export();
assertEquals(1, Iterables.collection(this.writer.groups()).size()); assertThat(Iterables.collection(this.writer.groups())).hasSize(1);
} }
} }
...@@ -32,7 +32,7 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter; ...@@ -32,7 +32,7 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 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}. * Tests for {@link SpringIntegrationMetricReader}.
...@@ -50,7 +50,7 @@ public class SpringIntegrationMetricReaderTests { ...@@ -50,7 +50,7 @@ public class SpringIntegrationMetricReaderTests {
@Test @Test
public void test() { public void test() {
assertTrue(this.reader.count() > 0); assertThat(this.reader.count() > 0).isTrue();
} }
@Configuration @Configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment