Migrate away from ExpectedException (#22922)

* Add limited checkstyles to test code

Add a limited set of checkstyle rules to the test codebase to improve
code consistency.

* Fix checksyle violations in test code

* Organize imports to fix checkstyle for test code

* Migrate to assertThatExceptionOfType

Migrate aware from ExpectedException rules to AssertJ exception
assertions. Also include a checkstyle rules to ensure that the
the ExpectedException is not accidentally used in the future.

See gh-22894
This commit is contained in:
Phil Webb
2019-05-08 07:25:52 -07:00
committed by Sam Brannen
parent 7e6e3d7027
commit d7320de871
671 changed files with 3861 additions and 4601 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,15 +25,14 @@ import java.util.Set;
import io.reactivex.Observable;
import io.reactivex.Single;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.tests.sample.objects.TestObject;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.*;
/**
@@ -44,10 +43,6 @@ import static org.junit.Assert.*;
*/
public class ConventionsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void simpleObject() {
assertEquals("Incorrect singular variable name",
@@ -76,8 +71,8 @@ public class ConventionsTests {
@Test
public void emptyList() {
this.exception.expect(IllegalArgumentException.class);
Conventions.getVariableName(new ArrayList<>());
assertThatIllegalArgumentException().isThrownBy(() ->
Conventions.getVariableName(new ArrayList<>()));
}
@Test

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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,6 +21,7 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.tests.sample.objects.TestObject;
import static org.junit.Assert.*;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -42,9 +42,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@@ -53,10 +51,11 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.ResolvableType.VariableResolver;
import org.springframework.util.MultiValueMap;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.*;
/**
@@ -70,9 +69,6 @@ import static org.mockito.BDDMockito.*;
@RunWith(MockitoJUnitRunner.class)
public class ResolvableTypeTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Captor
private ArgumentCaptor<TypeVariable<?>> typeVariableCaptor;
@@ -138,9 +134,9 @@ public class ResolvableTypeTests {
@Test
public void forInstanceMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Instance must not be null");
ResolvableType.forInstance(null);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forInstance(null))
.withMessageContaining("Instance must not be null");
}
@Test
@@ -191,9 +187,9 @@ public class ResolvableTypeTests {
@Test
public void forFieldMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Field must not be null");
ResolvableType.forField(null);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forField(null))
.withMessageContaining("Field must not be null");
}
@Test
@@ -205,9 +201,9 @@ public class ResolvableTypeTests {
@Test
public void forConstructorParameterMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Constructor must not be null");
ResolvableType.forConstructorParameter(null, 0);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forConstructorParameter(null, 0))
.withMessageContaining("Constructor must not be null");
}
@Test
@@ -219,9 +215,9 @@ public class ResolvableTypeTests {
@Test
public void forMethodParameterByIndexMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Method must not be null");
ResolvableType.forMethodParameter(null, 0);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodParameter(null, 0))
.withMessageContaining("Method must not be null");
}
@Test
@@ -257,9 +253,9 @@ public class ResolvableTypeTests {
@Test
public void forMethodParameterMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("MethodParameter must not be null");
ResolvableType.forMethodParameter(null);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodParameter(null))
.withMessageContaining("MethodParameter must not be null");
}
@Test // SPR-16210
@@ -284,9 +280,9 @@ public class ResolvableTypeTests {
@Test
public void forMethodReturnMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Method must not be null");
ResolvableType.forMethodReturnType(null);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodReturnType(null))
.withMessageContaining("Method must not be null");
}
@Test
@@ -963,9 +959,9 @@ public class ResolvableTypeTests {
@Test
public void isAssignableFromMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null");
ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
.withMessageContaining("Type must not be null");
}
@Test
@@ -1226,9 +1222,9 @@ public class ResolvableTypeTests {
@Test
public void forClassWithMismatchedGenerics() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Mismatched number of generics specified");
ResolvableType.forClassWithGenerics(Map.class, Integer.class);
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forClassWithGenerics(Map.class, Integer.class))
.withMessageContaining("Mismatched number of generics specified");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -31,7 +31,7 @@ import java.util.List;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

View File

@@ -35,11 +35,13 @@ import javax.annotation.Resource;
import javax.annotation.meta.When;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.ArrayComparisonFailure;
import org.junit.rules.ExpectedException;
import org.springframework.core.annotation.AnnotationUtilsTests.ExtendsBaseClassWithGenericAnnotatedMethod;
import org.springframework.core.annotation.AnnotationUtilsTests.ImplementsInterfaceWithGenericAnnotatedMethod;
import org.springframework.core.annotation.AnnotationUtilsTests.WebController;
import org.springframework.core.annotation.AnnotationUtilsTests.WebMapping;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
@@ -48,8 +50,8 @@ import org.springframework.util.MultiValueMap;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.core.annotation.AnnotatedElementUtils.*;
import static org.springframework.core.annotation.AnnotationUtilsTests.*;
@@ -69,9 +71,6 @@ public class AnnotatedElementUtilsTests {
private static final String TX_NAME = Transactional.class.getName();
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void getMetaAnnotationTypesOnNonAnnotatedClass() {
@@ -512,16 +511,11 @@ public class AnnotatedElementUtilsTests {
@Test
public void getMergedAnnotationAttributesWithInvalidConventionBasedComposedAnnotation() {
Class<?> element = InvalidConventionBasedComposedContextConfigClass.class;
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(either(containsString("attribute 'value' and its alias 'locations'")).or(
containsString("attribute 'locations' and its alias 'value'")));
exception.expectMessage(either(
containsString("values of [{duplicateDeclaration}] and [{requiredLocationsDeclaration}]")).or(
containsString("values of [{requiredLocationsDeclaration}] and [{duplicateDeclaration}]")));
exception.expectMessage(either(
containsString("but only one is permitted")).or(
containsString("Different @AliasFor mirror values for annotation")));
getMergedAnnotationAttributes(element, ContextConfig.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
getMergedAnnotationAttributes(element, ContextConfig.class))
.withMessageContaining("Different @AliasFor mirror values for annotation")
.withMessageContaining("attribute 'locations' and its alias 'value'")
.withMessageContaining("values of [{requiredLocationsDeclaration}] and [{duplicateDeclaration}]");
}
@Test

View File

@@ -21,12 +21,11 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.annotation.AnnotationUtilsTests.ImplicitAliasesContextConfig;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -43,9 +42,6 @@ public class AnnotationAttributesTests {
private AnnotationAttributes attributes = new AnnotationAttributes();
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void typeSafeAttributeAccess() {
@@ -80,9 +76,9 @@ public class AnnotationAttributesTests {
@Test
public void unresolvableClass() throws Exception {
attributes.put("unresolvableClass", new ClassNotFoundException("myclass"));
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("myclass"));
attributes.getClass("unresolvableClass");
assertThatIllegalArgumentException().isThrownBy(() ->
attributes.getClass("unresolvableClass"))
.withMessageContaining("myclass");
}
@Test
@@ -132,31 +128,31 @@ public class AnnotationAttributesTests {
@Test
public void getEnumWithNullAttributeName() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("must not be null or empty");
attributes.getEnum(null);
assertThatIllegalArgumentException().isThrownBy(() ->
attributes.getEnum(null))
.withMessageContaining("must not be null or empty");
}
@Test
public void getEnumWithEmptyAttributeName() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("must not be null or empty");
attributes.getEnum("");
assertThatIllegalArgumentException().isThrownBy(() ->
attributes.getEnum(""))
.withMessageContaining("must not be null or empty");
}
@Test
public void getEnumWithUnknownAttributeName() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Attribute 'bogus' not found");
attributes.getEnum("bogus");
assertThatIllegalArgumentException().isThrownBy(() ->
attributes.getEnum("bogus"))
.withMessageContaining("Attribute 'bogus' not found");
}
@Test
public void getEnumWithTypeMismatch() {
attributes.put("color", "RED");
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("Attribute 'color' is of type String, but Enum was expected"));
attributes.getEnum("color");
assertThatIllegalArgumentException().isThrownBy(() ->
attributes.getEnum("color"))
.withMessageContaining("Attribute 'color' is of type String, but Enum was expected");
}
@Test

View File

@@ -21,7 +21,7 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
/**
* Tests to ensure back-compatibility with Spring Framework 5.1.

View File

@@ -49,9 +49,9 @@ public class AnnotationIntrospectionFailureTests {
Annotation annotation = withExampleAnnotation.getAnnotations()[0];
Method method = annotation.annotationType().getMethod("value");
method.setAccessible(true);
assertThatExceptionOfType(TypeNotPresentException.class).isThrownBy(() -> {
ReflectionUtils.invokeMethod(method, annotation);
}).withCauseInstanceOf(ClassNotFoundException.class);
assertThatExceptionOfType(TypeNotPresentException.class).isThrownBy(() ->
ReflectionUtils.invokeMethod(method, annotation))
.withCauseInstanceOf(ClassNotFoundException.class);
}
@Test

View File

@@ -98,46 +98,42 @@ public class AnnotationTypeMappingsTests {
@Test
public void forAnnotationTypeWhenHasAliasForWithBothValueAndAttributeThrowsException() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForWithBothValueAndAttribute.class)).withMessage(
"In @AliasFor declared on attribute 'test' in annotation ["
+ AliasForWithBothValueAndAttribute.class.getName()
+ "], attribute 'attribute' and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForWithBothValueAndAttribute.class))
.withMessage("In @AliasFor declared on attribute 'test' in annotation ["
+ AliasForWithBothValueAndAttribute.class.getName()
+ "], attribute 'attribute' and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted.");
}
@Test
public void forAnnotationTypeWhenAliasForToSelfNonExistingAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForToSelfNonExistingAttribute.class)).withMessage(
"@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelfNonExistingAttribute.class.getName()
+ "] declares an alias for 'missing' which is not present.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelfNonExistingAttribute.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelfNonExistingAttribute.class.getName()
+ "] declares an alias for 'missing' which is not present.");
}
@Test
public void forAnnotationTypeWhenAliasForToOtherNonExistingAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForToOtherNonExistingAttribute.class)).withMessage(
"Attribute 'test' in annotation ["
+ AliasForToOtherNonExistingAttribute.class.getName()
+ "] is declared as an @AliasFor nonexistent "
+ "attribute 'missing' in annotation ["
+ AliasForToOtherNonExistingAttributeTarget.class.getName()
+ "].");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToOtherNonExistingAttribute.class))
.withMessage("Attribute 'test' in annotation ["
+ AliasForToOtherNonExistingAttribute.class.getName()
+ "] is declared as an @AliasFor nonexistent "
+ "attribute 'missing' in annotation ["
+ AliasForToOtherNonExistingAttributeTarget.class.getName()
+ "].");
}
@Test
public void forAnnotationTypeWhenAliasForToSelf() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForToSelf.class)).withMessage(
"@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelf.class.getName()
+ "] points to itself. Specify 'annotation' to point to "
+ "a same-named attribute on a meta-annotation.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelf.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelf.class.getName()
+ "] points to itself. Specify 'annotation' to point to "
+ "a same-named attribute on a meta-annotation.");
}
@Test
@@ -151,82 +147,75 @@ public class AnnotationTypeMappingsTests {
@Test
public void forAnnotationTypeWhenAliasForWithIncompatibleReturnTypes() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForWithIncompatibleReturnTypes.class)).withMessage(
"Misconfigured aliases: attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypes.class.getName()
+ "] and attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypesTarget.class.getName()
+ "] must declare the same return type.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForWithIncompatibleReturnTypes.class))
.withMessage("Misconfigured aliases: attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypes.class.getName()
+ "] and attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypesTarget.class.getName()
+ "] must declare the same return type.");
}
@Test
public void forAnnotationTypeWhenAliasForToSelfNonAnnotatedAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForToSelfNonAnnotatedAttribute.class)).withMessage(
"Attribute 'other' in annotation ["
+ AliasForToSelfNonAnnotatedAttribute.class.getName()
+ "] must be declared as an @AliasFor 'test'.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelfNonAnnotatedAttribute.class))
.withMessage("Attribute 'other' in annotation ["
+ AliasForToSelfNonAnnotatedAttribute.class.getName()
+ "] must be declared as an @AliasFor 'test'.");
}
@Test
public void forAnnotationTypeWhenAliasForToSelfAnnotatedToOtherAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForToSelfAnnotatedToOtherAttribute.class)).withMessage(
"Attribute 'b' in annotation ["
+ AliasForToSelfAnnotatedToOtherAttribute.class.getName()
+ "] must be declared as an @AliasFor 'a', not 'c'.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelfAnnotatedToOtherAttribute.class))
.withMessage("Attribute 'b' in annotation ["
+ AliasForToSelfAnnotatedToOtherAttribute.class.getName()
+ "] must be declared as an @AliasFor 'a', not 'c'.");
}
@Test
public void forAnnotationTypeWhenAliasForNonMetaAnnotated() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForNonMetaAnnotated.class)).withMessage(
"@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForNonMetaAnnotated.class.getName()
+ "] declares an alias for attribute 'test' in annotation ["
+ AliasForNonMetaAnnotatedTarget.class.getName()
+ "] which is not meta-present.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForNonMetaAnnotated.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForNonMetaAnnotated.class.getName()
+ "] declares an alias for attribute 'test' in annotation ["
+ AliasForNonMetaAnnotatedTarget.class.getName()
+ "] which is not meta-present.");
}
@Test
public void forAnnotationTypeWhenAliasForSelfWithDifferentDefaults() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForSelfWithDifferentDefaults.class)).withMessage(
"Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] must declare the same default value.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForSelfWithDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] must declare the same default value.");
}
@Test
public void forAnnotationTypeWhenAliasForSelfWithMissingDefault() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasForSelfWithMissingDefault.class)).withMessage(
"Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] must declare default values.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForSelfWithMissingDefault.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] must declare default values.");
}
@Test
public void forAnnotationTypeWhenAliasWithExplicitMirrorAndDifferentDefaults() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> AnnotationTypeMappings.forAnnotationType(
AliasWithExplicitMirrorAndDifferentDefaults.class)).withMessage(
"Misconfigured aliases: attribute 'a' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] and attribute 'c' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] must declare the same default value.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasWithExplicitMirrorAndDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] and attribute 'c' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] must declare the same default value.");
}
@Test
@@ -399,13 +388,12 @@ public class AnnotationTypeMappingsTests {
public void resolveMirrorsWhenHasDifferentValuesThrowsException() {
AnnotationTypeMapping mapping = AnnotationTypeMappings.forAnnotationType(
AliasPair.class).get(0);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> resolveMirrorSets(mapping, WithDifferentValueAliasPair.class,
AliasPair.class)).withMessage(
"Different @AliasFor mirror values for annotation ["
+ AliasPair.class.getName() + "] declared on "
+ WithDifferentValueAliasPair.class.getName()
+ ", attribute 'a' and its alias 'b' are declared with values of [test1] and [test2].");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
resolveMirrorSets(mapping, WithDifferentValueAliasPair.class, AliasPair.class))
.withMessage("Different @AliasFor mirror values for annotation ["
+ AliasPair.class.getName() + "] declared on "
+ WithDifferentValueAliasPair.class.getName()
+ ", attribute 'a' and its alias 'b' are declared with values of [test1] and [test2].");
}
@Test

View File

@@ -33,9 +33,7 @@ import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
@@ -44,6 +42,7 @@ import org.springframework.stereotype.Component;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.*;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.core.annotation.AnnotationUtils.*;
@@ -61,10 +60,6 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
@SuppressWarnings("deprecation")
public class AnnotationUtilsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Before
public void clearCacheBeforeTests() {
AnnotationUtils.clearCache();
@@ -497,13 +492,12 @@ public class AnnotationUtilsTests {
@Test
public void getAnnotationAttributesWithAttributeAliasesWithDifferentValues() throws Exception {
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(containsString("attribute 'path' and its alias 'value'"));
exception.expectMessage(containsString("values of [{/test}] and [{/enigma}]"));
Method method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes");
WebMapping webMapping = method.getAnnotation(WebMapping.class);
getAnnotationAttributes(webMapping);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
getAnnotationAttributes(webMapping))
.withMessageContaining("attribute 'path' and its alias 'value'")
.withMessageContaining("values of [{/test}] and [{/enigma}]");
}
@Test
@@ -570,14 +564,12 @@ public class AnnotationUtilsTests {
@Test
public void getRepeatableAnnotationsDeclaredOnClassWithMissingAttributeAliasDeclaration() throws Exception {
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Attribute 'value' in"));
exception.expectMessage(containsString(BrokenContextConfig.class.getName()));
exception.expectMessage(either(
containsString("@AliasFor [location]")).or(
containsString("@AliasFor 'location'")));
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
getRepeatableAnnotations(BrokenConfigHierarchyTestCase.class, BrokenContextConfig.class, BrokenHierarchy.class))
.withMessageStartingWith("Attribute 'value' in")
.withMessageContaining(BrokenContextConfig.class.getName())
.withMessageContaining("@AliasFor 'location'");
getRepeatableAnnotations(BrokenConfigHierarchyTestCase.class, BrokenContextConfig.class, BrokenHierarchy.class);
}
@Test
@@ -748,13 +740,12 @@ public class AnnotationUtilsTests {
ImplicitAliasesWithMissingDefaultValuesContextConfig config = clazz.getAnnotation(annotationType);
assertNotNull(config);
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Misconfigured aliases:"));
exception.expectMessage(containsString("attribute 'location1' in annotation [" + annotationType.getName() + "]"));
exception.expectMessage(containsString("attribute 'location2' in annotation [" + annotationType.getName() + "]"));
exception.expectMessage(containsString("default values"));
synthesizeAnnotation(config, clazz);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
synthesizeAnnotation(config, clazz))
.withMessageStartingWith("Misconfigured aliases:")
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("default values");
}
@Test
@@ -763,14 +754,12 @@ public class AnnotationUtilsTests {
Class<ImplicitAliasesWithDifferentDefaultValuesContextConfig> annotationType = ImplicitAliasesWithDifferentDefaultValuesContextConfig.class;
ImplicitAliasesWithDifferentDefaultValuesContextConfig config = clazz.getAnnotation(annotationType);
assertNotNull(config);
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Misconfigured aliases:"));
exception.expectMessage(containsString("attribute 'location1' in annotation [" + annotationType.getName() + "]"));
exception.expectMessage(containsString("attribute 'location2' in annotation [" + annotationType.getName() + "]"));
exception.expectMessage(containsString("same default value"));
synthesizeAnnotation(config, clazz);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
synthesizeAnnotation(config, clazz))
.withMessageStartingWith("Misconfigured aliases:")
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("same default value");
}
@Test
@@ -780,16 +769,14 @@ public class AnnotationUtilsTests {
ImplicitAliasesWithDuplicateValuesContextConfig config = clazz.getAnnotation(annotationType);
assertNotNull(config);
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(either(startsWith("In annotation")).or(startsWith("Different @AliasFor mirror values")));
exception.expectMessage(containsString(annotationType.getName()));
exception.expectMessage(containsString("declared on class"));
exception.expectMessage(containsString(clazz.getName()));
exception.expectMessage(either(containsString("attribute 'location1' and its alias 'location2'")).or(
containsString("attribute 'location2' and its alias 'location1'")));
exception.expectMessage(either(containsString("with values of [1] and [2]")).or(
containsString("with values of [2] and [1]")));
synthesizeAnnotation(config, clazz).location1();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
synthesizeAnnotation(config, clazz).location1())
.withMessageStartingWith("Different @AliasFor mirror values")
.withMessageContaining(annotationType.getName())
.withMessageContaining("declared on class")
.withMessageContaining(clazz.getName())
.withMessageContaining("attribute 'location1' and its alias 'location2'")
.withMessageContaining("with values of [1] and [2]");
}
@Test
@@ -940,22 +927,18 @@ public class AnnotationUtilsTests {
}
private void assertMissingTextAttribute(Map<String, Object> attributes) {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(either(allOf(startsWith("Attributes map"),
containsString("returned null for required attribute 'text'"),
containsString("defined by annotation type [" + AnnotationWithoutDefaults.class.getName() + "]"))).or(
containsString("No value found for attribute named 'text' in merged annotation")));
synthesizeAnnotation(attributes, AnnotationWithoutDefaults.class, null);
assertThatIllegalArgumentException().isThrownBy(() ->
synthesizeAnnotation(attributes, AnnotationWithoutDefaults.class, null))
.withMessageContaining("No value found for attribute named 'text' in merged annotation");
}
@Test
public void synthesizeAnnotationFromMapWithAttributeOfIncorrectType() throws Exception {
Map<String, Object> map = Collections.singletonMap(VALUE, 42L);
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString(
"Attribute 'value' in annotation org.springframework.stereotype.Component " +
"should be compatible with java.lang.String but a java.lang.Long value was returned"));
synthesizeAnnotation(map, Component.class, null);
assertThatIllegalArgumentException().isThrownBy(() ->
synthesizeAnnotation(map, Component.class, null))
.withMessageContaining("Attribute 'value' in annotation org.springframework.stereotype.Component "
+ "should be compatible with java.lang.String but a java.lang.Long value was returned");
}
@Test

View File

@@ -157,8 +157,8 @@ public class AttributeMethodsTests {
given(annotation.value()).willThrow(TypeNotPresentException.class);
AttributeMethods attributes = AttributeMethods.forAnnotationType(
annotation.annotationType());
assertThatIllegalStateException().isThrownBy(
() -> attributes.validate(annotation));
assertThatIllegalStateException().isThrownBy(() ->
attributes.validate(annotation));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -26,13 +26,10 @@ import java.lang.reflect.AnnotatedElement;
import java.util.Iterator;
import java.util.Set;
import org.junit.Rule;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.CoreMatchers.isA;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.springframework.core.annotation.AnnotatedElementUtils.*;
@@ -51,33 +48,29 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.*;
*/
public class ComposedRepeatableAnnotationsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void getNonRepeatableAnnotation() {
expectNonRepeatableAnnotation();
getMergedRepeatableAnnotations(getClass(), NonRepeatable.class);
expectNonRepeatableAnnotation(() ->
getMergedRepeatableAnnotations(getClass(), NonRepeatable.class));
}
@Test
public void getInvalidRepeatableAnnotationContainerMissingValueAttribute() {
expectContainerMissingValueAttribute();
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerMissingValueAttribute.class);
expectContainerMissingValueAttribute(() ->
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerMissingValueAttribute.class));
}
@Test
public void getInvalidRepeatableAnnotationContainerWithNonArrayValueAttribute() {
expectContainerWithNonArrayValueAttribute();
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerWithNonArrayValueAttribute.class);
expectContainerWithNonArrayValueAttribute(() ->
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerWithNonArrayValueAttribute.class));
}
@Test
public void getInvalidRepeatableAnnotationContainerWithArrayValueAttributeButWrongComponentType() {
expectContainerWithArrayValueAttributeButWrongComponentType();
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class,
ContainerWithArrayValueAttributeButWrongComponentType.class);
expectContainerWithArrayValueAttributeButWrongComponentType(() ->
getMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerWithArrayValueAttributeButWrongComponentType.class));
}
@Test
@@ -122,27 +115,27 @@ public class ComposedRepeatableAnnotationsTests {
@Test
public void findNonRepeatableAnnotation() {
expectNonRepeatableAnnotation();
findMergedRepeatableAnnotations(getClass(), NonRepeatable.class);
expectNonRepeatableAnnotation(() ->
findMergedRepeatableAnnotations(getClass(), NonRepeatable.class));
}
@Test
public void findInvalidRepeatableAnnotationContainerMissingValueAttribute() {
expectContainerMissingValueAttribute();
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerMissingValueAttribute.class);
expectContainerMissingValueAttribute(() ->
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerMissingValueAttribute.class));
}
@Test
public void findInvalidRepeatableAnnotationContainerWithNonArrayValueAttribute() {
expectContainerWithNonArrayValueAttribute();
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerWithNonArrayValueAttribute.class);
expectContainerWithNonArrayValueAttribute(() ->
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class, ContainerWithNonArrayValueAttribute.class));
}
@Test
public void findInvalidRepeatableAnnotationContainerWithArrayValueAttributeButWrongComponentType() {
expectContainerWithArrayValueAttributeButWrongComponentType();
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class,
ContainerWithArrayValueAttributeButWrongComponentType.class);
expectContainerWithArrayValueAttributeButWrongComponentType(() ->
findMergedRepeatableAnnotations(getClass(), InvalidRepeatable.class,
ContainerWithArrayValueAttributeButWrongComponentType.class));
}
@Test
@@ -184,36 +177,36 @@ public class ComposedRepeatableAnnotationsTests {
assertFindRepeatableAnnotations(ComposedContainerClass.class);
}
private void expectNonRepeatableAnnotation() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Annotation type must be a repeatable annotation"));
exception.expectMessage(containsString("failed to resolve container type for"));
exception.expectMessage(containsString(NonRepeatable.class.getName()));
private void expectNonRepeatableAnnotation(ThrowingCallable throwingCallable) {
assertThatIllegalArgumentException().isThrownBy(throwingCallable)
.withMessageStartingWith("Annotation type must be a repeatable annotation")
.withMessageContaining("failed to resolve container type for")
.withMessageContaining(NonRepeatable.class.getName());
}
private void expectContainerMissingValueAttribute() {
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Invalid declaration of container type"));
exception.expectMessage(containsString(ContainerMissingValueAttribute.class.getName()));
exception.expectMessage(containsString("for repeatable annotation"));
exception.expectMessage(containsString(InvalidRepeatable.class.getName()));
exception.expectCause(isA(NoSuchMethodException.class));
private void expectContainerMissingValueAttribute(ThrowingCallable throwingCallable) {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(throwingCallable)
.withMessageStartingWith("Invalid declaration of container type")
.withMessageContaining(ContainerMissingValueAttribute.class.getName())
.withMessageContaining("for repeatable annotation")
.withMessageContaining(InvalidRepeatable.class.getName())
.withCauseExactlyInstanceOf(NoSuchMethodException.class);
}
private void expectContainerWithNonArrayValueAttribute() {
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Container type"));
exception.expectMessage(containsString(ContainerWithNonArrayValueAttribute.class.getName()));
exception.expectMessage(containsString("must declare a 'value' attribute for an array of type"));
exception.expectMessage(containsString(InvalidRepeatable.class.getName()));
private void expectContainerWithNonArrayValueAttribute(ThrowingCallable throwingCallable) {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(throwingCallable)
.withMessageStartingWith("Container type")
.withMessageContaining(ContainerWithNonArrayValueAttribute.class.getName())
.withMessageContaining("must declare a 'value' attribute for an array of type")
.withMessageContaining(InvalidRepeatable.class.getName());
}
private void expectContainerWithArrayValueAttributeButWrongComponentType() {
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(startsWith("Container type"));
exception.expectMessage(containsString(ContainerWithArrayValueAttributeButWrongComponentType.class.getName()));
exception.expectMessage(containsString("must declare a 'value' attribute for an array of type"));
exception.expectMessage(containsString(InvalidRepeatable.class.getName()));
private void expectContainerWithArrayValueAttributeButWrongComponentType(ThrowingCallable throwingCallable) {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(throwingCallable)
.withMessageStartingWith("Container type")
.withMessageContaining(ContainerWithArrayValueAttributeButWrongComponentType.class.getName())
.withMessageContaining("must declare a 'value' attribute for an array of type")
.withMessageContaining(InvalidRepeatable.class.getName());
}
private void assertGetRepeatableAnnotations(AnnotatedElement element) {

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.core.OverridingClassLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
/**
* Tests for {@link MergedAnnotation} to ensure the correct class loader is

View File

@@ -101,8 +101,8 @@ public class MergedAnnotationPredicatesTests {
@Test
public void firstRunOfWhenValueExtractorIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> MergedAnnotationPredicates.firstRunOf(null));
assertThatIllegalArgumentException().isThrownBy(() ->
MergedAnnotationPredicates.firstRunOf(null));
}
@Test
@@ -117,8 +117,8 @@ public class MergedAnnotationPredicatesTests {
@Test
public void uniqueWhenKeyExtractorIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> MergedAnnotationPredicates.unique(null));
assertThatIllegalArgumentException().isThrownBy(() ->
MergedAnnotationPredicates.unique(null));
}
private char firstCharOfValue(MergedAnnotation<TestAnnotation> annotation) {

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -53,9 +53,9 @@ public class MergedAnnotationsCollectionTests {
public void createWhenAnnotationIsNotDirectlyPresentThrowsException() {
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
given(annotation.isDirectlyPresent()).willReturn(false);
assertThatIllegalArgumentException().isThrownBy(() -> {
MergedAnnotationsCollection.of(Collections.singleton(annotation));
}).withMessage("Annotation must be directly present");
assertThatIllegalArgumentException().isThrownBy(() ->
MergedAnnotationsCollection.of(Collections.singleton(annotation)))
.withMessage("Annotation must be directly present");
}
@Test
@@ -63,9 +63,9 @@ public class MergedAnnotationsCollectionTests {
MergedAnnotation<?> annotation = mock(MergedAnnotation.class);
given(annotation.isDirectlyPresent()).willReturn(true);
given(annotation.getAggregateIndex()).willReturn(1);
assertThatIllegalArgumentException().isThrownBy(() -> {
MergedAnnotationsCollection.of(Collections.singleton(annotation));
}).withMessage("Annotation must have aggregate index of zero");
assertThatIllegalArgumentException().isThrownBy(() ->
MergedAnnotationsCollection.of(Collections.singleton(annotation)))
.withMessage("Annotation must have aggregate index of zero");
}
@Test

View File

@@ -27,15 +27,11 @@ import java.lang.reflect.AnnotatedElement;
import java.util.Set;
import org.assertj.core.api.ThrowableTypeAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
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.*;
/**
* Tests for {@link MergedAnnotations} and {@link RepeatableContainers} that
@@ -48,39 +44,35 @@ public class MergedAnnotationsRepeatableAnnotationTests {
// See SPR-13973
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void inheritedAnnotationsWhenNonRepeatableThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> getAnnotations(null, NonRepeatable.class,
SearchStrategy.INHERITED_ANNOTATIONS, getClass())).satisfies(
this::nonRepeatableRequirements);
assertThatIllegalArgumentException().isThrownBy(() ->
getAnnotations(null, NonRepeatable.class, SearchStrategy.INHERITED_ANNOTATIONS, getClass()))
.satisfies(this::nonRepeatableRequirements);
}
@Test
public void inheritedAnnotationsWhenContainerMissingValueAttributeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(
() -> getAnnotations(ContainerMissingValueAttribute.class,
InvalidRepeatable.class, SearchStrategy.INHERITED_ANNOTATIONS,
getClass())).satisfies(this::missingValueAttributeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerMissingValueAttribute.class, InvalidRepeatable.class,
SearchStrategy.INHERITED_ANNOTATIONS, getClass()))
.satisfies(this::missingValueAttributeRequirements);
}
@Test
public void inheritedAnnotationsWhenWhenNonArrayValueAttributeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(
() -> getAnnotations(ContainerWithNonArrayValueAttribute.class,
InvalidRepeatable.class, SearchStrategy.INHERITED_ANNOTATIONS,
getClass())).satisfies(this::nonArrayValueAttributeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerWithNonArrayValueAttribute.class, InvalidRepeatable.class,
SearchStrategy.INHERITED_ANNOTATIONS, getClass()))
.satisfies(this::nonArrayValueAttributeRequirements);
}
@Test
public void inheritedAnnotationsWhenWrongComponentTypeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(() -> getAnnotations(
ContainerWithArrayValueAttributeButWrongComponentType.class,
InvalidRepeatable.class, SearchStrategy.INHERITED_ANNOTATIONS,
getClass())).satisfies(this::wrongComponentTypeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerWithArrayValueAttributeButWrongComponentType.class,
InvalidRepeatable.class, SearchStrategy.INHERITED_ANNOTATIONS, getClass()))
.satisfies(this::wrongComponentTypeRequirements);
}
@Test
@@ -142,33 +134,33 @@ public class MergedAnnotationsRepeatableAnnotationTests {
@Test
public void exhaustiveWhenNonRepeatableThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> getAnnotations(null,
NonRepeatable.class, SearchStrategy.EXHAUSTIVE, getClass())).satisfies(
this::nonRepeatableRequirements);
assertThatIllegalArgumentException().isThrownBy(() ->
getAnnotations(null, NonRepeatable.class, SearchStrategy.EXHAUSTIVE, getClass()))
.satisfies(this::nonRepeatableRequirements);
}
@Test
public void exhaustiveWhenContainerMissingValueAttributeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(
() -> getAnnotations(ContainerMissingValueAttribute.class,
InvalidRepeatable.class, SearchStrategy.EXHAUSTIVE,
getClass())).satisfies(this::missingValueAttributeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerMissingValueAttribute.class, InvalidRepeatable.class,
SearchStrategy.EXHAUSTIVE, getClass()))
.satisfies(this::missingValueAttributeRequirements);
}
@Test
public void exhaustiveWhenWhenNonArrayValueAttributeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(
() -> getAnnotations(ContainerWithNonArrayValueAttribute.class,
InvalidRepeatable.class, SearchStrategy.EXHAUSTIVE,
getClass())).satisfies(this::nonArrayValueAttributeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerWithNonArrayValueAttribute.class, InvalidRepeatable.class,
SearchStrategy.EXHAUSTIVE, getClass()))
.satisfies(this::nonArrayValueAttributeRequirements);
}
@Test
public void exhaustiveWhenWrongComponentTypeThrowsException() {
assertThatAnnotationConfigurationException().isThrownBy(() -> getAnnotations(
ContainerWithArrayValueAttributeButWrongComponentType.class,
InvalidRepeatable.class, SearchStrategy.EXHAUSTIVE,
getClass())).satisfies(this::wrongComponentTypeRequirements);
assertThatAnnotationConfigurationException().isThrownBy(() ->
getAnnotations(ContainerWithArrayValueAttributeButWrongComponentType.class,
InvalidRepeatable.class, SearchStrategy.EXHAUSTIVE, getClass()))
.satisfies(this::wrongComponentTypeRequirements);
}
@Test
@@ -246,7 +238,6 @@ public class MergedAnnotationsRepeatableAnnotationTests {
}
private void missingValueAttributeRequirements(Exception ex) {
ex.printStackTrace();
assertThat(ex.getMessage()).startsWith(
"Invalid declaration of container type").contains(
ContainerMissingValueAttribute.class.getName(),

View File

@@ -441,11 +441,9 @@ public class MergedAnnotationsTests {
@Test
public void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotations.from(
InvalidConventionBasedComposedContextConfigurationClass.class,
SearchStrategy.INHERITED_ANNOTATIONS).get(
ContextConfiguration.class));
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
}
@Test
@@ -1215,11 +1213,10 @@ public class MergedAnnotationsTests {
@Test
public void getDirectWithAttributeAliasesWithDifferentValues() throws Exception {
Method method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotations.from(method).get(
RequestMapping.class)).withMessageContaining(
"attribute 'path' and its alias 'value'").withMessageContaining(
"values of [{/test}] and [{/enigma}]");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotations.from(method).get(RequestMapping.class))
.withMessageContaining("attribute 'path' and its alias 'value'")
.withMessageContaining("values of [{/test}] and [{/enigma}]");
}
@Test
@@ -1281,14 +1278,12 @@ public class MergedAnnotationsTests {
public void getRepeatableDeclaredOnClassWithMissingAttributeAliasDeclaration() {
RepeatableContainers containers = RepeatableContainers.of(
BrokenContextConfiguration.class, BrokenHierarchy.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotations.from(BrokenHierarchyClass.class,
SearchStrategy.EXHAUSTIVE, containers,
AnnotationFilter.PLAIN).get(
BrokenHierarchy.class)).withMessageStartingWith(
"Attribute 'value' in").withMessageContaining(
BrokenContextConfiguration.class.getName()).withMessageContaining(
"@AliasFor 'location'");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotations.from(BrokenHierarchyClass.class, SearchStrategy.EXHAUSTIVE, containers,
AnnotationFilter.PLAIN).get(BrokenHierarchy.class))
.withMessageStartingWith("Attribute 'value' in")
.withMessageContaining(BrokenContextConfiguration.class.getName())
.withMessageContaining("@AliasFor 'location'");
}
@Test
@@ -1429,11 +1424,11 @@ public class MergedAnnotationsTests {
public void synthesizeWhenAliasForIsMissingAttributeDeclaration() throws Exception {
AliasForWithMissingAttributeDeclaration annotation = AliasForWithMissingAttributeDeclarationClass.class.getAnnotation(
AliasForWithMissingAttributeDeclaration.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"@AliasFor declaration on attribute 'foo' in annotation").withMessageContaining(
AliasForWithMissingAttributeDeclaration.class.getName()).withMessageContaining(
"points to itself");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation")
.withMessageContaining(AliasForWithMissingAttributeDeclaration.class.getName())
.withMessageContaining("points to itself");
}
@Test
@@ -1441,33 +1436,33 @@ public class MergedAnnotationsTests {
throws Exception {
AliasForWithDuplicateAttributeDeclaration annotation = AliasForWithDuplicateAttributeDeclarationClass.class.getAnnotation(
AliasForWithDuplicateAttributeDeclaration.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"In @AliasFor declared on attribute 'foo' in annotation").withMessageContaining(
AliasForWithDuplicateAttributeDeclaration.class.getName()).withMessageContaining(
"attribute 'attribute' and its alias 'value' are present with values of 'baz' and 'bar'");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("In @AliasFor declared on attribute 'foo' in annotation")
.withMessageContaining(AliasForWithDuplicateAttributeDeclaration.class.getName())
.withMessageContaining("attribute 'attribute' and its alias 'value' are present with values of 'baz' and 'bar'");
}
@Test
public void synthesizeWhenAttributeAliasForNonexistentAttribute() throws Exception {
AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation(
AliasForNonexistentAttribute.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"@AliasFor declaration on attribute 'foo' in annotation").withMessageContaining(
AliasForNonexistentAttribute.class.getName()).withMessageContaining(
"declares an alias for 'bar' which is not present");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation")
.withMessageContaining(AliasForNonexistentAttribute.class.getName())
.withMessageContaining("declares an alias for 'bar' which is not present");
}
@Test
public void synthesizeWhenAttributeAliasWithoutMirroredAliasFor() throws Exception {
AliasForWithoutMirroredAliasFor annotation = AliasForWithoutMirroredAliasForClass.class.getAnnotation(
AliasForWithoutMirroredAliasFor.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"Attribute 'bar' in").withMessageContaining(
AliasForWithoutMirroredAliasFor.class.getName()).withMessageContaining(
"@AliasFor 'foo'");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("Attribute 'bar' in")
.withMessageContaining(AliasForWithoutMirroredAliasFor.class.getName())
.withMessageContaining("@AliasFor 'foo'");
}
@Test
@@ -1475,11 +1470,11 @@ public class MergedAnnotationsTests {
throws Exception {
AliasForWithMirroredAliasForWrongAttribute annotation = AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(
AliasForWithMirroredAliasForWrongAttribute.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessage(
"@AliasFor declaration on attribute 'bar' in annotation ["
+ AliasForWithMirroredAliasForWrongAttribute.class.getName()
+ "] declares an alias for 'quux' which is not present.");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessage("@AliasFor declaration on attribute 'bar' in annotation ["
+ AliasForWithMirroredAliasForWrongAttribute.class.getName()
+ "] declares an alias for 'quux' which is not present.");
}
@Test
@@ -1487,13 +1482,13 @@ public class MergedAnnotationsTests {
throws Exception {
AliasForAttributeOfDifferentType annotation = AliasForAttributeOfDifferentTypeClass.class.getAnnotation(
AliasForAttributeOfDifferentType.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"Misconfigured aliases").withMessageContaining(
AliasForAttributeOfDifferentType.class.getName()).withMessageContaining(
"attribute 'foo'").withMessageContaining(
"attribute 'bar'").withMessageContaining(
"same return type");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("Misconfigured aliases")
.withMessageContaining(AliasForAttributeOfDifferentType.class.getName())
.withMessageContaining("attribute 'foo'")
.withMessageContaining("attribute 'bar'")
.withMessageContaining("same return type");
}
@Test
@@ -1501,13 +1496,13 @@ public class MergedAnnotationsTests {
throws Exception {
AliasForWithMissingDefaultValues annotation = AliasForWithMissingDefaultValuesClass.class.getAnnotation(
AliasForWithMissingDefaultValues.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"Misconfigured aliases").withMessageContaining(
AliasForWithMissingDefaultValues.class.getName()).withMessageContaining(
"attribute 'foo' in annotation").withMessageContaining(
"attribute 'bar' in annotation").withMessageContaining(
"default values");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("Misconfigured aliases")
.withMessageContaining(AliasForWithMissingDefaultValues.class.getName())
.withMessageContaining("attribute 'foo' in annotation")
.withMessageContaining("attribute 'bar' in annotation")
.withMessageContaining("default values");
}
@Test
@@ -1515,13 +1510,13 @@ public class MergedAnnotationsTests {
throws Exception {
AliasForAttributeWithDifferentDefaultValue annotation = AliasForAttributeWithDifferentDefaultValueClass.class.getAnnotation(
AliasForAttributeWithDifferentDefaultValue.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"Misconfigured aliases").withMessageContaining(
AliasForAttributeWithDifferentDefaultValue.class.getName()).withMessageContaining(
"attribute 'foo' in annotation").withMessageContaining(
"attribute 'bar' in annotation").withMessageContaining(
"same default value");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("Misconfigured aliases")
.withMessageContaining(AliasForAttributeWithDifferentDefaultValue.class.getName())
.withMessageContaining("attribute 'foo' in annotation")
.withMessageContaining("attribute 'bar' in annotation")
.withMessageContaining("same default value");
}
@Test
@@ -1529,13 +1524,13 @@ public class MergedAnnotationsTests {
throws Exception {
AliasedComposedTestConfigurationNotMetaPresent annotation = AliasedComposedTestConfigurationNotMetaPresentClass.class.getAnnotation(
AliasedComposedTestConfigurationNotMetaPresent.class);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(annotation)).withMessageStartingWith(
"@AliasFor declaration on attribute 'xmlConfigFile' in annotation").withMessageContaining(
AliasedComposedTestConfigurationNotMetaPresent.class.getName()).withMessageContaining(
"declares an alias for attribute 'location' in annotation").withMessageContaining(
TestConfiguration.class.getName()).withMessageContaining(
"not meta-present");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(annotation))
.withMessageStartingWith("@AliasFor declaration on attribute 'xmlConfigFile' in annotation")
.withMessageContaining(AliasedComposedTestConfigurationNotMetaPresent.class.getName())
.withMessageContaining("declares an alias for attribute 'location' in annotation")
.withMessageContaining(TestConfiguration.class.getName())
.withMessageContaining("not meta-present");
}
@Test
@@ -1630,16 +1625,12 @@ public class MergedAnnotationsTests {
Class<ImplicitAliasesWithMissingDefaultValuesTestConfiguration> annotationType = ImplicitAliasesWithMissingDefaultValuesTestConfiguration.class;
ImplicitAliasesWithMissingDefaultValuesTestConfiguration config = clazz.getAnnotation(
annotationType);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(clazz, config)).withMessageStartingWith(
"Misconfigured aliases:").withMessageContaining(
"attribute 'location1' in annotation ["
+ annotationType.getName()
+ "]").withMessageContaining(
"attribute 'location2' in annotation ["
+ annotationType.getName()
+ "]").withMessageContaining(
"default values");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(clazz, config))
.withMessageStartingWith("Misconfigured aliases:")
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("default values");
}
@Test
@@ -1649,16 +1640,12 @@ public class MergedAnnotationsTests {
Class<ImplicitAliasesWithDifferentDefaultValuesTestConfiguration> annotationType = ImplicitAliasesWithDifferentDefaultValuesTestConfiguration.class;
ImplicitAliasesWithDifferentDefaultValuesTestConfiguration config = clazz.getAnnotation(
annotationType);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(clazz, config)).withMessageStartingWith(
"Misconfigured aliases:").withMessageContaining(
"attribute 'location1' in annotation ["
+ annotationType.getName()
+ "]").withMessageContaining(
"attribute 'location2' in annotation ["
+ annotationType.getName()
+ "]").withMessageContaining(
"same default value");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(clazz, config))
.withMessageStartingWith("Misconfigured aliases:")
.withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]")
.withMessageContaining("same default value");
}
@Test
@@ -1667,13 +1654,13 @@ public class MergedAnnotationsTests {
Class<ImplicitAliasesWithDuplicateValuesTestConfiguration> annotationType = ImplicitAliasesWithDuplicateValuesTestConfiguration.class;
ImplicitAliasesWithDuplicateValuesTestConfiguration config = clazz.getAnnotation(
annotationType);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(clazz, config)).withMessageStartingWith(
"Different @AliasFor mirror values for annotation").withMessageContaining(
annotationType.getName()).withMessageContaining(
"declared on class").withMessageContaining(
clazz.getName()).withMessageContaining(
"are declared with values of");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(clazz, config))
.withMessageStartingWith("Different @AliasFor mirror values for annotation")
.withMessageContaining(annotationType.getName())
.withMessageContaining("declared on class")
.withMessageContaining(clazz.getName())
.withMessageContaining("are declared with values of");
}
@Test
@@ -1755,9 +1742,8 @@ public class MergedAnnotationsTests {
@Test
public void synthesizeWhenAttributeAliasesWithDifferentValues() throws Exception {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(
TestConfiguration.class)).synthesize());
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(TestConfiguration.class)).synthesize());
}
@Test
@@ -1827,12 +1813,10 @@ public class MergedAnnotationsTests {
}
private void testMissingTextAttribute(Map<String, Object> attributes) {
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> {
MergedAnnotation<AnnotationWithoutDefaults> annotation = MergedAnnotation.of(
AnnotationWithoutDefaults.class, attributes);
annotation.synthesize();
}).withMessage("No value found for attribute named 'text' in merged annotation "
+ AnnotationWithoutDefaults.class.getName());
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() ->
MergedAnnotation.of(AnnotationWithoutDefaults.class, attributes).synthesize())
.withMessage("No value found for attribute named 'text' in merged annotation " +
AnnotationWithoutDefaults.class.getName());
}
@Test
@@ -1841,10 +1825,11 @@ public class MergedAnnotationsTests {
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class,
map);
// annotation.synthesize();
assertThatIllegalStateException().isThrownBy(
() -> annotation.synthesize()).withMessage(
"Attribute 'value' in annotation org.springframework.stereotype.Component "
+ "should be compatible with java.lang.String but a java.lang.Long value was returned");
assertThatIllegalStateException().isThrownBy(() ->
annotation.synthesize())
.withMessage("Attribute 'value' in annotation " +
"org.springframework.stereotype.Component should be " +
"compatible with java.lang.String but a java.lang.Long value was returned");
}
@Test

View File

@@ -262,12 +262,12 @@ public class MissingMergedAnnotationTests {
@Test
public void synthesizeWithPredicateWhenPredicateMatchesThrowsNoSuchElementException() {
assertThatNoSuchElementException().isThrownBy(
() -> this.missing.synthesize((annotation) -> true));
() -> this.missing.synthesize(annotation -> true));
}
@Test
public void synthesizeWithPredicateWhenPredicateDoesNotMatchReturnsEmpty() {
assertThat(this.missing.synthesize((annotation) -> false)).isEmpty();
assertThat(this.missing.synthesize(annotation -> false)).isEmpty();
}
@Test

View File

@@ -18,8 +18,7 @@ package org.springframework.core.annotation;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.*;
/**
* Tests for {@link PackagesAnnotationFilter}.
@@ -30,23 +29,23 @@ public class PackagesAnnotationFilterTests {
@Test
public void createWhenPackagesIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> new PackagesAnnotationFilter((String[]) null)).withMessage(
"Packages array must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
new PackagesAnnotationFilter((String[]) null))
.withMessage("Packages array must not be null");
}
@Test
public void createWhenPackagesContainsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> new PackagesAnnotationFilter((String) null)).withMessage(
"Packages array must not have empty elements");
assertThatIllegalArgumentException().isThrownBy(() ->
new PackagesAnnotationFilter((String) null))
.withMessage("Packages array must not have empty elements");
}
@Test
public void createWhenPackagesContainsEmptyTextThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> new PackagesAnnotationFilter("")).withMessage(
"Packages array must not have empty elements");
assertThatIllegalArgumentException().isThrownBy(() ->
new PackagesAnnotationFilter(""))
.withMessage("Packages array must not have empty elements");
}
@Test

View File

@@ -93,20 +93,19 @@ public class RepeatableContainersTests {
@Test
public void ofExplicitWhenHasNoValueThrowsException() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> RepeatableContainers.of(ExplicitRepeatable.class,
InvalidNoValue.class)).withMessageContaining(
"Invalid declaration of container type ["
+ InvalidNoValue.class.getName()
+ "] for repeatable annotation ["
+ ExplicitRepeatable.class.getName() + "]");
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
RepeatableContainers.of(ExplicitRepeatable.class, InvalidNoValue.class))
.withMessageContaining("Invalid declaration of container type ["
+ InvalidNoValue.class.getName()
+ "] for repeatable annotation ["
+ ExplicitRepeatable.class.getName() + "]");
}
@Test
public void ofExplicitWhenValueIsNotArrayThrowsException() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> RepeatableContainers.of(ExplicitRepeatable.class,
InvalidNotArray.class)).withMessage("Container type ["
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
RepeatableContainers.of(ExplicitRepeatable.class, InvalidNotArray.class))
.withMessage("Container type ["
+ InvalidNotArray.class.getName()
+ "] must declare a 'value' attribute for an array of type ["
+ ExplicitRepeatable.class.getName() + "]");
@@ -114,9 +113,9 @@ public class RepeatableContainersTests {
@Test
public void ofExplicitWhenValueIsArrayOfWrongTypeThrowsException() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(
() -> RepeatableContainers.of(ExplicitRepeatable.class,
InvalidWrongArrayType.class)).withMessage("Container type ["
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
RepeatableContainers.of(ExplicitRepeatable.class, InvalidWrongArrayType.class))
.withMessage("Container type ["
+ InvalidWrongArrayType.class.getName()
+ "] must declare a 'value' attribute for an array of type ["
+ ExplicitRepeatable.class.getName() + "]");
@@ -124,9 +123,9 @@ public class RepeatableContainersTests {
@Test
public void ofExplicitWhenAnnotationIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> RepeatableContainers.of(null, null)).withMessage(
"Repeatable must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
RepeatableContainers.of(null, null))
.withMessage("Repeatable must not be null");
}
@Test
@@ -139,11 +138,11 @@ public class RepeatableContainersTests {
@Test
public void ofExplicitWhenContainerIsNullAndNotRepeatableThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> RepeatableContainers.of(
ExplicitRepeatable.class, null)).withMessage(
"Annotation type must be a repeatable annotation: "
+ "failed to resolve container type for "
+ ExplicitRepeatable.class.getName());
assertThatIllegalArgumentException().isThrownBy(() ->
RepeatableContainers.of(ExplicitRepeatable.class, null))
.withMessage("Annotation type must be a repeatable annotation: " +
"failed to resolve container type for " +
ExplicitRepeatable.class.getName());
}
@Test

View File

@@ -303,7 +303,7 @@ public abstract class AbstractDecoderTestCase<D extends Decoder<?>>
}
/**
* Test a standard {@link Decoder#decodeToMono) decode} scenario. For example:
* Test a standard {@link Decoder#decodeToMono decode} scenario. For example:
* <pre class="code">
* byte[] bytes1 = ...
* byte[] bytes2 = ...
@@ -330,7 +330,7 @@ public abstract class AbstractDecoderTestCase<D extends Decoder<?>>
}
/**
* Test a standard {@link Decoder#decodeToMono) decode} scenario. For example:
* Test a standard {@link Decoder#decodeToMono decode} scenario. For example:
* <pre class="code">
* byte[] bytes1 = ...
* byte[] bytes2 = ...

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -32,9 +32,9 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.*;
import static org.junit.Assert.*;
import static org.springframework.core.io.buffer.DataBufferUtils.release;
import static org.springframework.core.io.buffer.DataBufferUtils.*;
/**
* Abstract base class for {@link Encoder} unit tests. Subclasses need to implement

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,10 +25,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.util.MimeTypeUtils;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_16;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.*;
import static org.junit.Assert.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -32,7 +32,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.charset.StandardCharsets.*;
import static org.junit.Assert.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -30,7 +30,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.util.comparator.ComparableComparator;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests for {@link ConvertingComparator}.

View File

@@ -367,7 +367,7 @@ public class DefaultConversionServiceTests {
Stream<Integer> result = (Stream<Integer>) this.conversionService.convert(source,
TypeDescriptor.valueOf(String[].class),
new TypeDescriptor(getClass().getDeclaredField("genericStream")));
assertEquals(8, result.mapToInt((x) -> x).sum());
assertEquals(8, result.mapToInt(x -> x).sum());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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.
@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,17 +21,14 @@ import java.util.List;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -42,9 +39,6 @@ import static org.junit.Assert.*;
*/
public class StreamConverterTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final GenericConversionService conversionService = new GenericConversionService();
private final StreamConverter streamConverter = new StreamConverter(this.conversionService);
@@ -112,10 +106,9 @@ public class StreamConverterTests {
public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
thrown.expect(ConversionFailedException.class);
thrown.expectCause(is(instanceOf(ConverterNotFoundException.class)));
this.conversionService.convert(stream, arrayOfLongs);
assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() ->
this.conversionService.convert(stream, arrayOfLongs))
.withCauseInstanceOf(ConverterNotFoundException.class);
}
@Test
@@ -130,7 +123,7 @@ public class StreamConverterTests {
assertTrue("Converted object must be a stream", result instanceof Stream);
@SuppressWarnings("unchecked")
Stream<Integer> content = (Stream<Integer>) result;
assertEquals(6, content.mapToInt((x) -> x).sum());
assertEquals(6, content.mapToInt(x -> x).sum());
}
@Test
@@ -178,9 +171,10 @@ public class StreamConverterTests {
@Test
public void shouldFailToConvertIfNoStream() throws NoSuchFieldException {
thrown.expect(IllegalStateException.class);
this.streamConverter.convert(new Object(), new TypeDescriptor(Types.class.getField("listOfStrings")),
new TypeDescriptor(Types.class.getField("arrayOfLongs")));
TypeDescriptor sourceType = new TypeDescriptor(Types.class.getField("listOfStrings"));
TypeDescriptor targetType = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
assertThatIllegalStateException().isThrownBy(() ->
this.streamConverter.convert(new Object(), sourceType, targetType));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -23,7 +23,7 @@ import java.util.Set;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests covering the extensibility of {@link AbstractEnvironment}.
@@ -74,7 +74,10 @@ public class CustomEnvironmentTests {
@Override
@SuppressWarnings("serial")
protected Set<String> getReservedDefaultProfiles() {
return new HashSet<String>() {{ add("rd1"); add("rd2"); }};
return new HashSet<String>() {{
add("rd1");
add("rd2");
}};
}
}

View File

@@ -21,12 +21,11 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.*;
/**
@@ -39,35 +38,32 @@ import static org.junit.Assert.*;
*/
public class ProfilesTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void ofWhenNullThrowsException() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Must specify at least one profile");
Profiles.of((String[]) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Profiles.of((String[]) null))
.withMessageContaining("Must specify at least one profile");
}
@Test
public void ofWhenEmptyThrowsException() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Must specify at least one profile");
Profiles.of();
assertThatIllegalArgumentException().isThrownBy(() ->
Profiles.of())
.withMessageContaining("Must specify at least one profile");
}
@Test
public void ofNullElement() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("must contain text");
Profiles.of((String) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Profiles.of((String) null))
.withMessageContaining("must contain text");
}
@Test
public void ofEmptyElement() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("must contain text");
Profiles.of(" ");
assertThatIllegalArgumentException().isThrownBy(() ->
Profiles.of(" "))
.withMessageContaining("must contain text");
}
@Test
@@ -124,7 +120,7 @@ public class ProfilesTests {
assertFalse(profiles.matches(activeProfiles("spring")));
assertTrue(profiles.matches(activeProfiles("framework")));
}
@Test
public void ofSingleInvertedExpression() {
Profiles profiles = Profiles.of("(!spring)");
@@ -305,7 +301,7 @@ public class ProfilesTests {
assertTrue(ex.getMessage().contains("Malformed"));
}
}
private static Predicate<String> activeProfiles(String... profiles) {
return new MockActiveProfiles(profiles);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,7 +25,7 @@ import java.util.Properties;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for {@link PropertySource} implementations.
@@ -38,10 +38,18 @@ public class PropertySourceTests {
@Test
@SuppressWarnings("serial")
public void equals() {
Map<String, Object> map1 = new HashMap<String, Object>() {{ put("a", "b"); }};
Map<String, Object> map2 = new HashMap<String, Object>() {{ put("c", "d"); }};
Properties props1 = new Properties() {{ setProperty("a", "b"); }};
Properties props2 = new Properties() {{ setProperty("c", "d"); }};
Map<String, Object> map1 = new HashMap<String, Object>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<String, Object>() {{
put("c", "d");
}};
Properties props1 = new Properties() {{
setProperty("a", "b");
}};
Properties props2 = new Properties() {{
setProperty("c", "d");
}};
MapPropertySource mps = new MapPropertySource("mps", map1);
assertThat(mps, equalTo(mps));
@@ -62,8 +70,12 @@ public class PropertySourceTests {
@Test
@SuppressWarnings("serial")
public void collectionsOperations() {
Map<String, Object> map1 = new HashMap<String, Object>() {{ put("a", "b"); }};
Map<String, Object> map2 = new HashMap<String, Object>() {{ put("c", "d"); }};
Map<String, Object> map1 = new HashMap<String, Object>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<String, Object>() {{
put("c", "d");
}};
PropertySource<?> ps1 = new MapPropertySource("ps1", map1);
ps1.getSource();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2019 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.
@@ -22,7 +22,7 @@ import java.util.List;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
public class SimpleCommandLineParserTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 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,7 +21,7 @@ import java.util.List;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for {@link SimpleCommandLinePropertySource}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for {@link SystemEnvironmentPropertySource}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -31,11 +31,12 @@ import java.nio.file.Paths;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
@@ -68,32 +69,29 @@ public class PathResourceTests {
}
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void nullPath() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Path must not be null");
new PathResource((Path) null);
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((Path) null))
.withMessageContaining("Path must not be null");
}
@Test
public void nullPathString() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Path must not be null");
new PathResource((String) null);
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((String) null))
.withMessageContaining("Path must not be null");
}
@Test
public void nullUri() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("URI must not be null");
new PathResource((URI) null);
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((URI) null))
.withMessageContaining("URI must not be null");
}
@Test
@@ -174,15 +172,15 @@ public class PathResourceTests {
@Test
public void getInputStreamForDir() throws IOException {
PathResource resource = new PathResource(TEST_DIR);
thrown.expect(FileNotFoundException.class);
resource.getInputStream();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getInputStream);
}
@Test
public void getInputStreamDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
thrown.expect(FileNotFoundException.class);
resource.getInputStream();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getInputStream);
}
@Test
@@ -210,8 +208,8 @@ public class PathResourceTests {
given(path.normalize()).willReturn(path);
given(path.toFile()).willThrow(new UnsupportedOperationException());
PathResource resource = new PathResource(path);
thrown.expect(FileNotFoundException.class);
resource.getFile();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getFile);
}
@Test
@@ -291,8 +289,8 @@ public class PathResourceTests {
@Test
public void directoryOutputStream() throws IOException {
PathResource resource = new PathResource(TEST_DIR);
thrown.expect(FileNotFoundException.class);
resource.getOutputStream();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getOutputStream);
}
@Test
@@ -327,8 +325,8 @@ public class PathResourceTests {
@Test
public void getReadableByteChannelDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
thrown.expect(FileNotFoundException.class);
resource.readableChannel();
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::readableChannel);
}
@Test

