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-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.
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for various parameter binding scenarios with before advice.

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.
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for various parameter binding scenarios with before advice.

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 org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.Afte
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for various parameter binding scenarios with before advice.

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.
@@ -29,7 +29,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for various parameter binding scenarios with before advice.

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.
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for various parameter binding scenarios with before advice.

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,6 +21,7 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

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.

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.
@@ -543,7 +543,6 @@ public abstract class AbstractAopProxyTests {
* Check that although a method is eligible for advice chain optimization and
* direct reflective invocation, it doesn't happen if we've asked to see the proxy,
* so as to guarantee a consistent programming model.
* @throws Throwable
*/
@Test
public void testTargetCanGetInvocationEvenIfNoAdviceChain() throws Throwable {

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.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Integration test for Objenesis proxy creation.

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.
@@ -20,9 +20,7 @@ import java.util.NoSuchElementException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -48,9 +46,6 @@ import static org.junit.Assert.*;
*/
public class CommonsPool2TargetSourceTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
/**
* Initial count value set in bean factory XML
*/

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.
@@ -17,14 +17,12 @@
package org.springframework.cache;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.UUID;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.*;
@@ -35,9 +33,6 @@ import static org.junit.Assert.*;
*/
public abstract class AbstractCacheTests<T extends Cache> {
@Rule
public final ExpectedException thrown = ExpectedException.none();
protected final static String CACHE_NAME = "testCache";
protected abstract T getCache();

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.
@@ -16,21 +16,18 @@
package org.springframework.cache;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import static org.assertj.core.api.Assertions.*;
/**
* @author Stephane Nicoll
*/
public abstract class AbstractValueAdaptingCacheTests<T extends AbstractValueAdaptingCache>
extends AbstractCacheTests<T> {
@Rule
public ExpectedException thrown = ExpectedException.none();
protected final static String CACHE_NAME_NO_NULL = "testCacheNoNull";
protected abstract T getCache(boolean allowNull);
@@ -39,12 +36,10 @@ public abstract class AbstractValueAdaptingCacheTests<T extends AbstractValueAda
public void testCachePutNullValueAllowNullFalse() {
T cache = getCache(false);
String key = createRandomKey();
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage(CACHE_NAME_NO_NULL);
this.thrown.expectMessage(
"is configured to not allow null values but null was provided");
cache.put(key, null);
assertThatIllegalArgumentException().isThrownBy(() ->
cache.put(key, null))
.withMessageContaining(CACHE_NAME_NO_NULL)
.withMessageContaining("is configured to not allow null values but null was provided");
}
}

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.
@@ -21,9 +21,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.cache.annotation.CachePut;
@@ -43,6 +41,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@@ -55,10 +54,6 @@ import static org.mockito.Mockito.*;
*/
public class CacheReproTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void spr11124MultipleAnnotations() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11124Config.class);
@@ -129,9 +124,9 @@ public class CacheReproTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
Spr13081Service bean = context.getBean(Spr13081Service.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(MyCacheResolver.class.getName());
bean.getSimple(null);
assertThatIllegalStateException().isThrownBy(() ->
bean.getSimple(null))
.withMessageContaining(MyCacheResolver.class.getName());
}
@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.
@@ -26,15 +26,14 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cache.interceptor.CacheEvictOperation;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.core.annotation.AliasFor;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -46,9 +45,6 @@ import static org.junit.Assert.*;
*/
public class AnnotationCacheOperationSourceTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource();
@@ -156,8 +152,8 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void keyAndKeyGeneratorCannotBeSetTogether() {
this.exception.expect(IllegalStateException.class);
getOps(AnnotatedClass.class, "invalidKeyAndKeyGeneratorSet");
assertThatIllegalStateException().isThrownBy(() ->
getOps(AnnotatedClass.class, "invalidKeyAndKeyGeneratorSet"));
}
@Test
@@ -190,8 +186,8 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void cacheResolverAndCacheManagerCannotBeSetTogether() {
this.exception.expect(IllegalStateException.class);
getOps(AnnotatedClass.class, "invalidCacheResolverAndCacheManagerSet");
assertThatIllegalStateException().isThrownBy(() ->
getOps(AnnotatedClass.class, "invalidCacheResolverAndCacheManagerSet"));
}
@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.
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.cache.AbstractValueAdaptingCacheTests;
import org.springframework.core.serializer.support.SerializationDelegate;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -97,10 +98,11 @@ public class ConcurrentMapCacheTests
public void testNonSerializableContent() {
ConcurrentMapCache serializeCache = createCacheWithStoreByValue();
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Failed to serialize");
this.thrown.expectMessage(this.cache.getClass().getName());
serializeCache.put(createRandomKey(), this.cache);
assertThatIllegalArgumentException().isThrownBy(() ->
serializeCache.put(createRandomKey(), this.cache))
.withMessageContaining("Failed to serialize")
.withMessageContaining(this.cache.getClass().getName());
}
@Test
@@ -109,10 +111,10 @@ public class ConcurrentMapCacheTests
String key = createRandomKey();
this.nativeCache.put(key, "Some garbage");
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Failed to deserialize");
this.thrown.expectMessage("Some garbage");
serializeCache.get(key);
assertThatIllegalArgumentException().isThrownBy(() ->
serializeCache.get(key))
.withMessageContaining("Failed to deserialize")
.withMessageContaining("Some garbage");
}

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,8 +30,8 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ConfigurableApplicationContext;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**

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.
@@ -20,9 +20,7 @@ import java.util.Collections;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
@@ -38,7 +36,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
@@ -47,9 +45,6 @@ import static org.mockito.BDDMockito.*;
*/
public class CacheErrorHandlerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private Cache cache;
private CacheInterceptor cacheInterceptor;
@@ -100,8 +95,9 @@ public class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.thrown.expect(is(exception));
this.simpleService.get(0L);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.get(0L))
.withMessage("Test exception on get");
}
@Test
@@ -120,8 +116,9 @@ public class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.thrown.expect(is(exception));
this.simpleService.put(0L);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.put(0L))
.withMessage("Test exception on put");
}
@Test
@@ -140,8 +137,9 @@ public class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.thrown.expect(is(exception));
this.simpleService.evict(0L);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.evict(0L))
.withMessage("Test exception on evict");
}
@Test
@@ -155,13 +153,14 @@ public class CacheErrorHandlerTests {
@Test
public void clearFailProperException() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on clear");
willThrow(exception).given(this.cache).clear();
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.thrown.expect(is(exception));
this.simpleService.clear();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.clear())
.withMessage("Test exception on clear");
}

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.
@@ -20,9 +20,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
@@ -36,6 +34,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Provides various failure scenario linked to the use of {@link Cacheable#sync()}.
*
@@ -44,9 +44,6 @@ import org.springframework.context.annotation.Configuration;
*/
public class CacheSyncFailureTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private ConfigurableApplicationContext context;
private SimpleService simpleService;
@@ -66,37 +63,37 @@ public class CacheSyncFailureTests {
@Test
public void unlessSync() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) does not support unless attribute");
this.simpleService.unlessSync("key");
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.unlessSync("key"))
.withMessageContaining("@Cacheable(sync=true) does not support unless attribute");
}
@Test
public void severalCachesSync() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.simpleService.severalCachesSync("key");
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.severalCachesSync("key"))
.withMessageContaining("@Cacheable(sync=true) only allows a single cache");
}
@Test
public void severalCachesWithResolvedSync() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.simpleService.severalCachesWithResolvedSync("key");
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.severalCachesWithResolvedSync("key"))
.withMessageContaining("@Cacheable(sync=true) only allows a single cache");
}
@Test
public void syncWithAnotherOperation() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) cannot be combined with other cache operations");
this.simpleService.syncWithAnotherOperation("key");
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.syncWithAnotherOperation("key"))
.withMessageContaining("@Cacheable(sync=true) cannot be combined with other cache operations");
}
@Test
public void syncWithTwoGetOperations() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Only one @Cacheable(sync=true) entry is allowed");
this.simpleService.syncWithTwoGetOperations("key");
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.syncWithTwoGetOperations("key"))
.withMessageContaining("Only one @Cacheable(sync=true) entry is allowed");
}

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,7 +18,7 @@ package org.springframework.cache.interceptor;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

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.
@@ -24,6 +24,7 @@ import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.AbstractListableBeanFactoryTests;
import org.springframework.tests.sample.beans.LifecycleBean;

