Migrate from ExpectedException rule to AssertJ
Replace ExpectedException JUnit rules with AssertJ exception assertions. Closes gh-14336
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,9 +21,7 @@ import java.util.Collections;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -33,6 +31,7 @@ import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -44,9 +43,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class RabbitHealthIndicatorTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@@ -64,9 +60,9 @@ public class RabbitHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void createWhenRabbitTemplateIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("RabbitTemplate must not be null");
|
||||
new RabbitHealthIndicator(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RabbitHealthIndicator(null))
|
||||
.withMessageContaining("RabbitTemplate must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,13 +19,12 @@ package org.springframework.boot.actuate.audit;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link AuditEvent}.
|
||||
@@ -35,9 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class AuditEventTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void nowEvent() {
|
||||
AuditEvent event = new AuditEvent("phil", "UNKNOWN",
|
||||
@@ -64,17 +60,18 @@ public class AuditEventTests {
|
||||
|
||||
@Test
|
||||
public void nullTimestamp() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Timestamp must not be null");
|
||||
new AuditEvent(null, "phil", "UNKNOWN",
|
||||
Collections.singletonMap("a", (Object) "b"));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN",
|
||||
Collections.singletonMap("a", (Object) "b")))
|
||||
.withMessageContaining("Timestamp must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullType() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Type must not be null");
|
||||
new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b"));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new AuditEvent("phil", null,
|
||||
Collections.singletonMap("a", (Object) "b")))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link InMemoryAuditEventRepository}.
|
||||
@@ -37,9 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class InMemoryAuditEventRepositoryTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void lessThanCapacity() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
@@ -65,10 +61,9 @@ public class InMemoryAuditEventRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void addNullAuditEvent() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("AuditEvent must not be null");
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
repository.add(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> repository.add(null))
|
||||
.withMessageContaining("AuditEvent must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,9 +22,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry;
|
||||
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor;
|
||||
@@ -34,6 +32,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -46,9 +45,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class CachesEndpointTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void allCachesWithSingleCacheManager() {
|
||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test",
|
||||
@@ -94,11 +90,10 @@ public class CachesEndpointTests {
|
||||
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
|
||||
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
|
||||
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
||||
this.thrown.expect(NonUniqueCacheException.class);
|
||||
this.thrown.expectMessage("dupe-cache");
|
||||
this.thrown.expectMessage("test");
|
||||
this.thrown.expectMessage("another");
|
||||
endpoint.cache("dupe-cache", null);
|
||||
assertThatExceptionOfType(NonUniqueCacheException.class)
|
||||
.isThrownBy(() -> endpoint.cache("dupe-cache", null))
|
||||
.withMessageContaining("dupe-cache").withMessageContaining("test")
|
||||
.withMessageContaining("another");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,11 +154,10 @@ public class CachesEndpointTests {
|
||||
cacheManagers.put("test", cacheManager(mockCache("dupe-cache"), mockCache("b")));
|
||||
cacheManagers.put("another", cacheManager(mockCache("dupe-cache")));
|
||||
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
||||
|
||||
this.thrown.expectMessage("dupe-cache");
|
||||
this.thrown.expectMessage("test");
|
||||
this.thrown.expectMessage("another");
|
||||
endpoint.clearCache("dupe-cache", null);
|
||||
assertThatExceptionOfType(NonUniqueCacheException.class)
|
||||
.isThrownBy(() -> endpoint.clearCache("dupe-cache", null))
|
||||
.withMessageContaining("dupe-cache").withMessageContaining("test")
|
||||
.withMessageContaining("another");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,15 +18,14 @@ package org.springframework.boot.actuate.endpoint.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DiscoveredOperationMethod}.
|
||||
@@ -35,15 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class DiscoveredOperationMethodTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenAnnotationAttributesIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("AnnotationAttributes must not be null");
|
||||
Method method = ReflectionUtils.findMethod(getClass(), "example");
|
||||
new DiscoveredOperationMethod(method, OperationType.READ, null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new DiscoveredOperationMethod(method, OperationType.READ, null))
|
||||
.withMessageContaining("AnnotationAttributes must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||
@@ -30,6 +28,7 @@ import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -40,14 +39,11 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class DiscovererEndpointFilterTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenDiscovererIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Discoverer must not be null");
|
||||
new TestDiscovererEndpointFilter(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestDiscovererEndpointFilter(null))
|
||||
.withMessageContaining("Discoverer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,9 +32,7 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||
@@ -54,6 +52,8 @@ import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -65,39 +65,39 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class EndpointDiscovererTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ApplicationContext must not be null");
|
||||
new TestEndpointDiscoverer(null, mock(ParameterValueMapper.class),
|
||||
Collections.emptyList(), Collections.emptyList());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(null,
|
||||
mock(ParameterValueMapper.class), Collections.emptyList(),
|
||||
Collections.emptyList()))
|
||||
.withMessageContaining("ApplicationContext must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ParameterValueMapper must not be null");
|
||||
new TestEndpointDiscoverer(mock(ApplicationContext.class), null,
|
||||
Collections.emptyList(), Collections.emptyList());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
null, Collections.emptyList(), Collections.emptyList()))
|
||||
.withMessageContaining("ParameterValueMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenInvokerAdvisorsIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("InvokerAdvisors must not be null");
|
||||
new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
mock(ParameterValueMapper.class), null, Collections.emptyList());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(
|
||||
mock(ApplicationContext.class), mock(ParameterValueMapper.class),
|
||||
null, Collections.emptyList()))
|
||||
.withMessageContaining("InvokerAdvisors must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenFiltersIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Filters must not be null");
|
||||
new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
mock(ParameterValueMapper.class), Collections.emptyList(), null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
mock(ParameterValueMapper.class), Collections.emptyList(), null))
|
||||
.withMessageContaining("Filters must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,11 +139,11 @@ public class EndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingEndpointConfiguration.class, (context) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
||||
new TestEndpointDiscoverer(context).getEndpoints();
|
||||
});
|
||||
load(ClashingEndpointConfiguration.class,
|
||||
(context) -> assertThatIllegalStateException()
|
||||
.isThrownBy(new TestEndpointDiscoverer(context)::getEndpoints)
|
||||
.withMessageContaining(
|
||||
"Found two endpoints with the id 'test': "));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.invoke.convert;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.ParameterMappingException;
|
||||
@@ -29,6 +27,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -43,9 +42,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class ConversionServiceParameterValueMapperTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void mapParameterShouldDelegateToConversionService() {
|
||||
DefaultFormattingConversionService conversionService = spy(
|
||||
@@ -90,9 +86,9 @@ public class ConversionServiceParameterValueMapperTests {
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(
|
||||
conversionService);
|
||||
this.thrown.expect(ParameterMappingException.class);
|
||||
mapper.mapParameterValue(new TestOperationParameter(OffsetDateTime.class),
|
||||
"2011-12-03T10:15:30+01:00");
|
||||
assertThatExceptionOfType(ParameterMappingException.class).isThrownBy(() -> mapper
|
||||
.mapParameterValue(new TestOperationParameter(OffsetDateTime.class),
|
||||
"2011-12-03T10:15:30+01:00"));
|
||||
}
|
||||
|
||||
private static class TestOperationParameter implements OperationParameter {
|
||||
|
||||
@@ -25,9 +25,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
@@ -35,6 +33,8 @@ import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -44,9 +44,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class OperationMethodParametersTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
||||
String.class);
|
||||
|
||||
@@ -55,24 +52,25 @@ public class OperationMethodParametersTests {
|
||||
|
||||
@Test
|
||||
public void createWhenMethodIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Method must not be null");
|
||||
new OperationMethodParameters(null, mock(ParameterNameDiscoverer.class));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new OperationMethodParameters(null,
|
||||
mock(ParameterNameDiscoverer.class)))
|
||||
.withMessageContaining("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterNameDiscovererIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ParameterNameDiscoverer must not be null");
|
||||
new OperationMethodParameters(this.exampleMethod, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new OperationMethodParameters(this.exampleMethod, null))
|
||||
.withMessageContaining("ParameterNameDiscoverer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterNameDiscovererReturnsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Failed to extract parameter names");
|
||||
new OperationMethodParameters(this.exampleMethod,
|
||||
mock(ParameterNameDiscoverer.class));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new OperationMethodParameters(this.exampleMethod,
|
||||
mock(ParameterNameDiscoverer.class)))
|
||||
.withMessageContaining("Failed to extract parameter names");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,15 +18,14 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameters;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link OperationMethod}.
|
||||
@@ -35,24 +34,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class OperationMethodTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
||||
String.class);
|
||||
|
||||
@Test
|
||||
public void createWhenMethodIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Method must not be null");
|
||||
new OperationMethod(null, OperationType.READ);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new OperationMethod(null, OperationType.READ))
|
||||
.withMessageContaining("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenOperationTypeIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("OperationType must not be null");
|
||||
new OperationMethod(this.exampleMethod, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new OperationMethod(this.exampleMethod, null))
|
||||
.withMessageContaining("OperationType must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||
@@ -32,6 +30,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -41,9 +41,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ReflectiveOperationInvokerTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private Example target;
|
||||
|
||||
private OperationMethod operationMethod;
|
||||
@@ -62,24 +59,26 @@ public class ReflectiveOperationInvokerTests {
|
||||
|
||||
@Test
|
||||
public void createWhenTargetIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Target must not be null");
|
||||
new ReflectiveOperationInvoker(null, this.operationMethod,
|
||||
this.parameterValueMapper);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(null,
|
||||
this.operationMethod, this.parameterValueMapper))
|
||||
.withMessageContaining("Target must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenOperationMethodIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("OperationMethod must not be null");
|
||||
new ReflectiveOperationInvoker(this.target, null, this.parameterValueMapper);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target, null,
|
||||
this.parameterValueMapper))
|
||||
.withMessageContaining("OperationMethod must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ParameterValueMapper must not be null");
|
||||
new ReflectiveOperationInvoker(this.target, this.operationMethod, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target,
|
||||
this.operationMethod, null))
|
||||
.withMessageContaining("ParameterValueMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,9 +94,9 @@ public class ReflectiveOperationInvokerTests {
|
||||
public void invokeWhenMissingNonNullableArgumentShouldThrowException() {
|
||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target,
|
||||
this.operationMethod, this.parameterValueMapper);
|
||||
this.thrown.expect(MissingParametersException.class);
|
||||
invoker.invoke(new InvocationContext(mock(SecurityContext.class),
|
||||
Collections.singletonMap("name", null)));
|
||||
assertThatExceptionOfType(MissingParametersException.class).isThrownBy(
|
||||
() -> invoker.invoke(new InvocationContext(mock(SecurityContext.class),
|
||||
Collections.singletonMap("name", null))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,15 +21,14 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -43,14 +42,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
*/
|
||||
public class CachingOperationInvokerTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createInstanceWithTtlSetToZero() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TimeToLive");
|
||||
new CachingOperationInvoker(mock(OperationInvoker.class), 0);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new CachingOperationInvoker(mock(OperationInvoker.class), 0))
|
||||
.withMessageContaining("TimeToLive");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,9 +27,7 @@ import javax.management.MBeanException;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.ReflectionException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
@@ -38,7 +36,8 @@ import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -55,9 +54,6 @@ public class EndpointMBeanTests {
|
||||
|
||||
private static final String[] NO_SIGNATURE = {};
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(
|
||||
new TestJmxOperation());
|
||||
|
||||
@@ -65,16 +61,17 @@ public class EndpointMBeanTests {
|
||||
|
||||
@Test
|
||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ResponseMapper must not be null");
|
||||
new EndpointMBean(null, null, mock(ExposableJmxEndpoint.class));
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new EndpointMBean(null, null, mock(ExposableJmxEndpoint.class)))
|
||||
.withMessageContaining("ResponseMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEndpointIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Endpoint must not be null");
|
||||
new EndpointMBean(mock(JmxOperationResponseMapper.class), null, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointMBean(
|
||||
mock(JmxOperationResponseMapper.class), null, null))
|
||||
.withMessageContaining("Endpoint must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,10 +97,11 @@ public class EndpointMBeanTests {
|
||||
throw new FatalBeanException("test failure");
|
||||
}));
|
||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||
this.thrown.expect(MBeanException.class);
|
||||
this.thrown.expectCause(instanceOf(IllegalStateException.class));
|
||||
this.thrown.expectMessage("test failure");
|
||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
assertThatExceptionOfType(MBeanException.class)
|
||||
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||
.withCauseInstanceOf(IllegalStateException.class)
|
||||
.withMessageContaining("test failure");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,20 +112,21 @@ public class EndpointMBeanTests {
|
||||
throw new UnsupportedOperationException("test failure");
|
||||
}));
|
||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||
this.thrown.expect(MBeanException.class);
|
||||
this.thrown.expectCause(instanceOf(UnsupportedOperationException.class));
|
||||
this.thrown.expectMessage("test failure");
|
||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
assertThatExceptionOfType(MBeanException.class)
|
||||
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||
.withCauseInstanceOf(UnsupportedOperationException.class)
|
||||
.withMessageContaining("test failure");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenActionNameIsNotAnOperationShouldThrowException()
|
||||
throws MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
this.thrown.expect(ReflectionException.class);
|
||||
this.thrown.expectCause(instanceOf(IllegalArgumentException.class));
|
||||
this.thrown.expectMessage("no operation named missingOperation");
|
||||
bean.invoke("missingOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
assertThatExceptionOfType(ReflectionException.class)
|
||||
.isThrownBy(
|
||||
() -> bean.invoke("missingOperation", NO_PARAMS, NO_SIGNATURE))
|
||||
.withCauseInstanceOf(IllegalArgumentException.class)
|
||||
.withMessageContaining("no operation named missingOperation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,10 +158,10 @@ public class EndpointMBeanTests {
|
||||
};
|
||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(operation);
|
||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||
this.thrown.expect(ReflectionException.class);
|
||||
this.thrown.expectCause(instanceOf(IllegalArgumentException.class));
|
||||
this.thrown.expectMessage("test failure");
|
||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
assertThatExceptionOfType(ReflectionException.class)
|
||||
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||
.withRootCauseInstanceOf(IllegalArgumentException.class)
|
||||
.withMessageContaining("test failure");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,18 +188,18 @@ public class EndpointMBeanTests {
|
||||
public void getAttributeShouldThrowException()
|
||||
throws AttributeNotFoundException, MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
this.thrown.expect(AttributeNotFoundException.class);
|
||||
this.thrown.expectMessage("EndpointMBeans do not support attributes");
|
||||
bean.getAttribute("test");
|
||||
assertThatExceptionOfType(AttributeNotFoundException.class)
|
||||
.isThrownBy(() -> bean.getAttribute("test"))
|
||||
.withMessageContaining("EndpointMBeans do not support attributes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAttributeShouldThrowException() throws AttributeNotFoundException,
|
||||
InvalidAttributeValueException, MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
this.thrown.expect(AttributeNotFoundException.class);
|
||||
this.thrown.expectMessage("EndpointMBeans do not support attributes");
|
||||
bean.setAttribute(new Attribute("test", "test"));
|
||||
assertThatExceptionOfType(AttributeNotFoundException.class)
|
||||
.isThrownBy(() -> bean.setAttribute(new Attribute("test", "test")))
|
||||
.withMessageContaining("EndpointMBeans do not support attributes");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,9 +26,7 @@ import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -38,6 +36,9 @@ import org.springframework.jmx.JmxException;
|
||||
import org.springframework.jmx.export.MBeanExportException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
@@ -52,9 +53,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class JmxEndpointExporterTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private MBeanServer mBeanServer;
|
||||
|
||||
@@ -82,34 +80,34 @@ public class JmxEndpointExporterTests {
|
||||
|
||||
@Test
|
||||
public void createWhenMBeanServerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("MBeanServer must not be null");
|
||||
new JmxEndpointExporter(null, this.objectNameFactory, this.responseMapper,
|
||||
this.endpoints);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JmxEndpointExporter(null, this.objectNameFactory,
|
||||
this.responseMapper, this.endpoints))
|
||||
.withMessageContaining("MBeanServer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenObjectNameFactoryIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ObjectNameFactory must not be null");
|
||||
new JmxEndpointExporter(this.mBeanServer, null, this.responseMapper,
|
||||
this.endpoints);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer, null,
|
||||
this.responseMapper, this.endpoints))
|
||||
.withMessageContaining("ObjectNameFactory must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ResponseMapper must not be null");
|
||||
new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory, null,
|
||||
this.endpoints);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer,
|
||||
this.objectNameFactory, null, this.endpoints))
|
||||
.withMessageContaining("ResponseMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEndpointsIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Endpoints must not be null");
|
||||
new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory,
|
||||
this.responseMapper, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer,
|
||||
this.objectNameFactory, this.responseMapper, null))
|
||||
.withMessageContaining("Endpoints must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,9 +133,8 @@ public class JmxEndpointExporterTests {
|
||||
given(this.objectNameFactory.getObjectName(any(ExposableJmxEndpoint.class)))
|
||||
.willThrow(MalformedObjectNameException.class);
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Invalid ObjectName for endpoint 'test'");
|
||||
this.exporter.afterPropertiesSet();
|
||||
assertThatIllegalStateException().isThrownBy(this.exporter::afterPropertiesSet)
|
||||
.withMessageContaining("Invalid ObjectName for endpoint 'test'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,9 +142,9 @@ public class JmxEndpointExporterTests {
|
||||
given(this.mBeanServer.registerMBean(any(), any(ObjectName.class)))
|
||||
.willThrow(new MBeanRegistrationException(new RuntimeException()));
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.thrown.expect(MBeanExportException.class);
|
||||
this.thrown.expectMessage("Failed to register MBean for endpoint 'test");
|
||||
this.exporter.afterPropertiesSet();
|
||||
assertThatExceptionOfType(MBeanExportException.class)
|
||||
.isThrownBy(this.exporter::afterPropertiesSet)
|
||||
.withMessageContaining("Failed to register MBean for endpoint 'test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,9 +173,9 @@ public class JmxEndpointExporterTests {
|
||||
this.exporter.afterPropertiesSet();
|
||||
willThrow(new MBeanRegistrationException(new RuntimeException()))
|
||||
.given(this.mBeanServer).unregisterMBean(any(ObjectName.class));
|
||||
this.thrown.expect(JmxException.class);
|
||||
this.thrown.expectMessage("Failed to unregister MBean with ObjectName 'boot");
|
||||
this.exporter.destroy();
|
||||
assertThatExceptionOfType(JmxException.class)
|
||||
.isThrownBy(() -> this.exporter.destroy()).withMessageContaining(
|
||||
"Failed to unregister MBean with ObjectName 'boot");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,9 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@@ -49,6 +47,7 @@ import org.springframework.jmx.export.annotation.ManagedOperationParameters;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JmxEndpointDiscoverer}.
|
||||
@@ -58,9 +57,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class JmxEndpointDiscovererTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
load(EmptyConfiguration.class,
|
||||
@@ -113,13 +109,10 @@ public class JmxEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenJmxExtensionIsMissingEndpointShouldThrowException() {
|
||||
load(TestJmxEndpointExtension.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Invalid extension 'jmxEndpointDiscovererTests.TestJmxEndpointExtension': "
|
||||
+ "no endpoint found with id 'test'");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(TestJmxEndpointExtension.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Invalid extension 'jmxEndpointDiscovererTests.TestJmxEndpointExtension': no endpoint found with id 'test'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,51 +181,42 @@ public class JmxEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
load(ClashingJmxEndpointConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Found multiple extensions for the endpoint bean "
|
||||
+ "testEndpoint (testExtensionOne, testExtensionTwo)");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingJmxEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Found multiple extensions for the endpoint bean testEndpoint (testExtensionOne, testExtensionTwo)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingStandardEndpointConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingStandardEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Found two endpoints with the id 'test': "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingOperationsEndpoint.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
||||
+ "[MBean call 'getAll'] to jmxEndpointDiscovererTests.ClashingOperationsEndpoint");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingOperationsEndpoint.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to jmxEndpointDiscovererTests.ClashingOperationsEndpoint"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(AdditionalClashingOperationsConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
||||
+ "[MBean call 'getAll'] to testEndpoint (clashingOperationsJmxEndpointExtension)");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(AdditionalClashingOperationsConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to testEndpoint (clashingOperationsJmxEndpointExtension)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
load(InvalidJmxExtensionConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Endpoint bean 'nonJmxEndpoint' cannot support the "
|
||||
+ "extension bean 'nonJmxJmxEndpointExtension'");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(InvalidJmxExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Endpoint bean 'nonJmxEndpoint' cannot support the extension bean 'nonJmxJmxEndpointExtension'"));
|
||||
}
|
||||
|
||||
private Object getInvoker(JmxOperation operation) {
|
||||
|
||||
@@ -20,11 +20,10 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link EndpointMediaTypes}.
|
||||
@@ -33,21 +32,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class EndpointMediaTypesTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenProducedIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Produced must not be null");
|
||||
new EndpointMediaTypes(null, Collections.emptyList());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointMediaTypes(null, Collections.emptyList()))
|
||||
.withMessageContaining("Produced must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenConsumedIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Consumed must not be null");
|
||||
new EndpointMediaTypes(Collections.emptyList(), null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointMediaTypes(Collections.emptyList(), null))
|
||||
.withMessageContaining("Consumed must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,11 +27,10 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
@@ -42,21 +41,18 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
public class EndpointServletTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenServletClassIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Servlet must not be null");
|
||||
new EndpointServlet((Class<Servlet>) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointServlet((Class<Servlet>) null))
|
||||
.withMessageContaining("Servlet must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenServletIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Servlet must not be null");
|
||||
new EndpointServlet((Servlet) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointServlet((Servlet) null))
|
||||
.withMessageContaining("Servlet must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,15 +71,15 @@ public class EndpointServletTests {
|
||||
@Test
|
||||
public void withInitParameterNullName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
endpointServlet.withInitParameter(null, "value");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> endpointServlet.withInitParameter(null, "value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParameterEmptyName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
endpointServlet.withInitParameter(" ", "value");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> endpointServlet.withInitParameter(" ", "value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,15 +101,15 @@ public class EndpointServletTests {
|
||||
@Test
|
||||
public void withInitParametersNullName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
endpointServlet.withInitParameters(Collections.singletonMap(null, "value"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet
|
||||
.withInitParameters(Collections.singletonMap(null, "value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParametersEmptyName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
endpointServlet.withInitParameters(Collections.singletonMap(" ", "value"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet
|
||||
.withInitParameters(Collections.singletonMap(" ", "value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link Link}.
|
||||
@@ -29,14 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class LinkTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenHrefIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("HREF must not be null");
|
||||
new Link(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Link(null))
|
||||
.withMessageContaining("HREF must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,15 +20,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.EndpointsSupplier;
|
||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.Operation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -39,21 +38,20 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class PathMappedEndpointsTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenSupplierIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Supplier must not be null");
|
||||
new PathMappedEndpoints(null, (WebEndpointsSupplier) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> new PathMappedEndpoints(null, (WebEndpointsSupplier) null))
|
||||
.withMessageContaining("Supplier must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenSuppliersIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Suppliers must not be null");
|
||||
new PathMappedEndpoints(null, (Collection<EndpointsSupplier<?>>) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PathMappedEndpoints(null,
|
||||
(Collection<EndpointsSupplier<?>>) null))
|
||||
.withMessageContaining("Suppliers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,15 +27,14 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -50,9 +49,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class ServletEndpointRegistrarTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private ServletContext servletContext;
|
||||
|
||||
@@ -71,9 +67,9 @@ public class ServletEndpointRegistrarTests {
|
||||
|
||||
@Test
|
||||
public void createWhenServletEndpointsIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletEndpoints must not be null");
|
||||
new ServletEndpointRegistrar(null, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ServletEndpointRegistrar(null, null))
|
||||
.withMessageContaining("ServletEndpoints must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,9 +22,7 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||
@@ -41,6 +39,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link ControllerEndpointDiscoverer}.
|
||||
@@ -50,9 +49,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class ControllerEndpointDiscovererTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||
|
||||
@Test
|
||||
@@ -140,12 +136,10 @@ public class ControllerEndpointDiscovererTests {
|
||||
@Test
|
||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestControllerWithOperation.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"ControllerEndpoints must not declare operations");
|
||||
discoverer.getEndpoints();
|
||||
}));
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining(
|
||||
"ControllerEndpoints must not declare operations")));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||
|
||||
@@ -29,9 +29,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||
@@ -50,6 +48,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServletEndpointDiscoverer}.
|
||||
@@ -59,9 +58,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class ServletEndpointDiscovererTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||
|
||||
@Test
|
||||
@@ -116,43 +112,36 @@ public class ServletEndpointDiscovererTests {
|
||||
@Test
|
||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointWithOperation.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"ServletEndpoints must not declare operations");
|
||||
discoverer.getEndpoints();
|
||||
}));
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining(
|
||||
"ServletEndpoints must not declare operations")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointNotASupplierShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointNotASupplier.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("must be a supplier");
|
||||
discoverer.getEndpoints();
|
||||
}));
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("must be a supplier")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointSuppliesWrongTypeShouldThrowException() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestServletEndpointSupplierOfWrongType.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("must supply an EndpointServlet");
|
||||
discoverer.getEndpoints();
|
||||
}));
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining(
|
||||
"must supply an EndpointServlet")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointSuppliesNullShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointSupplierOfNull.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("must not supply null");
|
||||
discoverer.getEndpoints();
|
||||
}));
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("must not supply null")));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||
|
||||
@@ -29,9 +29,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@@ -58,6 +56,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebEndpointDiscoverer}.
|
||||
@@ -68,9 +67,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class WebEndpointDiscovererTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
load(EmptyConfiguration.class,
|
||||
@@ -79,13 +75,11 @@ public class WebEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWebExtensionIsMissingEndpointShouldThrowException() {
|
||||
load(TestWebEndpointExtensionConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Invalid extension 'endpointExtension': no endpoint found with id '"
|
||||
+ "test'");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(TestWebEndpointExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Invalid extension 'endpointExtension': no endpoint found with id '"
|
||||
+ "test'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,52 +134,49 @@ public class WebEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
load(ClashingWebEndpointConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Found multiple extensions for the endpoint bean "
|
||||
+ "testEndpoint (testExtensionOne, testExtensionTwo)");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingWebEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Found multiple extensions for the endpoint bean "
|
||||
+ "testEndpoint (testExtensionOne, testExtensionTwo)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingStandardEndpointConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingStandardEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Found two endpoints with the id 'test': "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingOperationsEndpointConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
||||
+ "[web request predicate GET to path 'test' "
|
||||
+ "produces: application/json] to clashingOperationsEndpoint");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingOperationsEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations: "
|
||||
+ "[web request predicate GET to path 'test' "
|
||||
+ "produces: application/json] to clashingOperationsEndpoint"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
load(InvalidWebExtensionConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Endpoint bean 'nonWebEndpoint' cannot support the "
|
||||
+ "extension bean 'nonWebWebEndpointExtension'");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(InvalidWebExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Endpoint bean 'nonWebEndpoint' cannot support the "
|
||||
+ "extension bean 'nonWebWebEndpointExtension'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingSelectorsWebEndpointExtensionConfiguration.class, (discoverer) -> {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations");
|
||||
this.thrown.expectMessage("to testEndpoint (clashingSelectorsExtension)");
|
||||
discoverer.getEndpoints();
|
||||
});
|
||||
load(ClashingSelectorsWebEndpointExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations")
|
||||
.withMessageContaining(
|
||||
"to testEndpoint (clashingSelectorsExtension)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.web.reactive;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
||||
@@ -36,6 +34,7 @@ import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.server.MethodNotAllowedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -47,9 +46,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@Test
|
||||
@@ -92,8 +88,8 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
public void mappingNarrowedToMethod() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||
this.thrown.expect(MethodNotAllowedException.class);
|
||||
getHandler(mapping, HttpMethod.POST, "/actuator/first");
|
||||
assertThatExceptionOfType(MethodNotAllowedException.class).isThrownBy(
|
||||
() -> getHandler(mapping, HttpMethod.POST, "/actuator/first"));
|
||||
}
|
||||
|
||||
private Object getHandler(ControllerEndpointHandlerMapping mapping, HttpMethod method,
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.web.servlet;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
||||
@@ -34,6 +32,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -45,9 +44,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@Test
|
||||
@@ -80,8 +76,8 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
public void mappingNarrowedToMethod() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||
this.thrown.expect(HttpRequestMethodNotSupportedException.class);
|
||||
mapping.getHandler(request("POST", "/actuator/first"));
|
||||
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class)
|
||||
.isThrownBy(() -> mapping.getHandler(request("POST", "/actuator/first")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,11 +19,11 @@ package org.springframework.boot.actuate.health;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -35,9 +35,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class DefaultHealthIndicatorRegistryTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private HealthIndicator one = mock(HealthIndicator.class);
|
||||
|
||||
private HealthIndicator two = mock(HealthIndicator.class);
|
||||
@@ -65,9 +62,10 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
@Test
|
||||
public void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("HealthIndicator with name 'one' already registered");
|
||||
this.registry.register("one", this.two);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining(
|
||||
"HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,9 +100,8 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
public void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||
|
||||
this.thrown.expect(UnsupportedOperationException.class);
|
||||
snapshot.clear();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(snapshot::clear);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ package org.springframework.boot.actuate.health;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -36,9 +36,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
||||
|
||||
private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class);
|
||||
@@ -66,9 +63,10 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
@Test
|
||||
public void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("HealthIndicator with name 'one' already registered");
|
||||
this.registry.register("one", this.two);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining(
|
||||
"HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,9 +101,8 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
public void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||
|
||||
this.thrown.expect(UnsupportedOperationException.class);
|
||||
snapshot.clear();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(snapshot::clear);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
@@ -36,14 +35,11 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
public class HealthTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void statusMustNotBeNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Status must not be null");
|
||||
new Health.Builder(null, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new Health.Builder(null, null))
|
||||
.withMessageContaining("Status must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.springframework.boot.actuate.info;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
@@ -30,15 +29,11 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
public class InfoTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void infoIsImmutable() {
|
||||
Info info = new Info.Builder().withDetail("foo", "bar").build();
|
||||
|
||||
this.thrown.expect(UnsupportedOperationException.class);
|
||||
info.getDetails().clear();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(info.getDetails()::clear);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.springframework.boot.actuate.info;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleInfoContributor}.
|
||||
@@ -29,13 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class SimpleInfoContributorTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void prefixIsMandatory() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
new SimpleInfoContributor(null, new Object());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SimpleInfoContributor(null, new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,13 +27,12 @@ import io.micrometer.core.instrument.Statistic;
|
||||
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleConfig;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link MetricsEndpoint}.
|
||||
@@ -43,9 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class MetricsEndpointTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT,
|
||||
new MockClock());
|
||||
|
||||
@@ -118,8 +114,8 @@ public class MetricsEndpointTests {
|
||||
|
||||
@Test
|
||||
public void metricWithInvalidTag() {
|
||||
this.thrown.expect(InvalidEndpointRequestException.class);
|
||||
this.endpoint.metric("counter", Collections.singletonList("key"));
|
||||
assertThatExceptionOfType(InvalidEndpointRequestException.class).isThrownBy(
|
||||
() -> this.endpoint.metric("counter", Collections.singletonList("key")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.actuate.system;
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -45,9 +43,6 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
|
||||
private static final DataSize TOTAL_SPACE = DataSize.ofKilobytes(10);
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private File fileMock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user