View File

@@ -291,7 +291,8 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
int len = inputStream.read(result);
assertEquals(3, len);
assertArrayEquals(bytes, result);
} finally {
}
finally {
inputStream.close();
}

View File

@@ -49,7 +49,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,7 +19,7 @@ package org.springframework.core.io.buffer;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.springframework.core.io.buffer.DataBufferUtils.release;
import static org.springframework.core.io.buffer.DataBufferUtils.*;
/**
* @author Arjen Poutsma
@@ -51,4 +51,4 @@ public class LeakAwareDataBufferFactoryTests {
this.bufferFactory.checkForLeaks();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -22,8 +22,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -23,8 +23,7 @@ import org.junit.Test;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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,6 +19,7 @@ package org.springframework.core.io.support;
import java.nio.charset.Charset;
import org.junit.Test;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;

View File

@@ -19,10 +19,9 @@ package org.springframework.core.io.support;
import java.lang.reflect.Modifier;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.*;
/**
@@ -34,9 +33,6 @@ import static org.junit.Assert.*;
*/
public class SpringFactoriesLoaderTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void loadFactoriesInCorrectOrder() {
List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(DummyFactory.class, null);
@@ -55,10 +51,10 @@ public class SpringFactoriesLoaderTests {
@Test
public void attemptToLoadFactoryOfIncompatibleType() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Unable to instantiate factory class [org.springframework.core.io.support.MyDummyFactory1] for factory type [java.lang.String]");
SpringFactoriesLoader.loadFactories(String.class, null);
assertThatIllegalArgumentException().isThrownBy(() ->
SpringFactoriesLoader.loadFactories(String.class, null))
.withMessageContaining("Unable to instantiate factory class "
+ "[org.springframework.core.io.support.MyDummyFactory1] for factory type [java.lang.String]");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -18,12 +18,12 @@ package org.springframework.core.task;
import java.util.concurrent.ThreadFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.util.ConcurrencyThrottleSupport;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -35,17 +35,13 @@ import static org.junit.Assert.*;
*/
public class SimpleAsyncTaskExecutorTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
assertTrue(executor.isThrottleActive());
exception.expect(IllegalStateException.class);
executor.execute(new NoOpRunnable());
assertThatIllegalStateException().isThrownBy(() ->
executor.execute(new NoOpRunnable()));
}
@Test
@@ -80,8 +76,8 @@ public class SimpleAsyncTaskExecutorTests {
@Test
public void throwsExceptionWhenSuppliedWithNullRunnable() throws Exception {
exception.expect(IllegalArgumentException.class);
new SimpleAsyncTaskExecutor().execute(null);
assertThatIllegalArgumentException().isThrownBy(() ->
new SimpleAsyncTaskExecutor().execute(null));
}
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2019 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,7 +19,7 @@ package org.springframework.core.type;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Abstract base class for testing implementations of

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 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.
@@ -29,7 +29,7 @@ import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for checking the behaviour of {@link CachingMetadataReaderFactory} under

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,7 +25,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AbstractAnnotationMetadataTests;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.*;

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,8 +25,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AbstractMethodMetadataTests;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor;
import org.springframework.core.type.classreading.MethodMetadataReadingVisitor;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.*;

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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.
@@ -20,7 +20,6 @@ import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
/**
* Additional hamcrest matchers.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -23,7 +23,7 @@ import org.mockito.internal.stubbing.InvocationContainerImpl;
import org.mockito.internal.util.MockUtil;
import org.mockito.invocation.Invocation;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

View File

@@ -20,11 +20,10 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**
@@ -35,10 +34,6 @@ import static org.hamcrest.Matchers.*;
*/
public class TestGroupTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void parseNull() {
assertThat(TestGroup.parse(null), equalTo(Collections.emptySet()));
@@ -68,11 +63,11 @@ public class TestGroupTests {
@Test
public void parseMissing() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to find test group 'missing' when parsing " +
"testGroups value: 'performance, missing'. Available groups include: " +
"[LONG_RUNNING,PERFORMANCE,CI]");
TestGroup.parse("performance, missing");
assertThatIllegalArgumentException().isThrownBy(() ->
TestGroup.parse("performance, missing"))
.withMessageContaining("Unable to find test group 'missing' when parsing " +
"testGroups value: 'performance, missing'. Available groups include: " +
"[LONG_RUNNING,PERFORMANCE,CI]");
}
@Test
@@ -89,11 +84,11 @@ public class TestGroupTests {
@Test
public void parseAllExceptMissing() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to find test group 'missing' when parsing " +
"testGroups value: 'all-missing'. Available groups include: " +
"[LONG_RUNNING,PERFORMANCE,CI]");
TestGroup.parse("all-missing");
assertThatIllegalArgumentException().isThrownBy(() ->
TestGroup.parse("all-missing"))
.withMessageContaining("Unable to find test group 'missing' when parsing " +
"testGroups value: 'all-missing'. Available groups include: " +
"[LONG_RUNNING,PERFORMANCE,CI]");
}
}