View File

@@ -31,9 +31,9 @@ public class AggressiveFactoryBeanInstantiationTests {
public void directlyRegisteredFactoryBean() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(SimpleFactoryBean.class);
context.addBeanFactoryPostProcessor((factory) -> {
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, String.class);
});
context.addBeanFactoryPostProcessor(factory ->
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, String.class)
);
context.refresh();
}
}
@@ -42,9 +42,9 @@ public class AggressiveFactoryBeanInstantiationTests {
public void beanMethodFactoryBean() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(BeanMethodConfiguration.class);
context.addBeanFactoryPostProcessor((factory) -> {
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, String.class);
});
context.addBeanFactoryPostProcessor(factory ->
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, String.class)
);
context.refresh();
}
}

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.
@@ -107,12 +107,9 @@ public class AnnotationBeanNameGeneratorTests {
assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName);
}
/**
* @since 4.0.1
* @see https://jira.spring.io/browse/SPR-11360
*/
@Test
public void generateBeanNameFromComposedControllerAnnotationWithoutName() {
// SPR-11360
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
@@ -120,12 +117,9 @@ public class AnnotationBeanNameGeneratorTests {
assertEquals(expectedGeneratedBeanName, beanName);
}
/**
* @since 4.0.1
* @see https://jira.spring.io/browse/SPR-11360
*/
@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
// SPR-11360
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
@@ -133,12 +127,9 @@ public class AnnotationBeanNameGeneratorTests {
assertEquals(expectedGeneratedBeanName, beanName);
}
/**
* @since 4.0.1
* @see https://jira.spring.io/browse/SPR-11360
*/
@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
// SPR-11360
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
ComposedControllerAnnotationWithStringValue.class);

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.
@@ -33,7 +33,7 @@ import org.springframework.context.annotation6.Jsr330NamedForScanning;
import org.springframework.core.ResolvableType;
import org.springframework.util.ObjectUtils;
import static java.lang.String.*;
import static java.lang.String.format;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
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.
@@ -20,7 +20,6 @@ import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.annotation;
import java.lang.annotation.ElementType;

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.
@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.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.
@@ -513,9 +513,9 @@ public class ClassPathScanningCandidateComponentProviderTests {
private void assertBeanDefinitionType(Set<BeanDefinition> candidates,
Class<? extends BeanDefinition> expectedType) {
candidates.forEach(c -> {
assertThat(c, is(instanceOf(expectedType)));
});
candidates.forEach(c ->
assertThat(c, is(instanceOf(expectedType)))
);
}

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.
@@ -33,7 +33,6 @@ import example.scannable_implicitbasepackage.ComponentScanAnnotatedConfigWithImp
import example.scannable_implicitbasepackage.ConfigurableComponent;
import example.scannable_scoped.CustomScopeAnnotationBean;
import example.scannable_scoped.MyScope;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
@@ -393,7 +392,9 @@ class ComponentScanWithCustomTypeFilter {
@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
public static CustomAutowireConfigurer customAutowireConfigurer() {
CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
cac.setCustomQualifierTypes(new HashSet() {{ add(ComponentScanParserTests.CustomAnnotation.class); }});
cac.setCustomQualifierTypes(new HashSet() {{
add(ComponentScanParserTests.CustomAnnotation.class);
}});
return cac;
}

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.
@@ -24,7 +24,7 @@ import org.springframework.context.annotation.componentscan.level2.Level2Config;
import org.springframework.context.annotation.componentscan.level3.Level3Component;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests ensuring that configuration classes marked with @ComponentScan

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,9 +16,9 @@
package org.springframework.context.annotation;
import org.junit.Rule;
import example.scannable.FooService;
import example.scannable.ScopedProxyTestBean;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -26,10 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.util.SerializationTestUtils;
import example.scannable.FooService;
import example.scannable.ScopedProxyTestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -39,10 +36,6 @@ import static org.junit.Assert.*;
*/
public class ComponentScanParserScopedProxyTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void testDefaultScopedProxy() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
@@ -105,11 +98,10 @@ public class ComponentScanParserScopedProxyTests {
@Test
@SuppressWarnings("resource")
public void testInvalidConfigScopedProxy() throws Exception {
exception.expect(BeanDefinitionParsingException.class);
exception.expectMessage(containsString("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag"));
exception.expectMessage(containsString("Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]"));
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml");
assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() ->
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml"))
.withMessageContaining("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag")
.withMessageContaining("Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]");
}
}

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.
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests semantics of declaring {@link BeanFactoryPostProcessor}-returning @Bean

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.
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests cornering the issue reported in SPR-8080. If the product of a @Bean method

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.
@@ -31,8 +31,8 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**

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.
@@ -25,7 +25,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* @author Chris Beams

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.
@@ -24,7 +24,8 @@ import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeavi
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import static org.mockito.BDDMockito.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**
* Unit tests for @EnableLoadTimeWeaving

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.
@@ -36,7 +36,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Integration tests for {@link ImportBeanDefinitionRegistrar}.

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.
@@ -53,8 +53,10 @@ import org.springframework.lang.Nullable;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
/**
@@ -154,7 +156,7 @@ public class ImportSelectorTests {
ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
assertThat(TestImportGroup.imports.size(), equalTo(2));
assertThat(TestImportGroup.imports.size(), equalTo(2));
assertThat(TestImportGroup.allImports(), hasEntry(
is(ParentConfiguration1.class.getName()),
IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(),
@@ -529,7 +531,7 @@ public class ImportSelectorTests {
static Map<String, List<String>> allImports() {
return TestImportGroup.imports.entrySet()
.stream()
.collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
.collect(Collectors.toMap(entry -> entry.getKey().getClassName(),
Map.Entry::getValue));
}
private final List<Entry> instanceImports = new ArrayList<>();

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.
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests changes introduced for SPR-8874, allowing beans of primitive types to be looked

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,9 +25,7 @@ import java.util.Iterator;
import java.util.Properties;
import javax.inject.Inject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.FactoryBean;
@@ -40,6 +38,7 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.io.support.PropertySourceFactory;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -53,9 +52,6 @@ import static org.junit.Assert.*;
*/
public class PropertySourceAnnotationTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void withExplicitName() {
@@ -226,9 +222,9 @@ public class PropertySourceAnnotationTests {
@Test
public void withMissingPropertySource() {
thrown.expect(BeanDefinitionStoreException.class);
thrown.expectCause(isA(FileNotFoundException.class));
new AnnotationConfigApplicationContext(ConfigWithMissingPropertySource.class);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(ConfigWithMissingPropertySource.class))
.withCauseInstanceOf(FileNotFoundException.class);
}
@Test

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.
@@ -23,7 +23,7 @@ import org.springframework.context.annotation.role.ComponentWithRole;
import org.springframework.context.annotation.role.ComponentWithoutRole;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests the use of the @Role and @Description annotation on @Bean methods and @Component classes.

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.
@@ -17,13 +17,12 @@
package org.springframework.context.annotation;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.Is.*;
/**
@@ -31,9 +30,6 @@ import static org.hamcrest.core.Is.*;
*/
public class Spr12278Tests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context;
@After
@@ -59,10 +55,9 @@ public class Spr12278Tests {
@Test
public void componentTwoSpecificConstructorsNoHint() {
thrown.expect(BeanCreationException.class);
thrown.expectMessage(NoSuchMethodException.class.getName());
new AnnotationConfigApplicationContext(BaseConfiguration.class,
TwoSpecificConstructorsComponent.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(BaseConfiguration.class, TwoSpecificConstructorsComponent.class))
.withMessageContaining(NoSuchMethodException.class.getName());
}

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.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests to verify that FactoryBean semantics are the same in Configuration

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.
@@ -22,11 +22,13 @@ import org.junit.Test;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for SPR-8954, in which a custom {@link InstantiationAwareBeanPostProcessor}

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.
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests ensuring that configuration class bean names as expressed via @Configuration

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.
@@ -36,7 +36,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* System tests covering use of AspectJ {@link Aspect}s in conjunction with {@link Configuration} classes.

View File

@@ -24,9 +24,7 @@ import java.util.function.Supplier;
import javax.annotation.Resource;
import javax.inject.Provider;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
@@ -60,6 +58,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
/**
@@ -72,10 +71,6 @@ import static org.junit.Assert.*;
*/
public class ConfigurationClassProcessingTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void customBeanNameIsRespectedWhenConfiguredViaNameAttribute() {
customBeanNameIsRespected(ConfigWithBeanWithCustomName.class,
@@ -97,8 +92,8 @@ public class ConfigurationClassProcessingTests {
assertSame(testBeanSupplier.get(), ac.getBean(beanName));
// method name should not be registered
exception.expect(NoSuchBeanDefinitionException.class);
ac.getBean("methodName");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
ac.getBean("methodName"));
}
@Test
@@ -121,8 +116,8 @@ public class ConfigurationClassProcessingTests {
Arrays.stream(factory.getAliases(beanName)).map(factory::getBean).forEach(alias -> assertSame(testBean, alias));
// method name should not be registered
exception.expect(NoSuchBeanDefinitionException.class);
factory.getBean("methodName");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
factory.getBean("methodName"));
}
@Test // SPR-11830
@@ -145,8 +140,8 @@ public class ConfigurationClassProcessingTests {
@Test
public void testFinalBeanMethod() {
exception.expect(BeanDefinitionParsingException.class);
initBeanFactory(ConfigWithFinalBean.class);
assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() ->
initBeanFactory(ConfigWithFinalBean.class));
}
@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.
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* A configuration class that registers a non-static placeholder configurer {@code @Bean}

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.
@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Ensures that @Configuration is supported properly as a meta-annotation.

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.
@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests that @Import may be used both as a locally declared and meta-declared

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.
@@ -23,7 +23,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Reproduces SPR-8756, which has been marked as "won't fix" for reasons

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.
@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

View File

@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.configuration.spr9031.scanpackage.Spr9031Component;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests cornering bug SPR-9031.

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.
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.spr10546.scanpackage.AEnclosingConfig;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* @author Rob Winch

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.
@@ -25,7 +25,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.stereotype.Component;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests cornering the regression reported in SPR-8761.

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.annotation6;
import org.springframework.stereotype.Component;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.annotation6;
import org.springframework.context.annotation.Bean;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.annotation6;
import javax.inject.Named;

View File

@@ -31,9 +31,7 @@ import javax.annotation.PostConstruct;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
@@ -66,6 +64,7 @@ import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@@ -76,9 +75,6 @@ import static org.junit.Assert.*;
*/
public class AnnotationDrivenEventListenerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private ConfigurableApplicationContext context;
private EventCollector eventCollector;
@@ -162,10 +158,10 @@ public class AnnotationDrivenEventListenerTests {
failingContext.register(BasicConfiguration.class,
InvalidMethodSignatureEventListener.class);
this.thrown.expect(BeanInitializationException.class);
this.thrown.expectMessage(InvalidMethodSignatureEventListener.class.getName());
this.thrown.expectMessage("cannotBeCalled");
failingContext.refresh();
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() ->
failingContext.refresh())
.withMessageContaining(InvalidMethodSignatureEventListener.class.getName())
.withMessageContaining("cannotBeCalled");
}
@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.
@@ -49,6 +49,7 @@ import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;
/**

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.
@@ -20,9 +20,7 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.ApplicationContext;
@@ -33,9 +31,10 @@ import org.springframework.core.ResolvableTypeProvider;
import org.springframework.core.annotation.Order;
import org.springframework.util.ReflectionUtils;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
/**
@@ -43,9 +42,6 @@ import static org.mockito.Mockito.*;
*/
public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEventListenerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final SampleEvents sampleEvents = spy(new SampleEvents());
private final ApplicationContext context = mock(ApplicationContext.class);
@@ -139,23 +135,23 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
public void listenerWithTooManyParameters() {
Method method = ReflectionUtils.findMethod(
SampleEvents.class, "tooManyParameters", String.class, String.class);
this.thrown.expect(IllegalStateException.class);
createTestInstance(method);
assertThatIllegalStateException().isThrownBy(() ->
createTestInstance(method));
}
@Test
public void listenerWithNoParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, "noParameter");
this.thrown.expect(IllegalStateException.class);
createTestInstance(method);
assertThatIllegalStateException().isThrownBy(() ->
createTestInstance(method));
}
@Test
public void listenerWithMoreThanOneParameter() {
Method method = ReflectionUtils.findMethod(
SampleEvents.class, "moreThanOneParameter", String.class, Integer.class);
this.thrown.expect(IllegalStateException.class);
createTestInstance(method);
assertThatIllegalStateException().isThrownBy(() ->
createTestInstance(method));
}
@Test
@@ -225,10 +221,10 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
SampleEvents.class, "generateRuntimeException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Test exception");
this.thrown.expectCause(is((Throwable) isNull()));
invokeListener(method, event);
assertThatIllegalStateException().isThrownBy(() ->
invokeListener(method, event))
.withMessageContaining("Test exception")
.withNoCause();
}
@Test
@@ -237,9 +233,9 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
SampleEvents.class, "generateCheckedException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail");
this.thrown.expect(UndeclaredThrowableException.class);
this.thrown.expectCause(is(instanceOf(IOException.class)));
invokeListener(method, event);
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(() ->
invokeListener(method, event))
.withCauseInstanceOf(IOException.class);
}
@Test
@@ -254,9 +250,9 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
InvalidProxyTestBean.class, "handleIt2", ApplicationEvent.class);
StaticApplicationListenerMethodAdapter listener =
new StaticApplicationListenerMethodAdapter(method, bean);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("handleIt2");
listener.onApplicationEvent(createGenericTestEvent("test"));
assertThatIllegalStateException().isThrownBy(() ->
listener.onApplicationEvent(createGenericTestEvent("test")))
.withMessageContaining("handleIt2");
}
@Test

