Migrate JUnit 4 assertions to AssertJ

Migrate all existing JUnit 4 `assert...` based assertions to AssertJ
and add a checkstyle rule to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:51:39 -07:00
parent 95a9d46a87
commit 9d74da006c
1636 changed files with 37861 additions and 40390 deletions

View File

@@ -24,12 +24,8 @@ import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/**
@@ -43,73 +39,80 @@ public class CaffeineCacheManagerTests {
public void testDynamicMode() {
CacheManager cm = new CaffeineCacheManager();
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof CaffeineCache);
boolean condition2 = cache1 instanceof CaffeineCache;
assertThat(condition2).isTrue();
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
assertThat(cache1).isSameAs(cache1again);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof CaffeineCache);
boolean condition1 = cache2 instanceof CaffeineCache;
assertThat(condition1).isTrue();
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
assertThat(cache2).isSameAs(cache2again);
Cache cache3 = cm.getCache("c3");
assertTrue(cache3 instanceof CaffeineCache);
boolean condition = cache3 instanceof CaffeineCache;
assertThat(condition).isTrue();
Cache cache3again = cm.getCache("c3");
assertSame(cache3again, cache3);
assertThat(cache3).isSameAs(cache3again);
cache1.put("key1", "value1");
assertEquals("value1", cache1.get("key1").get());
assertThat(cache1.get("key1").get()).isEqualTo("value1");
cache1.put("key2", 2);
assertEquals(2, cache1.get("key2").get());
assertThat(cache1.get("key2").get()).isEqualTo(2);
cache1.put("key3", null);
assertNull(cache1.get("key3").get());
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertNull(cache1.get("key3"));
assertThat(cache1.get("key3")).isNull();
}
@Test
public void testStaticMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof CaffeineCache);
boolean condition3 = cache1 instanceof CaffeineCache;
assertThat(condition3).isTrue();
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
assertThat(cache1).isSameAs(cache1again);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof CaffeineCache);
boolean condition2 = cache2 instanceof CaffeineCache;
assertThat(condition2).isTrue();
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
assertThat(cache2).isSameAs(cache2again);
Cache cache3 = cm.getCache("c3");
assertNull(cache3);
assertThat(cache3).isNull();
cache1.put("key1", "value1");
assertEquals("value1", cache1.get("key1").get());
assertThat(cache1.get("key1").get()).isEqualTo("value1");
cache1.put("key2", 2);
assertEquals(2, cache1.get("key2").get());
assertThat(cache1.get("key2").get()).isEqualTo(2);
cache1.put("key3", null);
assertNull(cache1.get("key3").get());
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertNull(cache1.get("key3"));
assertThat(cache1.get("key3")).isNull();
cm.setAllowNullValues(false);
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x instanceof CaffeineCache);
assertTrue(cache1x != cache1);
boolean condition1 = cache1x instanceof CaffeineCache;
assertThat(condition1).isTrue();
assertThat(cache1x != cache1).isTrue();
Cache cache2x = cm.getCache("c2");
assertTrue(cache2x instanceof CaffeineCache);
assertTrue(cache2x != cache2);
boolean condition = cache2x instanceof CaffeineCache;
assertThat(condition).isTrue();
assertThat(cache2x != cache2).isTrue();
Cache cache3x = cm.getCache("c3");
assertNull(cache3x);
assertThat(cache3x).isNull();
cache1x.put("key1", "value1");
assertEquals("value1", cache1x.get("key1").get());
assertThat(cache1x.get("key1").get()).isEqualTo("value1");
cache1x.put("key2", 2);
assertEquals(2, cache1x.get("key2").get());
assertThat(cache1x.get("key2").get()).isEqualTo(2);
cm.setAllowNullValues(true);
Cache cache1y = cm.getCache("c1");
cache1y.put("key3", null);
assertNull(cache1y.get("key3").get());
assertThat(cache1y.get("key3").get()).isNull();
cache1y.evict("key3");
assertNull(cache1y.get("key3"));
assertThat(cache1y.get("key3")).isNull();
}
@Test
@@ -120,11 +123,11 @@ public class CaffeineCacheManagerTests {
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().maximumSize(10);
cm.setCaffeine(caffeine);
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x != cache1);
assertThat(cache1x != cache1).isTrue();
cm.setCaffeine(caffeine); // Set same instance
Cache cache1xx = cm.getCache("c1");
assertSame(cache1x, cache1xx);
assertThat(cache1xx).isSameAs(cache1x);
}
@Test
@@ -134,7 +137,7 @@ public class CaffeineCacheManagerTests {
cm.setCaffeineSpec(CaffeineSpec.parse("maximumSize=10"));
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x != cache1);
assertThat(cache1x != cache1).isTrue();
}
@Test
@@ -144,7 +147,7 @@ public class CaffeineCacheManagerTests {
cm.setCacheSpecification("maximumSize=10");
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x != cache1);
assertThat(cache1x != cache1).isTrue();
}
@Test
@@ -155,19 +158,19 @@ public class CaffeineCacheManagerTests {
CacheLoader<Object, Object> loader = mockCacheLoader();
cm.setCacheLoader(loader);
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x != cache1);
assertThat(cache1x != cache1).isTrue();
cm.setCacheLoader(loader); // Set same instance
Cache cache1xx = cm.getCache("c1");
assertSame(cache1x, cache1xx);
assertThat(cache1xx).isSameAs(cache1x);
}
@Test
public void setCacheNameNullRestoreDynamicMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
assertNull(cm.getCache("someCache"));
assertThat(cm.getCache("someCache")).isNull();
cm.setCacheNames(null);
assertNotNull(cm.getCache("someCache"));
assertThat(cm.getCache("someCache")).isNotNull();
}
@Test
@@ -184,11 +187,10 @@ public class CaffeineCacheManagerTests {
});
Cache cache1 = cm.getCache("c1");
Cache.ValueWrapper value = cache1.get("ping");
assertNotNull(value);
assertEquals("pong", value.get());
assertThat(value).isNotNull();
assertThat(value.get()).isEqualTo("pong");
assertThatIllegalArgumentException().isThrownBy(() ->
assertNull(cache1.get("foo")))
assertThatIllegalArgumentException().isThrownBy(() -> assertThat(cache1.get("foo")).isNull())
.withMessageContaining("I only know ping");
}

View File

@@ -23,9 +23,7 @@ import org.junit.Test;
import org.springframework.cache.AbstractValueAdaptingCacheTests;
import org.springframework.cache.Cache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ben Manes
@@ -70,13 +68,15 @@ public class CaffeineCacheTests extends AbstractValueAdaptingCacheTests<Caffeine
Object key = new Object();
Object value = null;
assertNull(cache.get(key));
assertNull(cache.putIfAbsent(key, value));
assertEquals(value, cache.get(key).get());
assertThat(cache.get(key)).isNull();
assertThat(cache.putIfAbsent(key, value)).isNull();
assertThat(cache.get(key).get()).isEqualTo(value);
Cache.ValueWrapper wrapper = cache.putIfAbsent(key, "anotherValue");
assertNotNull(wrapper); // A value is set but is 'null'
assertEquals(null, wrapper.get());
assertEquals(value, cache.get(key).get()); // not changed
// A value is set but is 'null'
assertThat(wrapper).isNotNull();
assertThat(wrapper.get()).isEqualTo(null);
// not changed
assertThat(cache.get(key).get()).isEqualTo(value);
}
}

View File

@@ -29,8 +29,7 @@ import org.springframework.cache.AbstractCacheTests;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Costin Leau
@@ -84,10 +83,10 @@ public class EhCacheCacheTests extends AbstractCacheTests<EhCacheCache> {
brancusi.setTimeToLive(3);
nativeCache.put(brancusi);
assertEquals(value, cache.get(key).get());
assertThat(cache.get(key).get()).isEqualTo(value);
// wait for the entry to expire
Thread.sleep(5 * 1000);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
}

View File

@@ -29,11 +29,8 @@ import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Juergen Hoeller
@@ -46,14 +43,14 @@ public class EhCacheSupportTests {
public void testBlankCacheManager() {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setCacheManagerName("myCacheManager");
assertEquals(CacheManager.class, cacheManagerFb.getObjectType());
assertTrue("Singleton property", cacheManagerFb.isSingleton());
assertThat(cacheManagerFb.getObjectType()).isEqualTo(CacheManager.class);
assertThat(cacheManagerFb.isSingleton()).as("Singleton property").isTrue();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0);
assertThat(cm.getCacheNames().length == 0).as("Loaded CacheManager with no caches").isTrue();
Cache myCache1 = cm.getCache("myCache1");
assertTrue("No myCache1 defined", myCache1 == null);
assertThat(myCache1 == null).as("No myCache1 defined").isTrue();
}
finally {
cacheManagerFb.destroy();
@@ -65,13 +62,13 @@ public class EhCacheSupportTests {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
try {
cacheManagerFb.setCacheManagerName("myCacheManager");
assertEquals(CacheManager.class, cacheManagerFb.getObjectType());
assertTrue("Singleton property", cacheManagerFb.isSingleton());
assertThat(cacheManagerFb.getObjectType()).isEqualTo(CacheManager.class);
assertThat(cacheManagerFb.isSingleton()).as("Singleton property").isTrue();
cacheManagerFb.afterPropertiesSet();
CacheManager cm = cacheManagerFb.getObject();
assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0);
assertThat(cm.getCacheNames().length == 0).as("Loaded CacheManager with no caches").isTrue();
Cache myCache1 = cm.getCache("myCache1");
assertTrue("No myCache1 defined", myCache1 == null);
assertThat(myCache1 == null).as("No myCache1 defined").isTrue();
EhCacheManagerFactoryBean cacheManagerFb2 = new EhCacheManagerFactoryBean();
cacheManagerFb2.setCacheManagerName("myCacheManager");
@@ -87,21 +84,21 @@ public class EhCacheSupportTests {
public void testAcceptExistingCacheManager() {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setCacheManagerName("myCacheManager");
assertEquals(CacheManager.class, cacheManagerFb.getObjectType());
assertTrue("Singleton property", cacheManagerFb.isSingleton());
assertThat(cacheManagerFb.getObjectType()).isEqualTo(CacheManager.class);
assertThat(cacheManagerFb.isSingleton()).as("Singleton property").isTrue();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
assertTrue("Loaded CacheManager with no caches", cm.getCacheNames().length == 0);
assertThat(cm.getCacheNames().length == 0).as("Loaded CacheManager with no caches").isTrue();
Cache myCache1 = cm.getCache("myCache1");
assertTrue("No myCache1 defined", myCache1 == null);
assertThat(myCache1 == null).as("No myCache1 defined").isTrue();
EhCacheManagerFactoryBean cacheManagerFb2 = new EhCacheManagerFactoryBean();
cacheManagerFb2.setCacheManagerName("myCacheManager");
cacheManagerFb2.setAcceptExisting(true);
cacheManagerFb2.afterPropertiesSet();
CacheManager cm2 = cacheManagerFb2.getObject();
assertSame(cm, cm2);
assertThat(cm2).isSameAs(cm);
cacheManagerFb2.destroy();
}
finally {
@@ -116,10 +113,10 @@ public class EhCacheSupportTests {
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
assertTrue("Correct number of caches loaded", cm.getCacheNames().length == 1);
assertThat(cm.getCacheNames().length == 1).as("Correct number of caches loaded").isTrue();
Cache myCache1 = cm.getCache("myCache1");
assertFalse("myCache1 is not eternal", myCache1.getCacheConfiguration().isEternal());
assertTrue("myCache1.maxElements == 300", myCache1.getCacheConfiguration().getMaxEntriesLocalHeap() == 300);
assertThat(myCache1.getCacheConfiguration().isEternal()).as("myCache1 is not eternal").isFalse();
assertThat(myCache1.getCacheConfiguration().getMaxEntriesLocalHeap() == 300).as("myCache1.maxElements == 300").isTrue();
}
finally {
cacheManagerFb.destroy();
@@ -143,8 +140,8 @@ public class EhCacheSupportTests {
try {
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
Class<? extends Ehcache> objectType = cacheFb.getObjectType();
assertTrue(Ehcache.class.isAssignableFrom(objectType));
assertTrue("Singleton property", cacheFb.isSingleton());
assertThat(Ehcache.class.isAssignableFrom(objectType)).isTrue();
assertThat(cacheFb.isSingleton()).as("Singleton property").isTrue();
if (useCacheManagerFb) {
cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass()));
@@ -158,14 +155,14 @@ public class EhCacheSupportTests {
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
Class<? extends Ehcache> objectType2 = cacheFb.getObjectType();
assertSame(objectType, objectType2);
assertThat(objectType2).isSameAs(objectType);
CacheConfiguration config = cache.getCacheConfiguration();
assertEquals("myCache1", cache.getName());
assertThat(cache.getName()).isEqualTo("myCache1");
if (useCacheManagerFb){
assertEquals("myCache1.maxElements", 300, config.getMaxEntriesLocalHeap());
assertThat(config.getMaxEntriesLocalHeap()).as("myCache1.maxElements").isEqualTo(300);
}
else {
assertEquals("myCache1.maxElements", 10000, config.getMaxEntriesLocalHeap());
assertThat(config.getMaxEntriesLocalHeap()).as("myCache1.maxElements").isEqualTo(10000);
}
// Cache region is not defined. Should create one with default properties.
@@ -177,12 +174,12 @@ public class EhCacheSupportTests {
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache", cache.getName());
assertTrue("default maxElements is correct", config.getMaxEntriesLocalHeap() == 10000);
assertFalse("default eternal is correct", config.isEternal());
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120);
assertTrue("default diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 120);
assertThat(cache.getName()).isEqualTo("undefinedCache");
assertThat(config.getMaxEntriesLocalHeap() == 10000).as("default maxElements is correct").isTrue();
assertThat(config.isEternal()).as("default eternal is correct").isFalse();
assertThat(config.getTimeToLiveSeconds() == 120).as("default timeToLive is correct").isTrue();
assertThat(config.getTimeToIdleSeconds() == 120).as("default timeToIdle is correct").isTrue();
assertThat(config.getDiskExpiryThreadIntervalSeconds() == 120).as("default diskExpiryThreadIntervalSeconds is correct").isTrue();
// overriding the default properties
cacheFb = new EhCacheFactoryBean();
@@ -198,11 +195,11 @@ public class EhCacheSupportTests {
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache2", cache.getName());
assertTrue("overridden maxElements is correct", config.getMaxEntriesLocalHeap() == 5);
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 8);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 7);
assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
assertThat(cache.getName()).isEqualTo("undefinedCache2");
assertThat(config.getMaxEntriesLocalHeap() == 5).as("overridden maxElements is correct").isTrue();
assertThat(config.getTimeToLiveSeconds() == 8).as("default timeToLive is correct").isTrue();
assertThat(config.getTimeToIdleSeconds() == 7).as("default timeToIdle is correct").isTrue();
assertThat(config.getDiskExpiryThreadIntervalSeconds() == 10).as("overridden diskExpiryThreadIntervalSeconds is correct").isTrue();
}
finally {
if (cacheManagerFbInitialized) {
@@ -224,10 +221,11 @@ public class EhCacheSupportTests {
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setBlocking(true);
assertEquals(cacheFb.getObjectType(), BlockingCache.class);
assertThat(BlockingCache.class).isEqualTo(cacheFb.getObjectType());
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof BlockingCache);
boolean condition = myCache1 instanceof BlockingCache;
assertThat(condition).isTrue();
}
finally {
cacheManagerFb.destroy();
@@ -244,11 +242,12 @@ public class EhCacheSupportTests {
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setCacheEntryFactory(key -> key);
assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
assertThat(SelfPopulatingCache.class).isEqualTo(cacheFb.getObjectType());
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof SelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getObjectValue());
boolean condition = myCache1 instanceof SelfPopulatingCache;
assertThat(condition).isTrue();
assertThat(myCache1.get("myKey1").getObjectValue()).isEqualTo("myKey1");
}
finally {
cacheManagerFb.destroy();
@@ -273,11 +272,12 @@ public class EhCacheSupportTests {
public void updateEntryValue(Object key, Object value) {
}
});
assertEquals(cacheFb.getObjectType(), UpdatingSelfPopulatingCache.class);
assertThat(UpdatingSelfPopulatingCache.class).isEqualTo(cacheFb.getObjectType());
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof UpdatingSelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getObjectValue());
boolean condition = myCache1 instanceof UpdatingSelfPopulatingCache;
assertThat(condition).isTrue();
assertThat(myCache1.get("myKey1").getObjectValue()).isEqualTo("myKey1");
}
finally {
cacheManagerFb.destroy();

View File

@@ -33,12 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -73,7 +67,7 @@ public abstract class AbstractJCacheAnnotationTests {
Object first = service.cache(keyItem);
Object second = service.cache(keyItem);
assertSame(first, second);
assertThat(second).isSameAs(first);
}
@Test
@@ -81,16 +75,16 @@ public abstract class AbstractJCacheAnnotationTests {
Cache cache = getCache(DEFAULT_CACHE);
String keyItem = name.getMethodName();
assertNull(cache.get(keyItem));
assertThat(cache.get(keyItem)).isNull();
Object first = service.cacheNull(keyItem);
Object second = service.cacheNull(keyItem);
assertSame(first, second);
assertThat(second).isSameAs(first);
Cache.ValueWrapper wrapper = cache.get(keyItem);
assertNotNull(wrapper);
assertSame(first, wrapper.get());
assertNull("Cached value should be null", wrapper.get());
assertThat(wrapper).isNotNull();
assertThat(wrapper.get()).isSameAs(first);
assertThat(wrapper.get()).as("Cached value should be null").isNull();
}
@Test
@@ -99,14 +93,14 @@ public abstract class AbstractJCacheAnnotationTests {
Cache cache = getCache(EXCEPTION_CACHE);
Object key = createKey(keyItem);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.cacheWithException(keyItem, true));
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(UnsupportedOperationException.class, result.get().getClass());
assertThat(result).isNotNull();
assertThat(result.get().getClass()).isEqualTo(UnsupportedOperationException.class);
}
@Test
@@ -115,11 +109,11 @@ public abstract class AbstractJCacheAnnotationTests {
Cache cache = getCache(EXCEPTION_CACHE);
Object key = createKey(keyItem);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatNullPointerException().isThrownBy(() ->
service.cacheWithException(keyItem, false));
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -128,13 +122,13 @@ public abstract class AbstractJCacheAnnotationTests {
Cache cache = getCache(EXCEPTION_CACHE);
Object key = createKey(keyItem);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatIOException().isThrownBy(() ->
service.cacheWithCheckedException(keyItem, true));
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(IOException.class, result.get().getClass());
assertThat(result).isNotNull();
assertThat(result.get().getClass()).isEqualTo(IOException.class);
}
@@ -169,7 +163,7 @@ public abstract class AbstractJCacheAnnotationTests {
Object first = service.cacheAlwaysInvoke(keyItem);
Object second = service.cacheAlwaysInvoke(keyItem);
assertNotSame(first, second);
assertThat(second).isNotSameAs(first);
}
@Test
@@ -178,7 +172,8 @@ public abstract class AbstractJCacheAnnotationTests {
Object first = service.cacheWithPartialKey(keyItem, true);
Object second = service.cacheWithPartialKey(keyItem, false);
assertSame(first, second); // second argument not used, see config
// second argument not used, see config
assertThat(second).isSameAs(first);
}
@Test
@@ -189,7 +184,8 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
service.cacheWithCustomCacheResolver(keyItem);
assertNull(cache.get(key)); // Cache in mock cache
// Cache in mock cache
assertThat(cache.get(key)).isNull();
}
@Test
@@ -200,7 +196,7 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
service.cacheWithCustomKeyGenerator(keyItem, "ignored");
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -210,13 +206,13 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
service.put(keyItem, value);
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(value, result.get());
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
@Test
@@ -226,14 +222,14 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.putWithException(keyItem, value, true));
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(value, result.get());
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
@Test
@@ -243,11 +239,11 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatNullPointerException().isThrownBy(() ->
service.putWithException(keyItem, value, false));
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -257,13 +253,13 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
service.earlyPut(keyItem, value);
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(value, result.get());
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
@Test
@@ -273,14 +269,14 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.earlyPutWithException(keyItem, value, true));
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(value, result.get());
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
@Test
@@ -290,13 +286,13 @@ public abstract class AbstractJCacheAnnotationTests {
Object key = createKey(keyItem);
Object value = new Object();
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
assertThatNullPointerException().isThrownBy(() ->
service.earlyPutWithException(keyItem, value, false));
// This will be cached anyway as the earlyPut has updated the cache before
Cache.ValueWrapper result = cache.get(key);
assertNotNull(result);
assertEquals(value, result.get());
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
@Test
@@ -310,7 +306,7 @@ public abstract class AbstractJCacheAnnotationTests {
service.remove(keyItem);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -325,7 +321,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.removeWithException(keyItem, true));
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -340,8 +336,8 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatNullPointerException().isThrownBy(() ->
service.removeWithException(keyItem, false));
Cache.ValueWrapper wrapper = cache.get(key);
assertNotNull(wrapper);
assertEquals(value, wrapper.get());
assertThat(wrapper).isNotNull();
assertThat(wrapper.get()).isEqualTo(value);
}
@Test
@@ -355,7 +351,7 @@ public abstract class AbstractJCacheAnnotationTests {
service.earlyRemove(keyItem);
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -369,7 +365,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.earlyRemoveWithException(keyItem, true));
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -384,7 +380,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatNullPointerException().isThrownBy(() ->
service.earlyRemoveWithException(keyItem, false));
// This will be remove anyway as the earlyRemove has removed the cache before
assertNull(cache.get(key));
assertThat(cache.get(key)).isNull();
}
@Test
@@ -396,7 +392,7 @@ public abstract class AbstractJCacheAnnotationTests {
service.removeAll();
assertTrue(isEmpty(cache));
assertThat(isEmpty(cache)).isTrue();
}
@Test
@@ -409,7 +405,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.removeAllWithException(true));
assertTrue(isEmpty(cache));
assertThat(isEmpty(cache)).isTrue();
}
@Test
@@ -421,7 +417,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatNullPointerException().isThrownBy(() ->
service.removeAllWithException(false));
assertNotNull(cache.get(key));
assertThat(cache.get(key)).isNotNull();
}
@Test
@@ -433,7 +429,7 @@ public abstract class AbstractJCacheAnnotationTests {
service.earlyRemoveAll();
assertTrue(isEmpty(cache));
assertThat(isEmpty(cache)).isTrue();
}
@Test
@@ -445,7 +441,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.earlyRemoveAllWithException(true));
assertTrue(isEmpty(cache));
assertThat(isEmpty(cache)).isTrue();
}
@Test
@@ -458,7 +454,7 @@ public abstract class AbstractJCacheAnnotationTests {
assertThatNullPointerException().isThrownBy(() ->
service.earlyRemoveAllWithException(false));
// This will be remove anyway as the earlyRemove has removed the cache before
assertTrue(isEmpty(cache));
assertThat(isEmpty(cache)).isTrue();
}
protected boolean isEmpty(Cache cache) {
@@ -473,7 +469,7 @@ public abstract class AbstractJCacheAnnotationTests {
private Cache getCache(String name) {
Cache cache = cacheManager.getCache(name);
assertNotNull("required cache " + name + " does not exist", cache);
assertThat(cache).as("required cache " + name + " does not exist").isNotNull();
return cache;
}

View File

@@ -38,8 +38,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.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* @author Stephane Nicoll
@@ -71,15 +71,16 @@ public class JCacheCustomInterceptorTests {
@Test
public void onlyOneInterceptorIsAvailable() {
Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
assertEquals("Only one interceptor should be defined", 1, interceptors.size());
assertThat(interceptors.size()).as("Only one interceptor should be defined").isEqualTo(1);
JCacheInterceptor interceptor = interceptors.values().iterator().next();
assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
assertThat(interceptor.getClass()).as("Custom interceptor not defined").isEqualTo(TestCacheInterceptor.class);
}
@Test
public void customInterceptorAppliesWithRuntimeException() {
Object o = cs.cacheWithException("id", true);
assertEquals(55L, o); // See TestCacheInterceptor
// See TestCacheInterceptor
assertThat(o).isEqualTo(55L);
}
@Test

View File

@@ -44,11 +44,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.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll
@@ -67,13 +64,11 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
new AnnotationConfigApplicationContext(FullCachingConfig.class);
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
assertSame(context.getBean("cacheResolver", CacheResolver.class),
cos.getCacheResolver());
assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
cos.getExceptionCacheResolver());
assertThat(cos.getKeyGenerator()).isSameAs(context.getBean(KeyGenerator.class));
assertThat(cos.getCacheResolver()).isSameAs(context.getBean("cacheResolver", CacheResolver.class));
assertThat(cos.getExceptionCacheResolver()).isSameAs(context.getBean("exceptionCacheResolver", CacheResolver.class));
JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
assertThat(interceptor.getErrorHandler()).isSameAs(context.getBean("errorHandler", CacheErrorHandler.class));
context.close();
}
@@ -83,11 +78,10 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertNotNull(cos.getCacheResolver());
assertEquals(SimpleCacheResolver.class, cos.getCacheResolver().getClass());
assertSame(context.getBean(CacheManager.class),
((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager());
assertNull(cos.getExceptionCacheResolver());
assertThat(cos.getCacheResolver()).isNotNull();
assertThat(cos.getCacheResolver().getClass()).isEqualTo(SimpleCacheResolver.class);
assertThat(((SimpleCacheResolver) cos.getCacheResolver()).getCacheManager()).isSameAs(context.getBean(CacheManager.class));
assertThat(cos.getExceptionCacheResolver()).isNull();
context.close();
}
@@ -97,9 +91,9 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
new AnnotationConfigApplicationContext(FullCachingConfigSupport.class);
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
assertSame(context.getBean("keyGenerator"), cos.getKeyGenerator());
assertSame(context.getBean("exceptionCacheResolver"), cos.getExceptionCacheResolver());
assertThat(cos.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
assertThat(cos.getKeyGenerator()).isSameAs(context.getBean("keyGenerator"));
assertThat(cos.getExceptionCacheResolver()).isSameAs(context.getBean("exceptionCacheResolver"));
context.close();
}
@@ -110,7 +104,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
try {
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
assertThat(cos.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
JCacheableService<?> service = context.getBean(JCacheableService.class);
service.cache("id");

View File

@@ -25,7 +25,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -44,14 +44,14 @@ public class JCacheNamespaceDrivenTests extends AbstractJCacheAnnotationTests {
"/org/springframework/cache/jcache/config/jCacheNamespaceDriven-resolver.xml");
DefaultJCacheOperationSource ci = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
context.close();
}
@Test
public void testCacheErrorHandler() {
JCacheInterceptor ci = ctx.getBean(JCacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
assertThat(ci.getErrorHandler()).isSameAs(ctx.getBean("errorHandler", CacheErrorHandler.class));
}
}

View File

@@ -28,8 +28,7 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -44,20 +43,18 @@ public abstract class AbstractCacheOperationTests<O extends JCacheOperation<?>>
@Test
public void simple() {
O operation = createSimpleOperation();
assertEquals("Wrong cache name", "simpleCache", operation.getCacheName());
assertEquals("Unexpected number of annotation on " + operation.getMethod(),
1, operation.getAnnotations().size());
assertEquals("Wrong method annotation", operation.getCacheAnnotation(),
operation.getAnnotations().iterator().next());
assertThat(operation.getCacheName()).as("Wrong cache name").isEqualTo("simpleCache");
assertThat(operation.getAnnotations().size()).as("Unexpected number of annotation on " + operation.getMethod()).isEqualTo(1);
assertThat(operation.getAnnotations().iterator().next()).as("Wrong method annotation").isEqualTo(operation.getCacheAnnotation());
assertNotNull("cache resolver should be set", operation.getCacheResolver());
assertThat(operation.getCacheResolver()).as("cache resolver should be set").isNotNull();
}
protected void assertCacheInvocationParameter(CacheInvocationParameter actual, Class<?> targetType,
Object value, int position) {
assertEquals("wrong parameter type for " + actual, targetType, actual.getRawType());
assertEquals("wrong parameter value for " + actual, value, actual.getValue());
assertEquals("wrong parameter position for " + actual, position, actual.getParameterPosition());
assertThat(actual.getRawType()).as("wrong parameter type for " + actual).isEqualTo(targetType);
assertThat(actual.getValue()).as("wrong parameter value for " + actual).isEqualTo(value);
assertThat(actual.getParameterPosition()).as("wrong parameter position for " + actual).isEqualTo(position);
}
protected <A extends Annotation> CacheMethodDetails<A> create(Class<A> annotationType,

View File

@@ -37,11 +37,8 @@ import org.springframework.cache.jcache.support.TestableCacheResolverFactory;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -68,15 +65,15 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
public void cache() {
CacheResultOperation op = getDefaultCacheOperation(CacheResultOperation.class, String.class);
assertDefaults(op);
assertNull("Exception caching not enabled so resolver should not be set", op.getExceptionCacheResolver());
assertThat(op.getExceptionCacheResolver()).as("Exception caching not enabled so resolver should not be set").isNull();
}
@Test
public void cacheWithException() {
CacheResultOperation op = getDefaultCacheOperation(CacheResultOperation.class, String.class, boolean.class);
assertDefaults(op);
assertEquals(defaultExceptionCacheResolver, op.getExceptionCacheResolver());
assertEquals("exception", op.getExceptionCacheName());
assertThat(op.getExceptionCacheResolver()).isEqualTo(defaultExceptionCacheResolver);
assertThat(op.getExceptionCacheName()).isEqualTo("exception");
}
@Test
@@ -94,12 +91,12 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
@Test
public void removeAll() {
CacheRemoveAllOperation op = getDefaultCacheOperation(CacheRemoveAllOperation.class);
assertEquals(defaultCacheResolver, op.getCacheResolver());
assertThat(op.getCacheResolver()).isEqualTo(defaultCacheResolver);
}
@Test
public void noAnnotation() {
assertNull(getCacheOperation(AnnotatedJCacheableService.class, name.getMethodName()));
assertThat(getCacheOperation(AnnotatedJCacheableService.class, name.getMethodName())).isNull();
}
@Test
@@ -111,7 +108,7 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
@Test
public void defaultCacheNameWithCandidate() {
Method method = ReflectionUtils.findMethod(Object.class, "toString");
assertEquals("foo", source.determineCacheName(method, null, "foo"));
assertThat(source.determineCacheName(method, null, "foo")).isEqualTo("foo");
}
@Test
@@ -119,20 +116,19 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
Method method = ReflectionUtils.findMethod(Object.class, "toString");
CacheDefaults mock = mock(CacheDefaults.class);
given(mock.cacheName()).willReturn("");
assertEquals("java.lang.Object.toString()", source.determineCacheName(method, mock, ""));
assertThat(source.determineCacheName(method, mock, "")).isEqualTo("java.lang.Object.toString()");
}
@Test
public void defaultCacheNameNoDefaults() {
Method method = ReflectionUtils.findMethod(Object.class, "toString");
assertEquals("java.lang.Object.toString()", source.determineCacheName(method, null, ""));
assertThat(source.determineCacheName(method, null, "")).isEqualTo("java.lang.Object.toString()");
}
@Test
public void defaultCacheNameWithParameters() {
Method method = ReflectionUtils.findMethod(Comparator.class, "compare", Object.class, Object.class);
assertEquals("java.util.Comparator.compare(java.lang.Object,java.lang.Object)",
source.determineCacheName(method, null, ""));
assertThat(source.determineCacheName(method, null, "")).isEqualTo("java.util.Comparator.compare(java.lang.Object,java.lang.Object)");
}
@Test
@@ -141,16 +137,16 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
assertJCacheResolver(operation.getExceptionCacheResolver(), null);
assertEquals(KeyGeneratorAdapter.class, operation.getKeyGenerator().getClass());
assertEquals(defaultKeyGenerator, ((KeyGeneratorAdapter) operation.getKeyGenerator()).getTarget());
assertThat(operation.getKeyGenerator().getClass()).isEqualTo(KeyGeneratorAdapter.class);
assertThat(((KeyGeneratorAdapter) operation.getKeyGenerator()).getTarget()).isEqualTo(defaultKeyGenerator);
}
@Test
public void customKeyGenerator() {
CacheResultOperation operation =
getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
assertEquals(defaultCacheResolver, operation.getCacheResolver());
assertNull(operation.getExceptionCacheResolver());
assertThat(operation.getCacheResolver()).isEqualTo(defaultCacheResolver);
assertThat(operation.getExceptionCacheResolver()).isNull();
assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
@@ -160,10 +156,11 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
beanFactory.registerSingleton("fooBar", bean);
CacheResultOperation operation =
getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
assertEquals(defaultCacheResolver, operation.getCacheResolver());
assertNull(operation.getExceptionCacheResolver());
assertThat(operation.getCacheResolver()).isEqualTo(defaultCacheResolver);
assertThat(operation.getExceptionCacheResolver()).isNull();
KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) operation.getKeyGenerator();
assertSame(bean, adapter.getTarget()); // take bean from context
// take bean from context
assertThat(adapter.getTarget()).isSameAs(bean);
}
@Test
@@ -185,9 +182,9 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
}
private void assertDefaults(AbstractJCacheKeyOperation<?> operation) {
assertEquals(defaultCacheResolver, operation.getCacheResolver());
assertEquals(KeyGeneratorAdapter.class, operation.getKeyGenerator().getClass());
assertEquals(defaultKeyGenerator, ((KeyGeneratorAdapter) operation.getKeyGenerator()).getTarget());
assertThat(operation.getCacheResolver()).isEqualTo(defaultCacheResolver);
assertThat(operation.getKeyGenerator().getClass()).isEqualTo(KeyGeneratorAdapter.class);
assertThat(((KeyGeneratorAdapter) operation.getKeyGenerator()).getTarget()).isEqualTo(defaultKeyGenerator);
}
protected <T extends JCacheOperation<?>> T getDefaultCacheOperation(Class<T> operationType, Class<?>... parameterTypes) {
@@ -198,8 +195,8 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
Class<T> operationType, Class<?> targetType, String methodName, Class<?>... parameterTypes) {
JCacheOperation<?> result = getCacheOperation(targetType, methodName, parameterTypes);
assertNotNull(result);
assertEquals(operationType, result.getClass());
assertThat(result).isNotNull();
assertThat(result.getClass()).isEqualTo(operationType);
return operationType.cast(result);
}
@@ -213,20 +210,20 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
Class<? extends javax.cache.annotation.CacheResolver> expectedTargetType) {
if (expectedTargetType == null) {
assertNull(actual);
assertThat(actual).isNull();
}
else {
assertEquals("Wrong cache resolver implementation", CacheResolverAdapter.class, actual.getClass());
assertThat(actual.getClass()).as("Wrong cache resolver implementation").isEqualTo(CacheResolverAdapter.class);
CacheResolverAdapter adapter = (CacheResolverAdapter) actual;
assertEquals("Wrong target JCache implementation", expectedTargetType, adapter.getTarget().getClass());
assertThat(adapter.getTarget().getClass()).as("Wrong target JCache implementation").isEqualTo(expectedTargetType);
}
}
private void assertCacheKeyGenerator(KeyGenerator actual,
Class<? extends CacheKeyGenerator> expectedTargetType) {
assertEquals("Wrong cache resolver implementation", KeyGeneratorAdapter.class, actual.getClass());
assertThat(actual.getClass()).as("Wrong cache resolver implementation").isEqualTo(KeyGeneratorAdapter.class);
KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) actual;
assertEquals("Wrong target CacheKeyGenerator implementation", expectedTargetType, adapter.getTarget().getClass());
assertThat(adapter.getTarget().getClass()).as("Wrong target CacheKeyGenerator implementation").isEqualTo(expectedTargetType);
}

View File

@@ -23,12 +23,9 @@ import javax.cache.annotation.CachePut;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -47,12 +44,12 @@ public class CachePutOperationTests extends AbstractCacheOperationTests<CachePut
CachePutOperation operation = createSimpleOperation();
CacheInvocationParameter[] allParameters = operation.getAllParameters(2L, sampleInstance);
assertEquals(2, allParameters.length);
assertThat(allParameters.length).isEqualTo(2);
assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0);
assertCacheInvocationParameter(allParameters[1], SampleObject.class, sampleInstance, 1);
CacheInvocationParameter valueParameter = operation.getValueParameter(2L, sampleInstance);
assertNotNull(valueParameter);
assertThat(valueParameter).isNotNull();
assertCacheInvocationParameter(valueParameter, SampleObject.class, sampleInstance, 1);
}
@@ -87,10 +84,10 @@ public class CachePutOperationTests extends AbstractCacheOperationTests<CachePut
CacheMethodDetails<CachePut> methodDetails = create(CachePut.class,
SampleObject.class, "fullPutConfig", Long.class, SampleObject.class);
CachePutOperation operation = createDefaultOperation(methodDetails);
assertTrue(operation.isEarlyPut());
assertNotNull(operation.getExceptionTypeFilter());
assertTrue(operation.getExceptionTypeFilter().match(IOException.class));
assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class));
assertThat(operation.isEarlyPut()).isTrue();
assertThat(operation.getExceptionTypeFilter()).isNotNull();
assertThat(operation.getExceptionTypeFilter().match(IOException.class)).isTrue();
assertThat(operation.getExceptionTypeFilter().match(NullPointerException.class)).isFalse();
}
private CachePutOperation createDefaultOperation(CacheMethodDetails<CachePut> methodDetails) {

View File

@@ -22,7 +22,7 @@ import javax.cache.annotation.CacheRemoveAll;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -42,7 +42,7 @@ public class CacheRemoveAllOperationTests extends AbstractCacheOperationTests<Ca
CacheRemoveAllOperation operation = createSimpleOperation();
CacheInvocationParameter[] allParameters = operation.getAllParameters();
assertEquals(0, allParameters.length);
assertThat(allParameters.length).isEqualTo(0);
}
}

View File

@@ -22,7 +22,7 @@ import javax.cache.annotation.CacheRemove;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -42,7 +42,7 @@ public class CacheRemoveOperationTests extends AbstractCacheOperationTests<Cache
CacheRemoveOperation operation = createSimpleOperation();
CacheInvocationParameter[] allParameters = operation.getAllParameters(2L);
assertEquals(1, allParameters.length);
assertThat(allParameters.length).isEqualTo(1);
assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0);
}

View File

@@ -29,9 +29,8 @@ import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.jcache.AbstractJCacheTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -45,9 +44,9 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests {
DefaultCacheInvocationContext<?> dummyContext = createDummyContext();
CacheResolverAdapter adapter = new CacheResolverAdapter(getCacheResolver(dummyContext, "testCache"));
Collection<? extends Cache> caches = adapter.resolveCaches(dummyContext);
assertNotNull(caches);
assertEquals(1, caches.size());
assertEquals("testCache", caches.iterator().next().getName());
assertThat(caches).isNotNull();
assertThat(caches.size()).isEqualTo(1);
assertThat(caches.iterator().next().getName()).isEqualTo("testCache");
}
@Test

View File

@@ -28,12 +28,8 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author Stephane Nicoll
@@ -53,18 +49,18 @@ public class CacheResultOperationTests extends AbstractCacheOperationTests<Cache
public void simpleGet() {
CacheResultOperation operation = createSimpleOperation();
assertNotNull(operation.getKeyGenerator());
assertNotNull(operation.getExceptionCacheResolver());
assertThat(operation.getKeyGenerator()).isNotNull();
assertThat(operation.getExceptionCacheResolver()).isNotNull();
assertNull(operation.getExceptionCacheName());
assertEquals(defaultExceptionCacheResolver, operation.getExceptionCacheResolver());
assertThat(operation.getExceptionCacheName()).isNull();
assertThat(operation.getExceptionCacheResolver()).isEqualTo(defaultExceptionCacheResolver);
CacheInvocationParameter[] allParameters = operation.getAllParameters(2L);
assertEquals(1, allParameters.length);
assertThat(allParameters.length).isEqualTo(1);
assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0);
CacheInvocationParameter[] keyParameters = operation.getKeyParameters(2L);
assertEquals(1, keyParameters.length);
assertThat(keyParameters.length).isEqualTo(1);
assertCacheInvocationParameter(keyParameters[0], Long.class, 2L, 0);
}
@@ -75,7 +71,7 @@ public class CacheResultOperationTests extends AbstractCacheOperationTests<Cache
CacheResultOperation operation = createDefaultOperation(methodDetails);
CacheInvocationParameter[] keyParameters = operation.getKeyParameters(3L, Boolean.TRUE, "Foo");
assertEquals(2, keyParameters.length);
assertThat(keyParameters.length).isEqualTo(2);
assertCacheInvocationParameter(keyParameters[0], Long.class, 3L, 0);
assertCacheInvocationParameter(keyParameters[1], String.class, "Foo", 2);
}
@@ -110,12 +106,12 @@ public class CacheResultOperationTests extends AbstractCacheOperationTests<Cache
CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo");
Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations();
assertEquals(1, firstParameterAnnotations.size());
assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType());
assertThat(firstParameterAnnotations.size()).isEqualTo(1);
assertThat(firstParameterAnnotations.iterator().next().annotationType()).isEqualTo(CacheKey.class);
Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations();
assertEquals(1, secondParameterAnnotations.size());
assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType());
assertThat(secondParameterAnnotations.size()).isEqualTo(1);
assertThat(secondParameterAnnotations.iterator().next().annotationType()).isEqualTo(Value.class);
}
@Test
@@ -123,10 +119,10 @@ public class CacheResultOperationTests extends AbstractCacheOperationTests<Cache
CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class,
SampleObject.class, "fullGetConfig", Long.class);
CacheResultOperation operation = createDefaultOperation(methodDetails);
assertTrue(operation.isAlwaysInvoked());
assertNotNull(operation.getExceptionTypeFilter());
assertTrue(operation.getExceptionTypeFilter().match(IOException.class));
assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class));
assertThat(operation.isAlwaysInvoked()).isTrue();
assertThat(operation.getExceptionTypeFilter()).isNotNull();
assertThat(operation.getExceptionTypeFilter().match(IOException.class)).isTrue();
assertThat(operation.getExceptionTypeFilter().match(NullPointerException.class)).isFalse();
}
private CacheResultOperation createDefaultOperation(CacheMethodDetails<CacheResult> methodDetails) {

View File

@@ -39,7 +39,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
@@ -102,7 +102,7 @@ public class JCacheErrorHandlerTests {
this.simpleService.getFail(0L);
}
catch (IllegalStateException ex) {
assertEquals("Test exception", ex.getMessage());
assertThat(ex.getMessage()).isEqualTo("Test exception");
}
verify(this.errorHandler).handleCachePutError(
exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION);

View File

@@ -29,9 +29,8 @@ import org.springframework.cache.interceptor.NamedCacheResolver;
import org.springframework.cache.jcache.AbstractJCacheTests;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Stephane Nicoll
@@ -88,9 +87,9 @@ public class JCacheInterceptorTests extends AbstractJCacheTests {
CacheOperationInvoker invoker = new DummyInvoker(0L);
Object execute = interceptor.execute(invoker, service, method, new Object[] {"myId"});
assertNotNull("result cannot be null.", execute);
assertEquals("Wrong result type", Long.class, execute.getClass());
assertEquals("Wrong result", 0L, execute);
assertThat(execute).as("result cannot be null.").isNotNull();
assertThat(execute.getClass()).as("Wrong result type").isEqualTo(Long.class);
assertThat(execute).as("Wrong result").isEqualTo(0L);
}
protected JCacheOperationSource createOperationSource(CacheManager cacheManager,

View File

@@ -38,9 +38,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -67,10 +65,10 @@ public class JCacheKeyGeneratorTests {
this.keyGenerator.expect(1L);
Object first = this.simpleService.get(1L);
Object second = this.simpleService.get(1L);
assertSame(first, second);
assertThat(second).isSameAs(first);
Object key = new SimpleKey(1L);
assertEquals(first, cache.get(key).get());
assertThat(cache.get(key).get()).isEqualTo(first);
}
@Test
@@ -78,10 +76,10 @@ public class JCacheKeyGeneratorTests {
this.keyGenerator.expect(1L, "foo", "bar");
Object first = this.simpleService.get(1L, "foo", "bar");
Object second = this.simpleService.get(1L, "foo", "bar");
assertSame(first, second);
assertThat(second).isSameAs(first);
Object key = new SimpleKey(1L, "foo", "bar");
assertEquals(first, cache.get(key).get());
assertThat(cache.get(key).get()).isEqualTo(first);
}
@Test
@@ -89,10 +87,10 @@ public class JCacheKeyGeneratorTests {
this.keyGenerator.expect(1L);
Object first = this.simpleService.getFiltered(1L, "foo", "bar");
Object second = this.simpleService.getFiltered(1L, "foo", "bar");
assertSame(first, second);
assertThat(second).isSameAs(first);
Object key = new SimpleKey(1L);
assertEquals(first, cache.get(key).get());
assertThat(cache.get(key).get()).isEqualTo(first);
}
@@ -151,9 +149,8 @@ public class JCacheKeyGeneratorTests {
@Override
public Object generate(Object target, Method method, Object... params) {
assertTrue("Unexpected parameters: expected: "
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params),
Arrays.equals(expectedParams, params));
assertThat(Arrays.equals(expectedParams, params)).as("Unexpected parameters: expected: "
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
return new SimpleKey(params);
}
}

View File

@@ -24,8 +24,6 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Shared tests for {@link CacheManager} that inherit from
@@ -76,10 +74,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
T cacheManager = getCacheManager(false);
String cacheName = name.getMethodName();
addNativeCache(cacheName);
assertFalse(cacheManager.getCacheNames().contains(cacheName));
assertThat(cacheManager.getCacheNames().contains(cacheName)).isFalse();
try {
assertThat(cacheManager.getCache(cacheName)).isInstanceOf(getCacheType());
assertTrue(cacheManager.getCacheNames().contains(cacheName));
assertThat(cacheManager.getCacheNames().contains(cacheName)).isTrue();
}
finally {
removeNativeCache(cacheName);
@@ -90,7 +88,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
public void getOnUnknownCache() {
T cacheManager = getCacheManager(false);
String cacheName = name.getMethodName();
assertFalse(cacheManager.getCacheNames().contains(cacheName));
assertThat(cacheManager.getCacheNames().contains(cacheName)).isFalse();
assertThat(cacheManager.getCache(cacheName)).isNull();
}
@@ -104,12 +102,12 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
public void getTransactionalOnNewCache() {
String cacheName = name.getMethodName();
T cacheManager = getCacheManager(true);
assertFalse(cacheManager.getCacheNames().contains(cacheName));
assertThat(cacheManager.getCacheNames().contains(cacheName)).isFalse();
addNativeCache(cacheName);
try {
assertThat(cacheManager.getCache(cacheName))
.isInstanceOf(TransactionAwareCacheDecorator.class);
assertTrue(cacheManager.getCacheNames().contains(cacheName));
assertThat(cacheManager.getCacheNames().contains(cacheName)).isTrue();
}
finally {
removeNativeCache(cacheName);

View File

@@ -26,10 +26,8 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll
@@ -48,23 +46,23 @@ public class TransactionAwareCacheDecoratorTests {
public void getTargetCache() {
Cache target = new ConcurrentMapCache("testCache");
TransactionAwareCacheDecorator cache = new TransactionAwareCacheDecorator(target);
assertSame(target, cache.getTargetCache());
assertThat(cache.getTargetCache()).isSameAs(target);
}
@Test
public void regularOperationsOnTarget() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
assertEquals(target.getName(), cache.getName());
assertEquals(target.getNativeCache(), cache.getNativeCache());
assertThat(cache.getName()).isEqualTo(target.getName());
assertThat(cache.getNativeCache()).isEqualTo(target.getNativeCache());
Object key = new Object();
target.put(key, "123");
assertEquals("123", cache.get(key).get());
assertEquals("123", cache.get(key, String.class));
assertThat(cache.get(key).get()).isEqualTo("123");
assertThat(cache.get(key, String.class)).isEqualTo("123");
cache.clear();
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
}
@Test
@@ -74,7 +72,7 @@ public class TransactionAwareCacheDecoratorTests {
Object key = new Object();
cache.put(key, "123");
assertEquals("123", target.get(key, String.class));
assertThat(target.get(key, String.class)).isEqualTo("123");
}
@Test
@@ -87,10 +85,10 @@ public class TransactionAwareCacheDecoratorTests {
Object key = new Object();
cache.put(key, "123");
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
this.txManager.commit(status);
assertEquals("123", target.get(key, String.class));
assertThat(target.get(key, String.class)).isEqualTo("123");
}
@Test
@@ -99,10 +97,11 @@ public class TransactionAwareCacheDecoratorTests {
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
assertNull(cache.putIfAbsent(key, "123"));
assertEquals("123", target.get(key, String.class));
assertEquals("123", cache.putIfAbsent(key, "456").get());
assertEquals("123", target.get(key, String.class)); // unchanged
assertThat(cache.putIfAbsent(key, "123")).isNull();
assertThat(target.get(key, String.class)).isEqualTo("123");
assertThat(cache.putIfAbsent(key, "456").get()).isEqualTo("123");
// unchanged
assertThat(target.get(key, String.class)).isEqualTo("123");
}
@Test
@@ -113,7 +112,7 @@ public class TransactionAwareCacheDecoratorTests {
cache.put(key, "123");
cache.evict(key);
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
}
@Test
@@ -127,10 +126,10 @@ public class TransactionAwareCacheDecoratorTests {
TransactionStatus status = this.txManager.getTransaction(
new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
cache.evict(key);
assertEquals("123", target.get(key, String.class));
assertThat(target.get(key, String.class)).isEqualTo("123");
this.txManager.commit(status);
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
}
@Test
@@ -141,7 +140,7 @@ public class TransactionAwareCacheDecoratorTests {
cache.put(key, "123");
cache.clear();
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
}
@Test
@@ -155,9 +154,9 @@ public class TransactionAwareCacheDecoratorTests {
TransactionStatus status = this.txManager.getTransaction(
new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
cache.clear();
assertEquals("123", target.get(key, String.class));
assertThat(target.get(key, String.class)).isEqualTo("123");
this.txManager.commit(status);
assertNull(target.get(key));
assertThat(target.get(key)).isNull();
}
}

View File

@@ -22,9 +22,8 @@ import java.util.List;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Dmitriy Kopylenko
@@ -42,8 +41,8 @@ public class SimpleMailMessageTests {
message.setTo("you@mail.org");
SimpleMailMessage messageCopy = new SimpleMailMessage(message);
assertEquals("me@mail.org", messageCopy.getFrom());
assertEquals("you@mail.org", messageCopy.getTo()[0]);
assertThat(messageCopy.getFrom()).isEqualTo("me@mail.org");
assertThat(messageCopy.getTo()[0]).isEqualTo("you@mail.org");
message.setReplyTo("reply@mail.org");
message.setCc(new String[]{"he@mail.org", "she@mail.org"});
@@ -53,32 +52,32 @@ public class SimpleMailMessageTests {
message.setSubject("my subject");
message.setText("my text");
assertEquals("me@mail.org", message.getFrom());
assertEquals("reply@mail.org", message.getReplyTo());
assertEquals("you@mail.org", message.getTo()[0]);
assertThat(message.getFrom()).isEqualTo("me@mail.org");
assertThat(message.getReplyTo()).isEqualTo("reply@mail.org");
assertThat(message.getTo()[0]).isEqualTo("you@mail.org");
List<String> ccs = Arrays.asList(message.getCc());
assertTrue(ccs.contains("he@mail.org"));
assertTrue(ccs.contains("she@mail.org"));
assertThat(ccs.contains("he@mail.org")).isTrue();
assertThat(ccs.contains("she@mail.org")).isTrue();
List<String> bccs = Arrays.asList(message.getBcc());
assertTrue(bccs.contains("us@mail.org"));
assertTrue(bccs.contains("them@mail.org"));
assertEquals(sentDate, message.getSentDate());
assertEquals("my subject", message.getSubject());
assertEquals("my text", message.getText());
assertThat(bccs.contains("us@mail.org")).isTrue();
assertThat(bccs.contains("them@mail.org")).isTrue();
assertThat(message.getSentDate()).isEqualTo(sentDate);
assertThat(message.getSubject()).isEqualTo("my subject");
assertThat(message.getText()).isEqualTo("my text");
messageCopy = new SimpleMailMessage(message);
assertEquals("me@mail.org", messageCopy.getFrom());
assertEquals("reply@mail.org", messageCopy.getReplyTo());
assertEquals("you@mail.org", messageCopy.getTo()[0]);
assertThat(messageCopy.getFrom()).isEqualTo("me@mail.org");
assertThat(messageCopy.getReplyTo()).isEqualTo("reply@mail.org");
assertThat(messageCopy.getTo()[0]).isEqualTo("you@mail.org");
ccs = Arrays.asList(messageCopy.getCc());
assertTrue(ccs.contains("he@mail.org"));
assertTrue(ccs.contains("she@mail.org"));
assertThat(ccs.contains("he@mail.org")).isTrue();
assertThat(ccs.contains("she@mail.org")).isTrue();
bccs = Arrays.asList(message.getBcc());
assertTrue(bccs.contains("us@mail.org"));
assertTrue(bccs.contains("them@mail.org"));
assertEquals(sentDate, messageCopy.getSentDate());
assertEquals("my subject", messageCopy.getSubject());
assertEquals("my text", messageCopy.getText());
assertThat(bccs.contains("us@mail.org")).isTrue();
assertThat(bccs.contains("them@mail.org")).isTrue();
assertThat(messageCopy.getSentDate()).isEqualTo(sentDate);
assertThat(messageCopy.getSubject()).isEqualTo("my subject");
assertThat(messageCopy.getText()).isEqualTo("my text");
}
@Test
@@ -95,9 +94,9 @@ public class SimpleMailMessageTests {
original.getCc()[0] = "mmm@mmm.org";
original.getBcc()[0] = "mmm@mmm.org";
assertEquals("fiona@mail.org", copy.getTo()[0]);
assertEquals("he@mail.org", copy.getCc()[0]);
assertEquals("us@mail.org", copy.getBcc()[0]);
assertThat(copy.getTo()[0]).isEqualTo("fiona@mail.org");
assertThat(copy.getCc()[0]).isEqualTo("he@mail.org");
assertThat(copy.getBcc()[0]).isEqualTo("us@mail.org");
}
/**
@@ -118,8 +117,8 @@ public class SimpleMailMessageTests {
// Copy the message
SimpleMailMessage message2 = new SimpleMailMessage(message1);
assertEquals(message1, message2);
assertEquals(message1.hashCode(), message2.hashCode());
assertThat(message2).isEqualTo(message1);
assertThat(message2.hashCode()).isEqualTo(message1.hashCode());
}
public final void testEqualsObject() {
@@ -129,20 +128,22 @@ public class SimpleMailMessageTests {
// Same object is equal
message1 = new SimpleMailMessage();
message2 = message1;
assertTrue(message1.equals(message2));
assertThat(message1.equals(message2)).isTrue();
// Null object is not equal
message1 = new SimpleMailMessage();
message2 = null;
assertTrue(!(message1.equals(message2)));
boolean condition1 = !(message1.equals(message2));
assertThat(condition1).isTrue();
// Different class is not equal
assertTrue(!(message1.equals(new Object())));
boolean condition = !(message1.equals(new Object()));
assertThat(condition).isTrue();
// Equal values are equal
message1 = new SimpleMailMessage();
message2 = new SimpleMailMessage();
assertTrue(message1.equals(message2));
assertThat(message1.equals(message2)).isTrue();
message1 = new SimpleMailMessage();
message1.setFrom("from@somewhere");
@@ -154,7 +155,7 @@ public class SimpleMailMessageTests {
message1.setSubject("subject");
message1.setText("text");
message2 = new SimpleMailMessage(message1);
assertTrue(message1.equals(message2));
assertThat(message1.equals(message2)).isTrue();
}
@Test

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@@ -36,18 +36,18 @@ public class ConfigurableMimeFileTypeMapTests {
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
ftm.afterPropertiesSet();
assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType("foobar.HTM"));
assertEquals("Invalid content type for html", "text/html", ftm.getContentType("foobar.html"));
assertEquals("Invalid content type for c++", "text/plain", ftm.getContentType("foobar.c++"));
assertEquals("Invalid content type for svf", "image/vnd.svf", ftm.getContentType("foobar.svf"));
assertEquals("Invalid content type for dsf", "image/x-mgx-dsf", ftm.getContentType("foobar.dsf"));
assertEquals("Invalid default content type", "application/octet-stream", ftm.getContentType("foobar.foo"));
assertThat(ftm.getContentType("foobar.HTM")).as("Invalid content type for HTM").isEqualTo("text/html");
assertThat(ftm.getContentType("foobar.html")).as("Invalid content type for html").isEqualTo("text/html");
assertThat(ftm.getContentType("foobar.c++")).as("Invalid content type for c++").isEqualTo("text/plain");
assertThat(ftm.getContentType("foobar.svf")).as("Invalid content type for svf").isEqualTo("image/vnd.svf");
assertThat(ftm.getContentType("foobar.dsf")).as("Invalid content type for dsf").isEqualTo("image/x-mgx-dsf");
assertThat(ftm.getContentType("foobar.foo")).as("Invalid default content type").isEqualTo("application/octet-stream");
}
@Test
public void againstDefaultConfigurationWithFilePath() throws Exception {
ConfigurableMimeFileTypeMap ftm = new ConfigurableMimeFileTypeMap();
assertEquals("Invalid content type for HTM", "text/html", ftm.getContentType(new File("/tmp/foobar.HTM")));
assertThat(ftm.getContentType(new File("/tmp/foobar.HTM"))).as("Invalid content type for HTM").isEqualTo("text/html");
}
@Test
@@ -56,9 +56,9 @@ public class ConfigurableMimeFileTypeMapTests {
ftm.setMappings(new String[] {"foo/bar HTM foo", "foo/cpp c++"});
ftm.afterPropertiesSet();
assertEquals("Invalid content type for HTM - override didn't work", "foo/bar", ftm.getContentType("foobar.HTM"));
assertEquals("Invalid content type for c++ - override didn't work", "foo/cpp", ftm.getContentType("foobar.c++"));
assertEquals("Invalid content type for foo - new mapping didn't work", "foo/bar", ftm.getContentType("bar.foo"));
assertThat(ftm.getContentType("foobar.HTM")).as("Invalid content type for HTM - override didn't work").isEqualTo("foo/bar");
assertThat(ftm.getContentType("foobar.c++")).as("Invalid content type for c++ - override didn't work").isEqualTo("foo/cpp");
assertThat(ftm.getContentType("bar.foo")).as("Invalid content type for foo - new mapping didn't work").isEqualTo("foo/bar");
}
@Test
@@ -69,10 +69,10 @@ public class ConfigurableMimeFileTypeMapTests {
ftm.setMappingLocation(resource);
ftm.afterPropertiesSet();
assertEquals("Invalid content type for foo", "text/foo", ftm.getContentType("foobar.foo"));
assertEquals("Invalid content type for bar", "text/bar", ftm.getContentType("foobar.bar"));
assertEquals("Invalid content type for fimg", "image/foo", ftm.getContentType("foobar.fimg"));
assertEquals("Invalid content type for bimg", "image/bar", ftm.getContentType("foobar.bimg"));
assertThat(ftm.getContentType("foobar.foo")).as("Invalid content type for foo").isEqualTo("text/foo");
assertThat(ftm.getContentType("foobar.bar")).as("Invalid content type for bar").isEqualTo("text/bar");
assertThat(ftm.getContentType("foobar.fimg")).as("Invalid content type for fimg").isEqualTo("image/foo");
assertThat(ftm.getContentType("foobar.bimg")).as("Invalid content type for bimg").isEqualTo("image/bar");
}
}

View File

@@ -18,8 +18,8 @@ package org.springframework.mail.javamail;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
/**
* @author Brian Hanafee
@@ -37,37 +37,37 @@ public class InternetAddressEditorTests {
@Test
public void uninitialized() {
assertEquals("Uninitialized editor did not return empty value string", EMPTY, editor.getAsText());
assertThat(editor.getAsText()).as("Uninitialized editor did not return empty value string").isEqualTo(EMPTY);
}
@Test
public void setNull() {
editor.setAsText(null);
assertEquals("Setting null did not result in empty value string", EMPTY, editor.getAsText());
assertThat(editor.getAsText()).as("Setting null did not result in empty value string").isEqualTo(EMPTY);
}
@Test
public void setEmpty() {
editor.setAsText(EMPTY);
assertEquals("Setting empty string did not result in empty value string", EMPTY, editor.getAsText());
assertThat(editor.getAsText()).as("Setting empty string did not result in empty value string").isEqualTo(EMPTY);
}
@Test
public void allWhitespace() {
editor.setAsText(" ");
assertEquals("All whitespace was not recognized", EMPTY, editor.getAsText());
assertThat(editor.getAsText()).as("All whitespace was not recognized").isEqualTo(EMPTY);
}
@Test
public void simpleGoodAddress() {
editor.setAsText(SIMPLE);
assertEquals("Simple email address failed", SIMPLE, editor.getAsText());
assertThat(editor.getAsText()).as("Simple email address failed").isEqualTo(SIMPLE);
}
@Test
public void excessWhitespace() {
editor.setAsText(" " + SIMPLE + " ");
assertEquals("Whitespace was not stripped", SIMPLE, editor.getAsText());
assertThat(editor.getAsText()).as("Whitespace was not stripped").isEqualTo(SIMPLE);
}
@Test

View File

@@ -45,9 +45,6 @@ import org.springframework.util.ObjectUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author Juergen Hoeller
@@ -76,33 +73,33 @@ public class JavaMailSenderTests {
simpleMessage.setText("my text");
sender.send(simpleMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals(30, sender.transport.getConnectedPort());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedPort()).isEqualTo(30);
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertEquals(1, sender.transport.getSentMessages().size());
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
MimeMessage sentMessage = sender.transport.getSentMessage(0);
List<Address> froms = Arrays.asList(sentMessage.getFrom());
assertEquals(1, froms.size());
assertEquals("me@mail.org", ((InternetAddress) froms.get(0)).getAddress());
assertThat(froms.size()).isEqualTo(1);
assertThat(((InternetAddress) froms.get(0)).getAddress()).isEqualTo("me@mail.org");
List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo());
assertEquals("reply@mail.org", ((InternetAddress) replyTos.get(0)).getAddress());
assertThat(((InternetAddress) replyTos.get(0)).getAddress()).isEqualTo("reply@mail.org");
List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO));
assertEquals(1, tos.size());
assertEquals("you@mail.org", ((InternetAddress) tos.get(0)).getAddress());
assertThat(tos.size()).isEqualTo(1);
assertThat(((InternetAddress) tos.get(0)).getAddress()).isEqualTo("you@mail.org");
List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC));
assertEquals(2, ccs.size());
assertEquals("he@mail.org", ((InternetAddress) ccs.get(0)).getAddress());
assertEquals("she@mail.org", ((InternetAddress) ccs.get(1)).getAddress());
assertThat(ccs.size()).isEqualTo(2);
assertThat(((InternetAddress) ccs.get(0)).getAddress()).isEqualTo("he@mail.org");
assertThat(((InternetAddress) ccs.get(1)).getAddress()).isEqualTo("she@mail.org");
List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC));
assertEquals(2, bccs.size());
assertEquals("us@mail.org", ((InternetAddress) bccs.get(0)).getAddress());
assertEquals("them@mail.org", ((InternetAddress) bccs.get(1)).getAddress());
assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime());
assertEquals("my subject", sentMessage.getSubject());
assertEquals("my text", sentMessage.getContent());
assertThat(bccs.size()).isEqualTo(2);
assertThat(((InternetAddress) bccs.get(0)).getAddress()).isEqualTo("us@mail.org");
assertThat(((InternetAddress) bccs.get(1)).getAddress()).isEqualTo("them@mail.org");
assertThat(sentMessage.getSentDate().getTime()).isEqualTo(sentDate.getTime());
assertThat(sentMessage.getSubject()).isEqualTo("my subject");
assertThat(sentMessage.getContent()).isEqualTo("my text");
}
@Test
@@ -118,20 +115,20 @@ public class JavaMailSenderTests {
simpleMessage2.setTo("she@mail.org");
sender.send(simpleMessage1, simpleMessage2);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertEquals(2, sender.transport.getSentMessages().size());
assertThat(sender.transport.getSentMessages().size()).isEqualTo(2);
MimeMessage sentMessage1 = sender.transport.getSentMessage(0);
List<Address> tos1 = Arrays.asList(sentMessage1.getRecipients(Message.RecipientType.TO));
assertEquals(1, tos1.size());
assertEquals("he@mail.org", ((InternetAddress) tos1.get(0)).getAddress());
assertThat(tos1.size()).isEqualTo(1);
assertThat(((InternetAddress) tos1.get(0)).getAddress()).isEqualTo("he@mail.org");
MimeMessage sentMessage2 = sender.transport.getSentMessage(1);
List<Address> tos2 = Arrays.asList(sentMessage2.getRecipients(Message.RecipientType.TO));
assertEquals(1, tos2.size());
assertEquals("she@mail.org", ((InternetAddress) tos2.get(0)).getAddress());
assertThat(tos2.size()).isEqualTo(1);
assertThat(((InternetAddress) tos2.get(0)).getAddress()).isEqualTo("she@mail.org");
}
@Test
@@ -145,12 +142,12 @@ public class JavaMailSenderTests {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage, sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(mimeMessage);
}
@Test
@@ -166,13 +163,13 @@ public class JavaMailSenderTests {
mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
sender.send(mimeMessage1, mimeMessage2);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(2, sender.transport.getSentMessages().size());
assertEquals(mimeMessage1, sender.transport.getSentMessage(0));
assertEquals(mimeMessage2, sender.transport.getSentMessage(1));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(2);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(mimeMessage1);
assertThat(sender.transport.getSentMessage(1)).isEqualTo(mimeMessage2);
}
@Test
@@ -193,12 +190,12 @@ public class JavaMailSenderTests {
};
sender.send(preparator);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(messages.get(0), sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(messages.get(0));
}
@Test
@@ -226,13 +223,13 @@ public class JavaMailSenderTests {
};
sender.send(preparator1, preparator2);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(2, sender.transport.getSentMessages().size());
assertEquals(messages.get(0), sender.transport.getSentMessage(0));
assertEquals(messages.get(1), sender.transport.getSentMessage(1));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(2);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(messages.get(0));
assertThat(sender.transport.getSentMessage(1)).isEqualTo(messages.get(1));
}
@Test
@@ -243,18 +240,19 @@ public class JavaMailSenderTests {
sender.setPassword("password");
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
assertNull(message.getEncoding());
assertTrue(message.getFileTypeMap() instanceof ConfigurableMimeFileTypeMap);
assertThat(message.getEncoding()).isNull();
boolean condition = message.getFileTypeMap() instanceof ConfigurableMimeFileTypeMap;
assertThat(condition).isTrue();
message.setTo("you@mail.org");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(message.getMimeMessage());
}
@Test
@@ -265,20 +263,20 @@ public class JavaMailSenderTests {
sender.setPassword("password");
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), "UTF-8");
assertEquals("UTF-8", message.getEncoding());
assertThat(message.getEncoding()).isEqualTo("UTF-8");
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
message.setFileTypeMap(fileTypeMap);
assertEquals(fileTypeMap, message.getFileTypeMap());
assertThat(message.getFileTypeMap()).isEqualTo(fileTypeMap);
message.setTo("you@mail.org");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(message.getMimeMessage());
}
@Test
@@ -292,18 +290,18 @@ public class JavaMailSenderTests {
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
sender.setDefaultFileTypeMap(fileTypeMap);
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
assertEquals("UTF-8", message.getEncoding());
assertEquals(fileTypeMap, message.getFileTypeMap());
assertThat(message.getEncoding()).isEqualTo("UTF-8");
assertThat(message.getFileTypeMap()).isEqualTo(fileTypeMap);
message.setTo("you@mail.org");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(message.getMimeMessage());
}
@Test
@@ -316,7 +314,8 @@ public class JavaMailSenderTests {
}
catch (MailParseException ex) {
// expected
assertTrue(ex.getCause() instanceof AddressException);
boolean condition = ex.getCause() instanceof AddressException;
assertThat(condition).isTrue();
}
}
@@ -334,7 +333,8 @@ public class JavaMailSenderTests {
}
catch (MailParseException ex) {
// expected
assertTrue(ex.getCause() instanceof AddressException);
boolean condition = ex.getCause() instanceof AddressException;
assertThat(condition).isTrue();
}
}
@@ -344,7 +344,7 @@ public class JavaMailSenderTests {
MockJavaMailSender sender = new MockJavaMailSender() {
@Override
protected Transport getTransport(Session sess) throws NoSuchProviderException {
assertEquals(session, sess);
assertThat(sess).isEqualTo(session);
return super.getTransport(sess);
}
};
@@ -359,12 +359,12 @@ public class JavaMailSenderTests {
mimeMessage.setSentDate(new GregorianCalendar(2005, 3, 1).getTime());
sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage, sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(mimeMessage);
}
@Test
@@ -374,7 +374,7 @@ public class JavaMailSenderTests {
MockJavaMailSender sender = new MockJavaMailSender() {
@Override
protected Transport getTransport(Session sess) throws NoSuchProviderException {
assertEquals("bogusValue", sess.getProperty("bogusKey"));
assertThat(sess.getProperty("bogusKey")).isEqualTo("bogusValue");
return super.getTransport(sess);
}
};
@@ -387,12 +387,12 @@ public class JavaMailSenderTests {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage, sender.transport.getSentMessage(0));
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(mimeMessage);
}
@Test
@@ -437,17 +437,18 @@ public class JavaMailSenderTests {
}
catch (MailSendException ex) {
ex.printStackTrace();
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(new InternetAddress("she@mail.org"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
assertEquals(1, ex.getFailedMessages().size());
assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0).getAllRecipients()[0]).isEqualTo(new InternetAddress("she@mail.org"));
assertThat(ex.getFailedMessages().size()).isEqualTo(1);
assertThat(ex.getFailedMessages().keySet().iterator().next()).isEqualTo(simpleMessage1);
Object subEx = ex.getFailedMessages().values().iterator().next();
assertTrue(subEx instanceof MessagingException);
assertEquals("failed", ((MessagingException) subEx).getMessage());
boolean condition = subEx instanceof MessagingException;
assertThat(condition).isTrue();
assertThat(((MessagingException) subEx).getMessage()).isEqualTo("failed");
}
}
@@ -469,17 +470,18 @@ public class JavaMailSenderTests {
}
catch (MailSendException ex) {
ex.printStackTrace();
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
assertEquals(1, ex.getFailedMessages().size());
assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
assertThat(sender.transport.isCloseCalled()).isTrue();
assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
assertThat(sender.transport.getSentMessage(0)).isEqualTo(mimeMessage2);
assertThat(ex.getFailedMessages().size()).isEqualTo(1);
assertThat(ex.getFailedMessages().keySet().iterator().next()).isEqualTo(mimeMessage1);
Object subEx = ex.getFailedMessages().values().iterator().next();
assertTrue(subEx instanceof MessagingException);
assertEquals("failed", ((MessagingException) subEx).getMessage());
boolean condition = subEx instanceof MessagingException;
assertThat(condition).isTrue();
assertThat(((MessagingException) subEx).getMessage()).isEqualTo("failed");
}
}
@@ -585,7 +587,7 @@ public class JavaMailSenderTests {
throw new MessagingException("No sentDate specified");
}
if (message.getSubject() != null && message.getSubject().contains("custom")) {
assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate());
assertThat(message.getSentDate()).isEqualTo(new GregorianCalendar(2005, 3, 1).getTime());
}
this.sentMessages.add(message);
}

View File

@@ -21,7 +21,7 @@ import java.text.ParseException;
import org.junit.Test;
import org.quartz.CronTrigger;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -35,7 +35,7 @@ public class CronTriggerFactoryBeanTests {
factory.setCronExpression("0 15 10 ? * *");
factory.afterPropertiesSet();
CronTrigger trigger = factory.getObject();
assertEquals("0 15 10 ? * *", trigger.getCronExpression());
assertThat(trigger.getCronExpression()).isEqualTo("0 15 10 ? * *");
}
}

View File

@@ -22,8 +22,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StopWatch;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mark Fisher
@@ -35,26 +34,26 @@ public class QuartzSchedulerLifecycleTests {
public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() {
ConfigurableApplicationContext context =
new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder"));
assertThat(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder")).isNotNull();
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.close();
sw.stop();
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
assertThat(sw.getTotalTimeMillis() < 500).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isTrue();
}
@Test // SPR-6354
public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() {
ConfigurableApplicationContext context =
new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder"));
assertThat(context.getBean("lazyInitSchedulerWithCustomShutdownOrder")).isNotNull();
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.close();
sw.stop();
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
assertThat(sw.getTotalTimeMillis() < 500).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isTrue();
}
}

View File

@@ -41,12 +41,8 @@ import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -87,8 +83,8 @@ public class QuartzSupportTests {
schedulerFactoryBean.afterPropertiesSet();
schedulerFactoryBean.start();
Scheduler returnedScheduler = schedulerFactoryBean.getObject();
assertEquals(tb, returnedScheduler.getContext().get("testBean"));
assertEquals(ac, returnedScheduler.getContext().get("appCtx"));
assertThat(returnedScheduler.getContext().get("testBean")).isEqualTo(tb);
assertThat(returnedScheduler.getContext().get("appCtx")).isEqualTo(ac);
}
finally {
schedulerFactoryBean.destroy();
@@ -126,8 +122,8 @@ public class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
assertEquals(DummyJob.count, taskExecutor.count);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
assertThat(taskExecutor.count).isEqualTo(DummyJob.count);
bean.destroy();
}
@@ -168,8 +164,8 @@ public class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertEquals(10, DummyJobBean.param);
assertTrue(DummyJobBean.count > 0);
assertThat(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
bean.destroy();
}
@@ -204,8 +200,8 @@ public class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertEquals(10, DummyJob.param);
assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
assertThat(DummyJob.param).isEqualTo(10);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
bean.destroy();
}
@@ -241,8 +237,8 @@ public class QuartzSupportTests {
bean.afterPropertiesSet();
Thread.sleep(500);
assertEquals(0, DummyJob.param);
assertTrue(DummyJob.count == 0);
assertThat(DummyJob.param).isEqualTo(0);
assertThat(DummyJob.count == 0).isTrue();
bean.destroy();
}
@@ -275,8 +271,8 @@ public class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertEquals(10, DummyJobBean.param);
assertTrue(DummyJobBean.count > 0);
assertThat(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
bean.destroy();
}
@@ -294,8 +290,8 @@ public class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertEquals(10, DummyJob.param);
assertTrue("DummyJob should have been executed at least once.", DummyJob.count > 0);
assertThat(DummyJob.param).isEqualTo(10);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
bean.destroy();
}
@@ -306,9 +302,9 @@ public class QuartzSupportTests {
try {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
assertNotSame(scheduler1, scheduler2);
assertEquals("quartz1", scheduler1.getSchedulerName());
assertEquals("quartz2", scheduler2.getSchedulerName());
assertThat(scheduler2).isNotSameAs(scheduler1);
assertThat(scheduler1.getSchedulerName()).isEqualTo("quartz1");
assertThat(scheduler2.getSchedulerName()).isEqualTo("quartz2");
}
finally {
ctx.close();
@@ -321,9 +317,9 @@ public class QuartzSupportTests {
try {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
assertNotSame(scheduler1, scheduler2);
assertEquals("quartz1", scheduler1.getSchedulerName());
assertEquals("quartz2", scheduler2.getSchedulerName());
assertThat(scheduler2).isNotSameAs(scheduler1);
assertThat(scheduler1.getSchedulerName()).isEqualTo("quartz1");
assertThat(scheduler2.getSchedulerName()).isEqualTo("quartz2");
}
finally {
ctx.close();
@@ -339,10 +335,10 @@ public class QuartzSupportTests {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
assertEquals("doImport called exportService", 0, exportService.getImportCount());
assertEquals("doExport not called on exportService", 2, exportService.getExportCount());
assertEquals("doImport not called on importService", 2, importService.getImportCount());
assertEquals("doExport called on importService", 0, importService.getExportCount());
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
assertThat(importService.getExportCount()).as("doExport called on importService").isEqualTo(0);
}
finally {
ctx.close();
@@ -358,10 +354,10 @@ public class QuartzSupportTests {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
assertEquals("doImport called exportService", 0, exportService.getImportCount());
assertEquals("doExport not called on exportService", 2, exportService.getExportCount());
assertEquals("doImport not called on importService", 2, importService.getImportCount());
assertEquals("doExport called on importService", 0, importService.getExportCount());
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
assertThat(importService.getExportCount()).as("doExport called on importService").isEqualTo(0);
}
finally {
ctx.close();
@@ -374,9 +370,9 @@ public class QuartzSupportTests {
StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("scheduler", new RootBeanDefinition(SchedulerFactoryBean.class));
Scheduler bean = context.getBean("scheduler", Scheduler.class);
assertFalse(bean.isStarted());
assertThat(bean.isStarted()).isFalse();
context.refresh();
assertTrue(bean.isStarted());
assertThat(bean.isStarted()).isTrue();
}
@Test
@@ -387,15 +383,15 @@ public class QuartzSupportTests {
.addPropertyValue("autoStartup", false).getBeanDefinition();
context.registerBeanDefinition("scheduler", beanDefinition);
Scheduler bean = context.getBean("scheduler", Scheduler.class);
assertFalse(bean.isStarted());
assertThat(bean.isStarted()).isFalse();
context.refresh();
assertFalse(bean.isStarted());
assertThat(bean.isStarted()).isFalse();
}
@Test
public void schedulerRepositoryExposure() throws Exception {
ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml");
assertSame(SchedulerRepository.getInstance().lookup("myScheduler"), ctx.getBean("scheduler"));
assertThat(ctx.getBean("scheduler")).isSameAs(SchedulerRepository.getInstance().lookup("myScheduler"));
ctx.close();
}
@@ -412,7 +408,7 @@ public class QuartzSupportTests {
ClassPathXmlApplicationContext ctx = context("databasePersistence.xml");
JdbcTemplate jdbcTemplate = new JdbcTemplate(ctx.getBean(DataSource.class));
assertFalse("No triggers were persisted", jdbcTemplate.queryForList("SELECT * FROM qrtz_triggers").isEmpty());
assertThat(jdbcTemplate.queryForList("SELECT * FROM qrtz_triggers").isEmpty()).as("No triggers were persisted").isFalse();
/*
Thread.sleep(3000);

View File

@@ -21,7 +21,7 @@ import java.text.ParseException;
import org.junit.Test;
import org.quartz.SimpleTrigger;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -36,8 +36,8 @@ public class SimpleTriggerFactoryBeanTests {
factory.setRepeatInterval(1000L);
factory.afterPropertiesSet();
SimpleTrigger trigger = factory.getObject();
assertEquals(5, trigger.getRepeatCount());
assertEquals(1000L, trigger.getRepeatInterval());
assertThat(trigger.getRepeatCount()).isEqualTo(5);
assertThat(trigger.getRepeatInterval()).isEqualTo(1000L);
}
}

View File

@@ -31,7 +31,6 @@ import org.springframework.validation.beanvalidation.BeanValidationPostProcessor
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertNotNull;
/**
* @author Juergen Hoeller
@@ -127,7 +126,7 @@ public class BeanValidationPostProcessorTests {
@PostConstruct
public void init() {
assertNotNull("Shouldn't be here after constraint checking", this.testBean);
assertThat(this.testBean).as("Shouldn't be here after constraint checking").isNotNull();
}
}

View File

@@ -42,9 +42,8 @@ import org.springframework.validation.beanvalidation.CustomValidatorBean;
import org.springframework.validation.beanvalidation.MethodValidationInterceptor;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Juergen Hoeller
@@ -76,7 +75,7 @@ public class MethodValidationTests {
}
private void doTestProxyValidation(MyValidInterface<String> proxy) {
assertNotNull(proxy.myValidMethod("value", 5));
assertThat(proxy.myValidMethod("value", 5)).isNotNull();
assertThatExceptionOfType(ValidationException.class).isThrownBy(() ->
proxy.myValidMethod("value", 15));
assertThatExceptionOfType(ValidationException.class).isThrownBy(() ->
@@ -88,7 +87,7 @@ public class MethodValidationTests {
proxy.myValidAsyncMethod("value", 15));
assertThatExceptionOfType(ValidationException.class).isThrownBy(() ->
proxy.myValidAsyncMethod(null, 5));
assertEquals("myValue", proxy.myGenericMethod("myValue"));
assertThat(proxy.myGenericMethod("myValue")).isEqualTo("myValue");
assertThatExceptionOfType(ValidationException.class).isThrownBy(() ->
proxy.myGenericMethod(null));
}

View File

@@ -58,10 +58,6 @@ import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Kazuki Shimizu
@@ -88,7 +84,7 @@ public class SpringValidatorAdapterTests {
@Test
public void testUnwrap() {
Validator nativeValidator = validatorAdapter.unwrap(Validator.class);
assertSame(this.nativeValidator, nativeValidator);
assertThat(nativeValidator).isSameAs(this.nativeValidator);
}
@Test // SPR-13406
@@ -103,9 +99,9 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("pass");
FieldError error = errors.getFieldError("password");
assertNotNull(error);
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Size of Password is must be between 8 and 128");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
}
@@ -121,9 +117,9 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("password");
FieldError error = errors.getFieldError("password");
assertNotNull(error);
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Password must be same value as Password(Confirm)");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
}
@@ -141,13 +137,13 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("confirmEmail")).isEqualTo(1);
FieldError error1 = errors.getFieldError("email");
FieldError error2 = errors.getFieldError("confirmEmail");
assertNotNull(error1);
assertNotNull(error2);
assertThat(error1).isNotNull();
assertThat(error2).isNotNull();
assertThat(messageSource.getMessage(error1, Locale.ENGLISH)).isEqualTo("email must be same value as confirmEmail");
assertThat(messageSource.getMessage(error2, Locale.ENGLISH)).isEqualTo("Email required");
assertTrue(error1.contains(ConstraintViolation.class));
assertThat(error1.contains(ConstraintViolation.class)).isTrue();
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
assertTrue(error2.contains(ConstraintViolation.class));
assertThat(error2.contains(ConstraintViolation.class)).isTrue();
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("confirmEmail");
}
@@ -167,13 +163,13 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("confirmEmail")).isEqualTo(1);
FieldError error1 = errors.getFieldError("email");
FieldError error2 = errors.getFieldError("confirmEmail");
assertNotNull(error1);
assertNotNull(error2);
assertThat(error1).isNotNull();
assertThat(error2).isNotNull();
assertThat(messageSource.getMessage(error1, Locale.ENGLISH)).isEqualTo("email must be same value as confirmEmail");
assertThat(messageSource.getMessage(error2, Locale.ENGLISH)).isEqualTo("Email required");
assertTrue(error1.contains(ConstraintViolation.class));
assertThat(error1.contains(ConstraintViolation.class)).isTrue();
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
assertTrue(error2.contains(ConstraintViolation.class));
assertThat(error2.contains(ConstraintViolation.class)).isTrue();
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("confirmEmail");
}
@@ -189,9 +185,9 @@ public class SpringValidatorAdapterTests {
assertThat(errors.getFieldErrorCount("email")).isEqualTo(1);
assertThat(errors.getFieldValue("email")).isEqualTo("X");
FieldError error = errors.getFieldError("email");
assertNotNull(error);
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).contains("[\\w.'-]{1,}@[\\w.'-]{1,}");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
}
@@ -204,7 +200,7 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(parent, "parent");
validatorAdapter.validate(parent, errors);
assertTrue(errors.getErrorCount() > 0);
assertThat(errors.getErrorCount() > 0).isTrue();
}
@Test // SPR-16177
@@ -216,7 +212,7 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(parent, "parent");
validatorAdapter.validate(parent, errors);
assertTrue(errors.getErrorCount() > 0);
assertThat(errors.getErrorCount() > 0).isTrue();
}
private List<Child> createChildren(Parent parent) {
@@ -242,7 +238,7 @@ public class SpringValidatorAdapterTests {
validatorAdapter.validate(bean, errors);
assertThat(errors.getFieldErrorCount("property[4]")).isEqualTo(1);
assertNull(errors.getFieldValue("property[4]"));
assertThat(errors.getFieldValue("property[4]")).isNull();
}
@Test // SPR-15839
@@ -257,7 +253,7 @@ public class SpringValidatorAdapterTests {
validatorAdapter.validate(bean, errors);
assertThat(errors.getFieldErrorCount("property[no value can be]")).isEqualTo(1);
assertNull(errors.getFieldValue("property[no value can be]"));
assertThat(errors.getFieldValue("property[no value can be]")).isNull();
}
@Test // SPR-15839
@@ -271,8 +267,8 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(bean, "bean");
validatorAdapter.validate(bean, errors);
assertTrue(errors.hasFieldErrors("property[]"));
assertNull(errors.getFieldValue("property[]"));
assertThat(errors.hasFieldErrors("property[]")).isTrue();
assertThat(errors.getFieldValue("property[]")).isNull();
}

View File

@@ -53,10 +53,6 @@ import org.springframework.validation.ObjectError;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author Juergen Hoeller
@@ -72,7 +68,7 @@ public class ValidatorFactoryTests {
ValidPerson person = new ValidPerson();
Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
assertEquals(2, result.size());
assertThat(result.size()).isEqualTo(2);
for (ConstraintViolation<ValidPerson> cv : result) {
String path = cv.getPropertyPath().toString();
assertThat(path).matches(actual -> "name".equals(actual) || "address.street".equals(actual));
@@ -80,9 +76,9 @@ public class ValidatorFactoryTests {
}
Validator nativeValidator = validator.unwrap(Validator.class);
assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);
assertThat(nativeValidator.getClass().getName().startsWith("org.hibernate")).isTrue();
assertThat(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory).isTrue();
assertThat(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory).isTrue();
validator.destroy();
}
@@ -96,7 +92,7 @@ public class ValidatorFactoryTests {
ValidPerson person = new ValidPerson();
Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
assertEquals(2, result.size());
assertThat(result.size()).isEqualTo(2);
for (ConstraintViolation<ValidPerson> cv : result) {
String path = cv.getPropertyPath().toString();
assertThat(path).matches(actual -> "name".equals(actual) || "address.street".equals(actual));
@@ -104,9 +100,9 @@ public class ValidatorFactoryTests {
}
Validator nativeValidator = validator.unwrap(Validator.class);
assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);
assertThat(nativeValidator.getClass().getName().startsWith("org.hibernate")).isTrue();
assertThat(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory).isTrue();
assertThat(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory).isTrue();
validator.destroy();
}
@@ -120,11 +116,11 @@ public class ValidatorFactoryTests {
person.setName("Juergen");
person.getAddress().setStreet("Juergen's Street");
Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
assertEquals(1, result.size());
assertThat(result.size()).isEqualTo(1);
Iterator<ConstraintViolation<ValidPerson>> iterator = result.iterator();
ConstraintViolation<?> cv = iterator.next();
assertEquals("", cv.getPropertyPath().toString());
assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NameAddressValid);
assertThat(cv.getPropertyPath().toString()).isEqualTo("");
assertThat(cv.getConstraintDescriptor().getAnnotation() instanceof NameAddressValid).isTrue();
}
@Test
@@ -137,7 +133,7 @@ public class ValidatorFactoryTests {
person.getAddress().setStreet("Phil's Street");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(person, "person");
validator.validate(person, errors);
assertEquals(1, errors.getErrorCount());
assertThat(errors.getErrorCount()).isEqualTo(1);
assertThat(errors.getFieldError("address").getRejectedValue()).isInstanceOf(ValidAddress.class);
}
@@ -149,24 +145,24 @@ public class ValidatorFactoryTests {
ValidPerson person = new ValidPerson();
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertEquals(2, result.getErrorCount());
assertThat(result.getErrorCount()).isEqualTo(2);
FieldError fieldError = result.getFieldError("name");
assertEquals("name", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("name");
List<String> errorCodes = Arrays.asList(fieldError.getCodes());
assertEquals(4, errorCodes.size());
assertTrue(errorCodes.contains("NotNull.person.name"));
assertTrue(errorCodes.contains("NotNull.name"));
assertTrue(errorCodes.contains("NotNull.java.lang.String"));
assertTrue(errorCodes.contains("NotNull"));
assertThat(errorCodes.size()).isEqualTo(4);
assertThat(errorCodes.contains("NotNull.person.name")).isTrue();
assertThat(errorCodes.contains("NotNull.name")).isTrue();
assertThat(errorCodes.contains("NotNull.java.lang.String")).isTrue();
assertThat(errorCodes.contains("NotNull")).isTrue();
fieldError = result.getFieldError("address.street");
assertEquals("address.street", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("address.street");
errorCodes = Arrays.asList(fieldError.getCodes());
assertEquals(5, errorCodes.size());
assertTrue(errorCodes.contains("NotNull.person.address.street"));
assertTrue(errorCodes.contains("NotNull.address.street"));
assertTrue(errorCodes.contains("NotNull.street"));
assertTrue(errorCodes.contains("NotNull.java.lang.String"));
assertTrue(errorCodes.contains("NotNull"));
assertThat(errorCodes.size()).isEqualTo(5);
assertThat(errorCodes.contains("NotNull.person.address.street")).isTrue();
assertThat(errorCodes.contains("NotNull.address.street")).isTrue();
assertThat(errorCodes.contains("NotNull.street")).isTrue();
assertThat(errorCodes.contains("NotNull.java.lang.String")).isTrue();
assertThat(errorCodes.contains("NotNull")).isTrue();
}
@Test
@@ -179,12 +175,12 @@ public class ValidatorFactoryTests {
person.getAddress().setStreet("Juergen's Street");
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertEquals(1, result.getErrorCount());
assertThat(result.getErrorCount()).isEqualTo(1);
ObjectError globalError = result.getGlobalError();
List<String> errorCodes = Arrays.asList(globalError.getCodes());
assertEquals(2, errorCodes.size());
assertTrue(errorCodes.contains("NameAddressValid.person"));
assertTrue(errorCodes.contains("NameAddressValid"));
assertThat(errorCodes.size()).isEqualTo(2);
assertThat(errorCodes.contains("NameAddressValid.person")).isTrue();
assertThat(errorCodes.contains("NameAddressValid")).isTrue();
}
@Test
@@ -199,12 +195,12 @@ public class ValidatorFactoryTests {
person.getAddress().setStreet("Juergen's Street");
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertEquals(1, result.getErrorCount());
assertThat(result.getErrorCount()).isEqualTo(1);
ObjectError globalError = result.getGlobalError();
List<String> errorCodes = Arrays.asList(globalError.getCodes());
assertEquals(2, errorCodes.size());
assertTrue(errorCodes.contains("NameAddressValid.person"));
assertTrue(errorCodes.contains("NameAddressValid"));
assertThat(errorCodes.size()).isEqualTo(2);
assertThat(errorCodes.contains("NameAddressValid.person")).isTrue();
assertThat(errorCodes.contains("NameAddressValid")).isTrue();
ctx.close();
}
@@ -217,13 +213,13 @@ public class ValidatorFactoryTests {
person.getAddressList().add(new ValidAddress());
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertEquals(3, result.getErrorCount());
assertThat(result.getErrorCount()).isEqualTo(3);
FieldError fieldError = result.getFieldError("name");
assertEquals("name", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("name");
fieldError = result.getFieldError("address.street");
assertEquals("address.street", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("address.street");
fieldError = result.getFieldError("addressList[0].street");
assertEquals("addressList[0].street", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("addressList[0].street");
}
@Test
@@ -235,13 +231,13 @@ public class ValidatorFactoryTests {
person.getAddressSet().add(new ValidAddress());
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertEquals(3, result.getErrorCount());
assertThat(result.getErrorCount()).isEqualTo(3);
FieldError fieldError = result.getFieldError("name");
assertEquals("name", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("name");
fieldError = result.getFieldError("address.street");
assertEquals("address.street", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("address.street");
fieldError = result.getFieldError("addressSet[].street");
assertEquals("addressSet[].street", fieldError.getField());
assertThat(fieldError.getField()).isEqualTo("addressSet[].street");
}
@Test
@@ -253,7 +249,7 @@ public class ValidatorFactoryTests {
Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
validator.validate(mainBean, errors);
Object rejected = errors.getFieldValue("inner.value");
assertNull(rejected);
assertThat(rejected).isNull();
}
@Test
@@ -265,7 +261,7 @@ public class ValidatorFactoryTests {
Errors errors = new BeanPropertyBindingResult(mainBean, "mainBean");
validator.validate(mainBean, errors);
Object rejected = errors.getFieldValue("inner.value");
assertNull(rejected);
assertThat(rejected).isNull();
}
@Test
@@ -282,9 +278,9 @@ public class ValidatorFactoryTests {
validator.validate(listContainer, errors);
FieldError fieldError = errors.getFieldError("list[1]");
assertNotNull(fieldError);
assertEquals("X", fieldError.getRejectedValue());
assertEquals("X", errors.getFieldValue("list[1]"));
assertThat(fieldError).isNotNull();
assertThat(fieldError.getRejectedValue()).isEqualTo("X");
assertThat(errors.getFieldValue("list[1]")).isEqualTo("X");
}
@@ -379,7 +375,7 @@ public class ValidatorFactoryTests {
@Override
public boolean isValid(ValidPerson value, ConstraintValidatorContext context) {
if (value.expectsAutowiredValidator) {
assertNotNull(this.environment);
assertThat(this.environment).isNotNull();
}
boolean valid = (value.name == null || !value.address.street.contains(value.name));
if (!valid && "Phil".equals(value.name)) {