View File

@@ -1,19 +1,3 @@
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Shared utilities that are used internally throughout the test suite but are not
* published. This package should not be confused with {@code org.springframework.test}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -23,11 +23,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -44,9 +42,6 @@ public class AntPathMatcherTests {
private final AntPathMatcher pathMatcher = new AntPathMatcher();
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void match() {
@@ -401,9 +396,9 @@ public class AntPathMatcherTests {
*/
@Test
public void extractUriTemplateVarsRegexCapturingGroups() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("The number of capturing groups in the pattern"));
pathMatcher.extractUriTemplateVariables("/web/{id:foo(bar)?}", "/web/foobar");
assertThatIllegalArgumentException().isThrownBy(() ->
pathMatcher.extractUriTemplateVariables("/web/{id:foo(bar)?}", "/web/foobar"))
.withMessageContaining("The number of capturing groups in the pattern");
}
@Test
@@ -439,8 +434,8 @@ public class AntPathMatcherTests {
@Test
public void combineWithTwoFileExtensionPatterns() {
exception.expect(IllegalArgumentException.class);
pathMatcher.combine("/*.html", "/*.txt");
assertThatIllegalArgumentException().isThrownBy(() ->
pathMatcher.combine("/*.html", "/*.txt"));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -20,12 +20,10 @@ import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static java.util.Collections.*;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assertions.*;
/**
* Unit tests for the {@link Assert} class.
@@ -39,9 +37,6 @@ import static org.hamcrest.CoreMatchers.*;
*/
public class AssertTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void stateWithMessage() {
@@ -50,9 +45,8 @@ public class AssertTests {
@Test
public void stateWithFalseExpressionAndMessage() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("enigma");
Assert.state(false, "enigma");
assertThatIllegalStateException().isThrownBy(() ->
Assert.state(false, "enigma")).withMessageContaining("enigma");
}
@Test
@@ -62,16 +56,16 @@ public class AssertTests {
@Test
public void stateWithFalseExpressionAndMessageSupplier() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("enigma");
Assert.state(false, () -> "enigma");
assertThatIllegalStateException().isThrownBy(() ->
Assert.state(false, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void stateWithFalseExpressionAndNullMessageSupplier() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage(equalTo(null));
Assert.state(false, (Supplier<String>) null);
assertThatIllegalStateException().isThrownBy(() ->
Assert.state(false, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -81,9 +75,9 @@ public class AssertTests {
@Test
public void isTrueWithFalse() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.isTrue(false, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isTrue(false, "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -93,16 +87,16 @@ public class AssertTests {
@Test
public void isTrueWithFalseAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.isTrue(false, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isTrue(false, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void isTrueWithFalseAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.isTrue(false, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isTrue(false, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -117,16 +111,16 @@ public class AssertTests {
@Test
public void isNullWithNonNullObjectAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.isNull("foo", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isNull("foo", () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void isNullWithNonNullObjectAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.isNull("foo", (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isNull("foo", (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -141,16 +135,16 @@ public class AssertTests {
@Test
public void notNullWithNullAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notNull(null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notNull(null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notNullWithNullAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.notNull(null, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notNull(null, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -165,16 +159,16 @@ public class AssertTests {
@Test
public void hasLengthWithEmptyString() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength("", "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasLength("", "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasLengthWithNull() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength(null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasLength(null, "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -189,23 +183,23 @@ public class AssertTests {
@Test
public void hasLengthWithEmptyStringAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength("", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasLength("", () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasLengthWithNullAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasLength(null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasLength(null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasLengthWithNullAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.hasLength(null, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasLength(null, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -215,23 +209,23 @@ public class AssertTests {
@Test
public void hasTextWithWhitespaceOnly() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText("\t ", "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText("\t ", "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasTextWithEmptyString() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText("", "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText("", "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasTextWithNull() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText(null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText(null, "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -241,30 +235,29 @@ public class AssertTests {
@Test
public void hasTextWithWhitespaceOnlyAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText("\t ", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText("\t ", () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasTextWithEmptyStringAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText("", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText("", () -> "enigma")).withMessageContaining("enigma");
}
@Test
public void hasTextWithNullAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.hasText(null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText(null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void hasTextWithNullAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.hasText(null, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.hasText(null, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -309,16 +302,16 @@ public class AssertTests {
@Test
public void doesNotContainWithSubstringPresentInSearchStringAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.doesNotContain("1234", "23", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.doesNotContain("1234", "23", () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void doesNotContainWithNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.doesNotContain("1234", "23", (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.doesNotContain("1234", "23", (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -328,16 +321,16 @@ public class AssertTests {
@Test
public void notEmptyArrayWithEmptyArray() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(new String[] {}, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(new String[] {}, "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyArrayWithNullArray() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Object[]) null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Object[]) null, "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -347,23 +340,23 @@ public class AssertTests {
@Test
public void notEmptyArrayWithEmptyArrayAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(new String[] {}, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(new String[] {}, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyArrayWithNullArrayAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Object[]) null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Object[]) null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyArrayWithEmptyArrayAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.notEmpty(new String[] {}, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(new String[] {}, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -393,16 +386,16 @@ public class AssertTests {
@Test
public void noNullElementsWithNullElementsAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.noNullElements(new String[] { "foo", null, "bar" }, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.noNullElements(new String[] { "foo", null, "bar" }, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void noNullElementsWithNullElementsAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.noNullElements(new String[] { "foo", null, "bar" }, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.noNullElements(new String[] { "foo", null, "bar" }, (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -412,16 +405,16 @@ public class AssertTests {
@Test
public void notEmptyCollectionWithEmptyCollection() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(emptyList(), "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyList(), "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyCollectionWithNullCollection() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Collection<?>) null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Collection<?>) null, "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -431,23 +424,23 @@ public class AssertTests {
@Test
public void notEmptyCollectionWithEmptyCollectionAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(emptyList(), () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyList(), () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyCollectionWithNullCollectionAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Collection<?>) null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Collection<?>) null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyCollectionWithEmptyCollectionAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.notEmpty(emptyList(), (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyList(), (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -457,16 +450,16 @@ public class AssertTests {
@Test
public void notEmptyMapWithNullMap() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Map<?, ?>) null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Map<?, ?>) null, "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyMapWithEmptyMap() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(emptyMap(), "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyMap(), "enigma"))
.withMessageContaining("enigma");
}
@Test
@@ -476,23 +469,23 @@ public class AssertTests {
@Test
public void notEmptyMapWithEmptyMapAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty(emptyMap(), () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyMap(), () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyMapWithNullMapAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma");
Assert.notEmpty((Map<?, ?>) null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty((Map<?, ?>) null, () -> "enigma"))
.withMessageContaining("enigma");
}
@Test
public void notEmptyMapWithEmptyMapAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(equalTo(null));
Assert.notEmpty(emptyMap(), (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.notEmpty(emptyMap(), (Supplier<String>) null))
.withMessage(null);
}
@Test
@@ -502,45 +495,44 @@ public class AssertTests {
@Test
public void isInstanceOfWithNullType() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Type to check against must not be null");
Assert.isInstanceOf(null, "foo", "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(null, "foo", "enigma"))
.withMessageContaining("Type to check against must not be null");
}
@Test
public void isInstanceOfWithNullInstance() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: null");
Assert.isInstanceOf(String.class, null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, null, "enigma"))
.withMessageContaining("enigma: null");
}
@Test
public void isInstanceOfWithTypeMismatchAndNullMessage() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Object of class [java.lang.Long] must be an instance of class java.lang.String");
Assert.isInstanceOf(String.class, 42L, (String) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, (String) null))
.withMessageContaining("Object of class [java.lang.Long] must be an instance of class java.lang.String");
}
@Test
public void isInstanceOfWithTypeMismatchAndCustomMessage() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Custom message: java.lang.Long");
Assert.isInstanceOf(String.class, 42L, "Custom message");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, "Custom message"))
.withMessageContaining("Custom message: java.lang.Long");
}
@Test
public void isInstanceOfWithTypeMismatchAndCustomMessageWithSeparator() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Custom message: Object of class [java.lang.Long] must be an instance of class java.lang.String");
Assert.isInstanceOf(String.class, 42L, "Custom message:");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, "Custom message:"))
.withMessageContaining("Custom message: Object of class [java.lang.Long] must be an instance of class java.lang.String");
}
@Test
public void isInstanceOfWithTypeMismatchAndCustomMessageWithSpace() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Custom message for java.lang.Long");
Assert.isInstanceOf(String.class, 42L, "Custom message for ");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, "Custom message for "))
.withMessageContaining("Custom message for java.lang.Long");
}
@Test
@@ -550,30 +542,30 @@ public class AssertTests {
@Test
public void isInstanceOfWithNullTypeAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Type to check against must not be null");
Assert.isInstanceOf(null, "foo", () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(null, "foo", () -> "enigma"))
.withMessageContaining("Type to check against must not be null");
}
@Test
public void isInstanceOfWithNullInstanceAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: null");
Assert.isInstanceOf(String.class, null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, null, () -> "enigma"))
.withMessageContaining("enigma: null");
}
@Test
public void isInstanceOfWithTypeMismatchAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Object of class [java.lang.Long] must be an instance of class java.lang.String");
Assert.isInstanceOf(String.class, 42L, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, (Supplier<String>) null))
.withMessageContaining("Object of class [java.lang.Long] must be an instance of class java.lang.String");
}
@Test
public void isInstanceOfWithTypeMismatchAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: java.lang.Long");
Assert.isInstanceOf(String.class, 42L, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isInstanceOf(String.class, 42L, () -> "enigma"))
.withMessageContaining("enigma: java.lang.Long");
}
@Test
@@ -583,44 +575,44 @@ public class AssertTests {
@Test
public void isAssignableWithNullSupertype() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Super type to check against must not be null");
Assert.isAssignable(null, Integer.class, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(null, Integer.class, "enigma"))
.withMessageContaining("Super type to check against must not be null");
}
@Test
public void isAssignableWithNullSubtype() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: null");
Assert.isAssignable(Integer.class, null, "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(Integer.class, null, "enigma"))
.withMessageContaining("enigma: null");
}
@Test
public void isAssignableWithTypeMismatchAndNullMessage() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("class java.lang.Integer is not assignable to class java.lang.String");
Assert.isAssignable(String.class, Integer.class, (String) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, (String) null))
.withMessageContaining("class java.lang.Integer is not assignable to class java.lang.String");
}
@Test
public void isAssignableWithTypeMismatchAndCustomMessage() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Custom message: class java.lang.Integer");
Assert.isAssignable(String.class, Integer.class, "Custom message");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, "Custom message"))
.withMessageContaining("Custom message: class java.lang.Integer");
}
@Test
public void isAssignableWithTypeMismatchAndCustomMessageWithSeparator() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Custom message: class java.lang.Integer is not assignable to class java.lang.String");
Assert.isAssignable(String.class, Integer.class, "Custom message:");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, "Custom message:"))
.withMessageContaining("Custom message: class java.lang.Integer is not assignable to class java.lang.String");
}
@Test
public void isAssignableWithTypeMismatchAndCustomMessageWithSpace() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Custom message for class java.lang.Integer");
Assert.isAssignable(String.class, Integer.class, "Custom message for ");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, "Custom message for "))
.withMessageContaining("Custom message for class java.lang.Integer");
}
@Test
@@ -630,30 +622,30 @@ public class AssertTests {
@Test
public void isAssignableWithNullSupertypeAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Super type to check against must not be null");
Assert.isAssignable(null, Integer.class, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(null, Integer.class, () -> "enigma"))
.withMessageContaining("Super type to check against must not be null");
}
@Test
public void isAssignableWithNullSubtypeAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: null");
Assert.isAssignable(Integer.class, null, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(Integer.class, null, () -> "enigma"))
.withMessageContaining("enigma: null");
}
@Test
public void isAssignableWithTypeMismatchAndNullMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("class java.lang.Integer is not assignable to class java.lang.String");
Assert.isAssignable(String.class, Integer.class, (Supplier<String>) null);
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, (Supplier<String>) null))
.withMessageContaining("class java.lang.Integer is not assignable to class java.lang.String");
}
@Test
public void isAssignableWithTypeMismatchAndMessageSupplier() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("enigma: class java.lang.Integer");
Assert.isAssignable(String.class, Integer.class, () -> "enigma");
assertThatIllegalArgumentException().isThrownBy(() ->
Assert.isAssignable(String.class, Integer.class, () -> "enigma"))
.withMessageContaining("enigma: class java.lang.Integer");
}
@Test
@@ -663,9 +655,9 @@ public class AssertTests {
@Test
public void stateWithFalseExpression() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("enigma");
Assert.state(false, "enigma");
assertThatIllegalStateException().isThrownBy(() ->
Assert.state(false, "enigma"))
.withMessageContaining("enigma");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -30,9 +30,7 @@ import java.util.Set;
import java.util.WeakHashMap;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.lang.Nullable;
import org.springframework.util.ConcurrentReferenceHashMap.Entry;
@@ -41,6 +39,7 @@ import org.springframework.util.ConcurrentReferenceHashMap.Restructure;
import org.springframework.util.comparator.ComparableComparator;
import org.springframework.util.comparator.NullSafeComparator;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@@ -55,9 +54,6 @@ public class ConcurrentReferenceHashMapTests {
private static final Comparator<? super String> NULL_SAFE_STRING_SORT = new NullSafeComparator<String>(
new ComparableComparator<String>(), true);
@Rule
public ExpectedException thrown = ExpectedException.none();
private TestWeakConcurrentCache<Integer, String> map = new TestWeakConcurrentCache<>();
@@ -106,25 +102,25 @@ public class ConcurrentReferenceHashMapTests {
@Test
public void shouldNeedNonNegativeInitialCapacity() {
new ConcurrentReferenceHashMap<Integer, String>(0, 1);
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Initial capacity must not be negative");
new TestWeakConcurrentCache<Integer, String>(-1, 1);
assertThatIllegalArgumentException().isThrownBy(() ->
new TestWeakConcurrentCache<Integer, String>(-1, 1))
.withMessageContaining("Initial capacity must not be negative");
}
@Test
public void shouldNeedPositiveLoadFactor() {
new ConcurrentReferenceHashMap<Integer, String>(0, 0.1f, 1);
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Load factor must be positive");
new TestWeakConcurrentCache<Integer, String>(0, 0.0f, 1);
assertThatIllegalArgumentException().isThrownBy(() ->
new TestWeakConcurrentCache<Integer, String>(0, 0.0f, 1))
.withMessageContaining("Load factor must be positive");
}
@Test
public void shouldNeedPositiveConcurrencyLevel() {
new ConcurrentReferenceHashMap<Integer, String>(1, 1);
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Concurrency level must be positive");
new TestWeakConcurrentCache<Integer, String>(1, 0);
assertThatIllegalArgumentException().isThrownBy(() ->
new TestWeakConcurrentCache<Integer, String>(1, 0))
.withMessageContaining("Concurrency level must be positive");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,13 +16,12 @@
package org.springframework.util;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.util.backoff.BackOffExecution;
import org.springframework.util.backoff.ExponentialBackOff;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.*;
/**
@@ -31,9 +30,6 @@ import static org.junit.Assert.*;
*/
public class ExponentialBackOffTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void defaultInstance() {
ExponentialBackOff backOff = new ExponentialBackOff();
@@ -109,9 +105,8 @@ public class ExponentialBackOffTests {
@Test
public void invalidInterval() {
ExponentialBackOff backOff = new ExponentialBackOff();
thrown.expect(IllegalArgumentException.class);
backOff.setMultiplier(0.9);
assertThatIllegalArgumentException().isThrownBy(() ->
backOff.setMultiplier(0.9));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -35,9 +35,9 @@ public class FastByteArrayOutputStreamTests {
private static final int INITIAL_CAPACITY = 256;
private final FastByteArrayOutputStream os = new FastByteArrayOutputStream(INITIAL_CAPACITY);;
private final FastByteArrayOutputStream os = new FastByteArrayOutputStream(INITIAL_CAPACITY);
private final byte[] helloBytes = "Hello World".getBytes(StandardCharsets.UTF_8);;
private final byte[] helloBytes = "Hello World".getBytes(StandardCharsets.UTF_8);
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -20,10 +20,9 @@ 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
/**
@@ -34,10 +33,6 @@ import static org.junit.Assert.*;
*/
public class MethodInvokerTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void plainMethodInvoker() throws Exception {
// sanity check: singleton, non-static should work
@@ -80,8 +75,8 @@ public class MethodInvokerTests {
mi.setTargetMethod("supertypes2");
mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE);
exception.expect(NoSuchMethodException.class);
mi.prepare();
assertThatExceptionOfType(NoSuchMethodException.class).isThrownBy(
mi::prepare);
}
@Test
@@ -91,8 +86,8 @@ public class MethodInvokerTests {
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments("no match");
exception.expect(NoSuchMethodException.class);
methodInvoker.prepare();
assertThatExceptionOfType(NoSuchMethodException.class).isThrownBy(
methodInvoker::prepare);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -24,10 +24,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -43,10 +42,6 @@ import static org.springframework.util.ObjectUtils.*;
*/
public class ObjectUtilsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void isCheckedException() {
assertTrue(ObjectUtils.isCheckedException(new Exception()));
@@ -170,8 +165,8 @@ public class ObjectUtilsTests {
@Test
public void toObjectArrayWithNonArrayType() {
exception.expect(IllegalArgumentException.class);
ObjectUtils.toObjectArray("Not an []");
assertThatIllegalArgumentException().isThrownBy(() ->
ObjectUtils.toObjectArray("Not an []"));
}
@Test
@@ -808,10 +803,9 @@ public class ObjectUtilsTests {
assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "foo"), is(Tropes.FOO));
assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "BAR"), is(Tropes.BAR));
exception.expect(IllegalArgumentException.class);
exception.expectMessage(
is("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"));
ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus");
assertThatIllegalArgumentException().isThrownBy(() ->
ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus"))
.withMessage("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes");
}
private void assertEqualHashCodes(int expected, Object array) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -22,14 +22,11 @@ import java.net.ServerSocket;
import java.util.SortedSet;
import javax.net.ServerSocketFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.springframework.util.SocketUtils.PORT_RANGE_MIN;
import static org.springframework.util.SocketUtils.PORT_RANGE_MAX;
import static org.springframework.util.SocketUtils.*;
/**
* Unit tests for {@link SocketUtils}.
@@ -39,9 +36,6 @@ import static org.springframework.util.SocketUtils.PORT_RANGE_MAX;
*/
public class SocketUtilsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void canBeInstantiated() {
// Just making sure somebody doesn't try to make SocketUtils abstract,
@@ -54,14 +48,14 @@ public class SocketUtilsTests {
@Test
public void findAvailableTcpPortWithZeroMinPort() {
exception.expect(IllegalArgumentException.class);
SocketUtils.findAvailableTcpPort(0);
assertThatIllegalArgumentException().isThrownBy(() ->
SocketUtils.findAvailableTcpPort(0));
}
@Test
public void findAvailableTcpPortWithNegativeMinPort() {
exception.expect(IllegalArgumentException.class);
SocketUtils.findAvailableTcpPort(-500);
assertThatIllegalArgumentException().isThrownBy(() ->
SocketUtils.findAvailableTcpPort(-500));
}
@Test
@@ -82,11 +76,11 @@ public class SocketUtilsTests {
int port = SocketUtils.findAvailableTcpPort();
ServerSocket socket = ServerSocketFactory.getDefault().createServerSocket(port, 1, InetAddress.getByName("localhost"));
try {
exception.expect(IllegalStateException.class);
exception.expectMessage(startsWith("Could not find an available TCP port"));
exception.expectMessage(endsWith("after 1 attempts"));
// will only look for the exact port
SocketUtils.findAvailableTcpPort(port, port);
assertThatIllegalStateException().isThrownBy(() ->
SocketUtils.findAvailableTcpPort(port, port))
.withMessageStartingWith("Could not find an available TCP port")
.withMessageEndingWith("after 1 attempts");
}
finally {
socket.close();
@@ -129,8 +123,8 @@ public class SocketUtilsTests {
@Test
public void findAvailableTcpPortsWithRequestedNumberGreaterThanSizeOfRange() {
exception.expect(IllegalArgumentException.class);
findAvailableTcpPorts(50, 45000, 45010);
assertThatIllegalArgumentException().isThrownBy(() ->
findAvailableTcpPorts(50, 45000, 45010));
}
@@ -138,14 +132,14 @@ public class SocketUtilsTests {
@Test
public void findAvailableUdpPortWithZeroMinPort() {
exception.expect(IllegalArgumentException.class);
SocketUtils.findAvailableUdpPort(0);
assertThatIllegalArgumentException().isThrownBy(() ->
SocketUtils.findAvailableUdpPort(0));
}
@Test
public void findAvailableUdpPortWithNegativeMinPort() {
exception.expect(IllegalArgumentException.class);
SocketUtils.findAvailableUdpPort(-500);
assertThatIllegalArgumentException().isThrownBy(() ->
SocketUtils.findAvailableUdpPort(-500));
}
@Test
@@ -159,11 +153,11 @@ public class SocketUtilsTests {
int port = SocketUtils.findAvailableUdpPort();
DatagramSocket socket = new DatagramSocket(port, InetAddress.getByName("localhost"));
try {
exception.expect(IllegalStateException.class);
exception.expectMessage(startsWith("Could not find an available UDP port"));
exception.expectMessage(endsWith("after 1 attempts"));
// will only look for the exact port
SocketUtils.findAvailableUdpPort(port, port);
assertThatIllegalStateException().isThrownBy(() ->
SocketUtils.findAvailableUdpPort(port, port))
.withMessageStartingWith("Could not find an available UDP port")
.withMessageEndingWith("after 1 attempts");
}
finally {
socket.close();
@@ -206,8 +200,8 @@ public class SocketUtilsTests {
@Test
public void findAvailableUdpPortsWithRequestedNumberGreaterThanSizeOfRange() {
exception.expect(IllegalArgumentException.class);
findAvailableUdpPorts(50, 45000, 45010);
assertThatIllegalArgumentException().isThrownBy(() ->
findAvailableUdpPorts(50, 45000, 45010));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 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,10 +16,10 @@
package org.springframework.util;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.*;
/**
@@ -31,9 +31,6 @@ public class StopWatchTests {
private final StopWatch sw = new StopWatch();
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void validUsage() throws Exception {
String id = "myId";
@@ -122,20 +119,20 @@ public class StopWatchTests {
assertFalse(toString.contains(name1));
assertFalse(toString.contains(name2));
exception.expect(UnsupportedOperationException.class);
sw.getTaskInfo();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
sw::getTaskInfo);
}
@Test
public void failureToStartBeforeGettingTimings() {
exception.expect(IllegalStateException.class);
sw.getLastTaskTimeMillis();
assertThatIllegalStateException().isThrownBy(
sw::getLastTaskTimeMillis);
}
@Test
public void failureToStartBeforeStop() {
exception.expect(IllegalStateException.class);
sw.stop();
assertThatIllegalStateException().isThrownBy(
sw::stop);
}
@Test
@@ -144,8 +141,8 @@ public class StopWatchTests {
sw.stop();
sw.start("");
assertTrue(sw.isRunning());
exception.expect(IllegalStateException.class);
sw.start("");
assertThatIllegalStateException().isThrownBy(() ->
sw.start(""));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 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.
@@ -29,9 +29,9 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for {@link StreamUtils}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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,7 +21,7 @@ import java.util.Comparator;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests for {@link BooleanComparator}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -18,10 +18,9 @@ package org.springframework.util.comparator;
import java.util.Comparator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
/**
@@ -33,9 +32,6 @@ import static org.junit.Assert.*;
*/
public class ComparableComparatorTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testComparableComparator() {
Comparator<String> c = new ComparableComparator<>();
@@ -50,8 +46,8 @@ public class ComparableComparatorTests {
Comparator c = new ComparableComparator();
Object o1 = new Object();
Object o2 = new Object();
thrown.expect(ClassCastException.class);
c.compare(o1, o2);
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() ->
c.compare(o1, o2));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -18,9 +18,9 @@ package org.springframework.util.comparator;
import java.util.Comparator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Test for {@link CompoundComparator}.
@@ -32,14 +32,11 @@ import org.junit.rules.ExpectedException;
@Deprecated
public class CompoundComparatorTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldNeedAtLeastOneComparator() {
Comparator<String> c = new CompoundComparator<>();
thrown.expect(IllegalStateException.class);
c.compare("foo", "bar");
assertThatIllegalStateException().isThrownBy(() ->
c.compare("foo", "bar"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,7 +21,7 @@ import java.util.Comparator;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests for {@link InstanceComparator}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -27,7 +27,7 @@ import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,10 +16,9 @@
package org.springframework.util.unit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -29,9 +28,6 @@ import static org.junit.Assert.*;
*/
public class DataSizeTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void ofBytesToBytes() {
assertEquals(1024, DataSize.ofBytes(1024).toBytes());
@@ -214,10 +210,9 @@ public class DataSizeTests {
@Test
public void parseWithUnsupportedUnit() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("3WB");
this.thrown.expectMessage("is not a valid data size");
DataSize.parse("3WB");
assertThatIllegalArgumentException().isThrownBy(() ->
DataSize.parse("3WB"))
.withMessage("'3WB' is not a valid data size");
}
}

View File

@@ -33,8 +33,8 @@ import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xmlunit.util.Predicate;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import static org.hamcrest.MatcherAssert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -44,6 +44,7 @@ import org.springframework.tests.MockitoUtils;
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -27,7 +27,7 @@ import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/**

View File

@@ -24,7 +24,7 @@ import javax.xml.XMLConstants;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -27,6 +27,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
public class StaxEventXMLReaderTests extends AbstractStaxXMLReaderTestCase {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,9 +16,9 @@
package org.springframework.util.xml;
import org.junit.Before;
import org.junit.Test;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
@@ -26,14 +26,13 @@ import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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,8 @@
package org.springframework.util.xml;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLEventReader;
@@ -30,13 +27,15 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamResult;
import java.io.StringReader;
import java.io.StringWriter;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/**
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -30,6 +30,7 @@ import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
public class StaxStreamXMLReaderTests extends AbstractStaxXMLReaderTestCase {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 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,22 +16,22 @@
package org.springframework.util.xml;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Node;
import org.xmlunit.util.Predicate;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringReader;
import java.io.StringWriter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Node;
import org.xmlunit.util.Predicate;
import static org.hamcrest.MatcherAssert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
public class XMLEventStreamReaderTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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,18 +16,18 @@
package org.springframework.util.xml;
import java.io.StringWriter;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Node;
import org.xmlunit.util.Predicate;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import java.io.StringWriter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import static org.hamcrest.MatcherAssert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
public class XMLEventStreamWriterTests {