View File

@@ -32,7 +32,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* @author Dmitriy Kopylenko

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.
@@ -17,6 +17,7 @@
package org.springframework.context.expression;
import org.junit.Test;
import org.springframework.beans.factory.BeanIsNotAFactoryException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

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.
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelCompiler;
import org.springframework.expression.spel.standard.SpelExpressionParser;

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.
@@ -19,14 +19,13 @@ package org.springframework.context.index;
import java.io.IOException;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests for {@link CandidateComponentsIndexLoader}.
@@ -35,10 +34,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
*/
public class CandidateComponentsIndexLoaderTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void validateIndexIsDisabledByDefault() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(null);
@@ -102,11 +97,10 @@ public class CandidateComponentsIndexLoaderTests {
@Test
public void loadIndexWithException() throws IOException {
final IOException cause = new IOException("test exception");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to load indexes");
this.thrown.expectCause(is(cause));
CandidateComponentsIndexLoader.loadIndex(new CandidateComponentsTestClassLoader(
getClass().getClassLoader(), cause));
assertThatIllegalStateException().isThrownBy(() -> {
CandidateComponentsTestClassLoader classLoader = new CandidateComponentsTestClassLoader(getClass().getClassLoader(), cause);
CandidateComponentsIndexLoader.loadIndex(classLoader);
}).withMessageContaining("Unable to load indexes").withCause(cause);
}
}

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,7 +23,7 @@ import java.util.Set;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**

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.
@@ -25,7 +25,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests covering the integration of the {@link Environment} into

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.
@@ -31,9 +31,9 @@ import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.StandardEnvironmentTests;
import org.springframework.stereotype.Component;
import static java.lang.String.format;
import static java.lang.String.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Tests integration between Environment and SecurityManagers. See SPR-9970.

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.support;
import org.springframework.beans.factory.FactoryBean;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.context.support;
import org.junit.Test;
@@ -6,7 +22,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.util.ClassUtils;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for {@link GenericXmlApplicationContext}.

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.
@@ -19,9 +19,7 @@ package org.springframework.context.support;
import java.util.Optional;
import java.util.Properties;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -35,6 +33,7 @@ import org.springframework.mock.env.MockEnvironment;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
@@ -47,9 +46,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
*/
public class PropertySourcesPlaceholderConfigurerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void replacementFromEnvironmentProperties() {
@@ -251,7 +247,9 @@ public class PropertySourcesPlaceholderConfigurerTests {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setLocalOverride(override);
ppc.setProperties(new Properties() {{ setProperty("foo", "local"); }});
ppc.setProperties(new Properties() {{
setProperty("foo", "local");
}});
ppc.setEnvironment(new MockEnvironment().withProperty("foo", "enclosing"));
ppc.postProcessBeanFactory(bf);
if (override) {
@@ -327,8 +325,8 @@ public class PropertySourcesPlaceholderConfigurerTests {
@Test
public void getAppliedPropertySourcesTooEarly() throws Exception {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
thrown.expect(IllegalStateException.class);
ppc.getAppliedPropertySources();
assertThatIllegalStateException().isThrownBy(
ppc::getAppliedPropertySources);
}
@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.
@@ -21,7 +21,6 @@ import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
@@ -30,7 +29,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
/**

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,9 +21,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
@@ -35,6 +33,7 @@ import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
/**
@@ -55,9 +54,6 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
protected StaticApplicationContext sac;
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
@Override
@@ -183,8 +179,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
exception.expect(NoSuchMessageException.class);
sac.getMessage(resolvable4, Locale.US);
assertThatExceptionOfType(NoSuchMessageException.class).isThrownBy(() ->
sac.getMessage(resolvable4, Locale.US));
}
@Override

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.
@@ -26,13 +26,12 @@ import java.util.TimeZone;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/**
@@ -45,9 +44,6 @@ public class DateFormatterTests {
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldPrintAndParseDefault() throws Exception {
@@ -175,9 +171,9 @@ public class DateFormatterTests {
public void shouldThrowOnUnsupportedStylePattern() throws Exception {
DateFormatter formatter = new DateFormatter();
formatter.setStylePattern("OO");
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Unsupported style pattern 'OO'");
formatter.parse("2009", Locale.US);
assertThatIllegalStateException().isThrownBy(() ->
formatter.parse("2009", Locale.US))
.withMessageContaining("Unsupported style pattern 'OO'");
}
@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.
@@ -20,8 +20,8 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Phillip Webb

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,8 +21,8 @@ import java.time.format.FormatStyle;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Phillip Webb

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.
@@ -34,9 +34,7 @@ import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.FactoryBean;
@@ -57,6 +55,8 @@ import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.*;
/**
@@ -72,9 +72,6 @@ import static org.junit.Assert.*;
*/
public class MBeanExporterTests extends AbstractMBeanServerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor";
@@ -85,8 +82,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
listeners.put("*", null);
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setNotificationListenerMappings(listeners);
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setNotificationListenerMappings(listeners));
}
@Test
@@ -179,8 +176,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertNotNull(instance);
thrown.expect(InstanceNotFoundException.class);
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
assertThatExceptionOfType(InstanceNotFoundException.class).isThrownBy(() ->
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false")));
}
finally {
ctx.close();
@@ -484,36 +481,36 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
@Test
public void testSetAutodetectModeToOutOfRangeNegativeValue() {
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setAutodetectMode(-1);
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setAutodetectMode(-1));
}
@Test
public void testSetAutodetectModeToOutOfRangePositiveValue() {
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setAutodetectMode(5);
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setAutodetectMode(5));
}
@Test
public void testSetAutodetectModeNameToAnEmptyString() {
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setAutodetectModeName("");
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setAutodetectModeName(""));
}
@Test
public void testSetAutodetectModeNameToAWhitespacedString() {
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setAutodetectModeName(" \t");
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setAutodetectModeName(" \t"));
}
@Test
public void testSetAutodetectModeNameToARubbishValue() {
MBeanExporter exporter = new MBeanExporter();
thrown.expect(IllegalArgumentException.class);
exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!");
assertThatIllegalArgumentException().isThrownBy(() ->
exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!"));
}
@Test
@@ -522,16 +519,16 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
Map<String, Object> beans = new HashMap<>();
beans.put(OBJECT_NAME, "beanName");
exporter.setBeans(beans);
thrown.expect(MBeanExportException.class);
start(exporter);
assertThatExceptionOfType(MBeanExportException.class).isThrownBy(() ->
start(exporter));
}
@Test
public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
thrown.expect(MBeanExportException.class);
start(exporter);
assertThatExceptionOfType(MBeanExportException.class).isThrownBy(() ->
start(exporter));
}
@Test // SPR-2158

View File

@@ -20,9 +20,7 @@ import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -41,6 +39,7 @@ import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
/**
@@ -52,9 +51,6 @@ import static org.junit.Assert.*;
*/
public class EnableMBeanExportConfigurationTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext ctx;
@@ -85,19 +81,19 @@ public class EnableMBeanExportConfigurationTests {
@Test
@SuppressWarnings("resource")
public void testPackagePrivateExtensionCantBeExposed() {
this.thrown.expect(InvalidMetadataException.class);
this.thrown.expectMessage(PackagePrivateTestBean.class.getName());
this.thrown.expectMessage("must be public");
new AnnotationConfigApplicationContext(PackagePrivateConfiguration.class);
assertThatExceptionOfType(InvalidMetadataException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(PackagePrivateConfiguration.class))
.withMessageContaining(PackagePrivateTestBean.class.getName())
.withMessageContaining("must be public");
}
@Test
@SuppressWarnings("resource")
public void testPackagePrivateImplementationCantBeExposed() {
this.thrown.expect(InvalidMetadataException.class);
this.thrown.expectMessage(PackagePrivateAnnotationTestBean.class.getName());
this.thrown.expectMessage("must be public");
new AnnotationConfigApplicationContext(PackagePrivateInterfaceImplementationConfiguration.class);
assertThatExceptionOfType(InvalidMetadataException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(PackagePrivateInterfaceImplementationConfiguration.class))
.withMessageContaining(PackagePrivateAnnotationTestBean.class.getName())
.withMessageContaining("must be public");
}
@Test

View File

@@ -1,3 +1,18 @@
/*
* 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
*
* 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.
*/
package org.springframework.jmx.export.assembler;

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.
@@ -21,8 +21,8 @@ import javax.naming.spi.NamingManager;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests for {@link JndiLocatorDelegate}.

View File

@@ -1,6 +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.

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.
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.*;
/**
* Unit tests for {@link AnnotationAsyncExecutionInterceptor}.

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.
@@ -91,7 +91,7 @@ public class AsyncResultTests {
String value = "val";
final Set<String> values = new HashSet<>(1);
ListenableFuture<String> future = AsyncResult.forValue(value);
future.addCallback(values::add, (ex) -> fail("Failure callback not expected: " + ex));
future.addCallback(values::add, ex -> fail("Failure callback not expected: " + ex));
assertSame(value, values.iterator().next());
assertSame(value, future.get());
assertSame(value, future.completable().get());
@@ -103,7 +103,7 @@ public class AsyncResultTests {
IOException ex = new IOException();
final Set<Throwable> values = new HashSet<>(1);
ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
future.addCallback((result) -> fail("Success callback not expected: " + result), values::add);
future.addCallback(result -> fail("Success callback not expected: " + result), values::add);
assertSame(ex, values.iterator().next());
try {
future.get();

View File

@@ -320,7 +320,7 @@ public class EnableAsyncTests {
Awaitility.await()
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(()-> asyncBean.getThreadOfExecution() != null);
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-"));
ctx.close();
}

View File

@@ -21,8 +21,8 @@ import org.junit.Test;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
* Tests ensuring that tasks scheduled using the <task:scheduled> element
* are never marked lazy, even if the enclosing <beans> element declares
* Tests ensuring that tasks scheduled using the &lt;task:scheduled&gt; element
* are never marked lazy, even if the enclosing &lt;beans&gt; element declares
* default-lazy-init="true". See SPR-8498
*
* @author Mike Youngstrom

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,11 +16,11 @@
package org.springframework.scripting.groovy;
import groovy.lang.GroovyClassLoader;
import java.lang.reflect.Method;
import groovy.lang.GroovyClassLoader;
import org.junit.Test;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.util.ReflectionUtils;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.scripting.groovy;
import java.lang.annotation.Documented;

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.scripting.groovy;
public interface TestService {

View File

@@ -1,3 +1,19 @@
/*
* 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
*
* 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.
*/
package org.springframework.scripting.groovy;
@Log

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.
@@ -32,7 +32,7 @@ import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* @author Rick Evans

View File

@@ -1,19 +1,3 @@
/*
* Copyright 2002-2012 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.
*/
/**
* The simplest implementation of the JNDI SPI that could possibly work.
*

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.
@@ -19,9 +19,7 @@ package org.springframework.validation;
import java.beans.PropertyEditorSupport;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.NotWritablePropertyException;
@@ -30,6 +28,7 @@ import org.springframework.beans.PropertyValue;
import org.springframework.tests.sample.beans.FieldAccessBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.*;
/**
@@ -39,9 +38,6 @@ import static org.junit.Assert.*;
*/
public class DataBinderFieldAccessTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void bindingNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
@@ -147,8 +143,8 @@ public class DataBinderFieldAccessTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry"));
thrown.expect(NullValueInNestedPathException.class);
binder.bind(pvs);
assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() ->
binder.bind(pvs));
}
@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.
@@ -36,9 +36,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.InvalidPropertyException;
@@ -69,6 +67,7 @@ import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.*;
/**
@@ -79,10 +78,6 @@ import static org.junit.Assert.*;
*/
public class DataBinderTests {
@Rule
public final ExpectedException expectedException = ExpectedException.none();
@Test
public void testBindingNoErrors() throws BindException {
TestBean rod = new TestBean();
@@ -2022,12 +2017,11 @@ public class DataBinderTests {
@Test // SPR-14888
public void testSetAutoGrowCollectionLimitAfterInitialization() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
binder.setAutoGrowCollectionLimit(257);
assertThatIllegalStateException().isThrownBy(() ->
binder.setAutoGrowCollectionLimit(257))
.withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
@Test // SPR-15009
@@ -2092,13 +2086,13 @@ public class DataBinderTests {
@Test // SPR-15009
public void testCallSetMessageCodesResolverTwice() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("DataBinder is already initialized with MessageCodesResolver");
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setMessageCodesResolver(new DefaultMessageCodesResolver());
binder.setMessageCodesResolver(new DefaultMessageCodesResolver());
assertThatIllegalStateException().isThrownBy(() ->
binder.setMessageCodesResolver(new DefaultMessageCodesResolver()))
.withMessageContaining("DataBinder is already initialized with MessageCodesResolver");
}

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,8 +21,8 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.validation.DefaultMessageCodesResolver.Format;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests for {@link DefaultMessageCodesResolver}.

View File

@@ -474,10 +474,10 @@ public class SpringValidatorAdapterTests {
.addPropertyNode(f.getName())
.addConstraintViolation();
}
} catch (IllegalAccessException ex) {
}
catch (IllegalAccessException ex) {
throw new IllegalStateException(ex);
}
});
return fieldsErros.isEmpty();
}