Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
@@ -63,11 +63,11 @@ public class GemfireCqInboundChannelAdapterParserTests {
@Test
public void testPhase() {
assertEquals(2, adapter.getPhase());
assertThat(adapter.getPhase()).isEqualTo(2);
}
@Test
public void testAutoStartup() {
assertEquals(false, adapter.isAutoStartup());
assertThat(adapter.isAutoStartup()).isEqualTo(false);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
@@ -56,12 +56,12 @@ public class GemfireInboundChannelAdapterParserTests {
@Test
public void testPhase() {
assertEquals(2, adapter1.getPhase());
assertThat(adapter1.getPhase()).isEqualTo(2);
}
@Test
public void testAutoStart() {
assertEquals(false, adapter1.isAutoStartup());
assertThat(adapter1.isAutoStartup()).isEqualTo(false);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
@@ -74,17 +73,17 @@ public class GemfireOutboundChannelAdapterParserTests {
adapter1.start();
MessageChannel channel = ctx.getBean("input", MessageChannel.class);
channel.send(new GenericMessage<String>("foo"));
assertTrue(adviceCalled.await(10, TimeUnit.SECONDS));
assertThat(adviceCalled.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
public void testPhase() {
assertEquals(2, adapter1.getPhase());
assertThat(adapter1.getPhase()).isEqualTo(2);
}
@Test
public void testAutoStart() {
assertEquals(false, adapter1.isAutoStartup());
assertThat(adapter1.isAutoStartup()).isEqualTo(false);
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.integration.gemfire.inbound;
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;
import static org.mockito.Mockito.mock;
import org.apache.geode.cache.Region;
@@ -80,11 +78,11 @@ public class CacheListeningMessageProducerTests {
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.put("x", "abc");
Message<?> message = channel.receive(0);
assertNotNull(message);
assertEquals("x=abc", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("x=abc");
producer.stop();
}
@@ -99,15 +97,15 @@ public class CacheListeningMessageProducerTests {
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.put("x", "abc");
Message<?> message1 = channel.receive(0);
assertNotNull(message1);
assertEquals("abc", message1.getPayload());
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("abc");
region.put("x", "xyz");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("xyz", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("xyz");
producer.stop();
}
@@ -123,13 +121,13 @@ public class CacheListeningMessageProducerTests {
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.put("foo", "abc");
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.destroy("foo");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("abc", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("abc");
producer.stop();
}
@@ -145,13 +143,13 @@ public class CacheListeningMessageProducerTests {
producer.afterPropertiesSet();
producer.start();
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.put("foo", "abc");
assertNull(channel.receive(0));
assertThat(channel.receive(0)).isNull();
region.invalidate("foo");
Message<?> message2 = channel.receive(0);
assertNotNull(message2);
assertEquals("foo was abc", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("foo was abc");
producer.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.inbound;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.apache.geode.cache.Operation;
@@ -66,8 +66,8 @@ public class ContinuousQueryMessageProducerTests {
cqMessageProducer.onEvent(cqEvent);
assertEquals(1, handler.count);
assertEquals(cqEvent, handler.payload);
assertThat(handler.count).isEqualTo(1);
assertThat(handler.payload).isEqualTo(cqEvent);
}
@Test
@@ -76,7 +76,7 @@ public class ContinuousQueryMessageProducerTests {
cqMessageProducer.onEvent(cqEvent);
assertEquals(0, handler.count);
assertThat(handler.count).isEqualTo(0);
}
@Test
@@ -87,8 +87,8 @@ public class ContinuousQueryMessageProducerTests {
cqMessageProducer.setSupportedEventTypes(CqEventType.DESTROYED);
cqMessageProducer.onEvent(cqEvent);
assertEquals(1, handler.count);
assertEquals(cqEvent, handler.payload);
assertThat(handler.count).isEqualTo(1);
assertThat(handler.payload).isEqualTo(cqEvent);
}
@Test
@@ -98,8 +98,8 @@ public class ContinuousQueryMessageProducerTests {
cqMessageProducer.afterPropertiesSet();
cqMessageProducer.onEvent(cqEvent);
assertEquals(1, handler.count);
assertEquals("HELLO, WORLD", handler.payload);
assertThat(handler.count).isEqualTo(1);
assertThat(handler.payload).isEqualTo("HELLO, WORLD");
}
CqEvent event(final Operation operation, final Object value) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.integration.gemfire.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.OutputStream;
@@ -75,19 +73,19 @@ public class CqInboundChannelAdapterTests {
@Test
public void testCqEvent() throws InterruptedException {
assertTrue(TestUtils.getPropertyValue(withDurable, "durable", Boolean.class));
assertThat(TestUtils.getPropertyValue(withDurable, "durable", Boolean.class)).isTrue();
region.put("one", 1);
Message<?> msg = outputChannel1.receive(10000);
assertNotNull(msg);
assertTrue(msg.getPayload() instanceof CqEvent);
assertThat(msg).isNotNull();
assertThat(msg.getPayload() instanceof CqEvent).isTrue();
}
@Test
public void testPayloadExpression() throws InterruptedException {
region.put("one", 1);
Message<?> msg = outputChannel2.receive(10000);
assertNotNull(msg);
assertEquals(1, msg.getPayload());
assertThat(msg).isNotNull();
assertThat(msg.getPayload()).isEqualTo(1);
}
@AfterClass

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.gemfire.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.geode.cache.EntryEvent;
import org.apache.geode.internal.cache.LocalRegion;
@@ -72,7 +71,7 @@ public class GemfireInboundChannelAdapterTests {
region1.put("payload", "payload");
assertEquals("payload", eventHandler1.event);
assertThat(eventHandler1.event).isEqualTo("payload");
}
@Test
@@ -82,9 +81,9 @@ public class GemfireInboundChannelAdapterTests {
region2.put("payload", "payload");
assertTrue(eventHandler2.event instanceof EntryEvent);
assertThat(eventHandler2.event instanceof EntryEvent).isTrue();
EntryEvent<?, ?> event = (EntryEvent<?, ?>) eventHandler2.event;
assertEquals("payload", event.getNewValue());
assertThat(event.getNewValue()).isEqualTo("payload");
}
@Test
@@ -97,7 +96,7 @@ public class GemfireInboundChannelAdapterTests {
region3.put("payload", "payload");
assertEquals(1, errorHandler.count);
assertThat(errorHandler.count).isEqualTo(1);
}
static class ErrorHandler implements MessageHandler {
@@ -106,7 +105,7 @@ public class GemfireInboundChannelAdapterTests {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
assertTrue(message instanceof ErrorMessage);
assertThat(message).isInstanceOf(ErrorMessage.class);
count++;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.metadata;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -96,8 +96,8 @@ public class GemfireMetadataStoreCacheListenerTests {
metadataStore.put(testKey, testValue);
latch.await(10, TimeUnit.SECONDS);
assertEquals(testKey, actualKey.get());
assertEquals(testValue, actualValue.get());
assertThat(actualKey.get()).isEqualTo(testKey);
assertThat(actualValue.get()).isEqualTo(testValue);
}
@Test
@@ -123,8 +123,8 @@ public class GemfireMetadataStoreCacheListenerTests {
metadataStore.remove(testKey);
latch.await(10, TimeUnit.SECONDS);
assertEquals(testKey, actualKey.get());
assertEquals(testValue, actualValue.get());
assertThat(actualKey.get()).isEqualTo(testKey);
assertThat(actualValue.get()).isEqualTo(testValue);
}
@Test
@@ -151,8 +151,8 @@ public class GemfireMetadataStoreCacheListenerTests {
metadataStore.put(testKey, testNewValue);
latch.await(10, TimeUnit.SECONDS);
assertEquals(testKey, actualKey.get());
assertEquals(testNewValue, actualValue.get());
assertThat(actualKey.get()).isEqualTo(testKey);
assertThat(actualValue.get()).isEqualTo(testNewValue);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,8 @@
package org.springframework.integration.gemfire.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
@@ -31,7 +30,6 @@ import org.junit.Test;
import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.integration.metadata.ConcurrentMetadataStore;
import org.springframework.util.Assert;
/**
* @author Artem Bilan
@@ -60,7 +58,7 @@ public class GemfireMetadataStoreTests {
}
if (cache != null) {
cache.close();
Assert.isTrue(cache.isClosed(), "Cache did not close after close() call");
assertThat(cache.isClosed()).as("Cache did not close after close() call").isTrue();
}
}
@@ -75,7 +73,7 @@ public class GemfireMetadataStoreTests {
@Test
public void testGetNonExistingKeyValue() {
String retrievedValue = metadataStore.get("does-not-exist");
assertNull(retrievedValue);
assertThat(retrievedValue).isNull();
}
@Test
@@ -84,7 +82,8 @@ public class GemfireMetadataStoreTests {
GemfireTemplate gemfireTemplate = new GemfireTemplate(region);
assertEquals("Integration", gemfireTemplate.get("GemfireMetadataStoreTests-Spring"));
Object v = gemfireTemplate.get("GemfireMetadataStoreTests-Spring");
assertThat(v).isEqualTo("Integration");
}
@Test
@@ -92,7 +91,7 @@ public class GemfireMetadataStoreTests {
metadataStore.put("GemfireMetadataStoreTests-GetValue", "Hello Gemfire");
String retrievedValue = metadataStore.get("GemfireMetadataStoreTests-GetValue");
assertEquals("Hello Gemfire", retrievedValue);
assertThat(retrievedValue).isEqualTo("Hello Gemfire");
}
@Test
@@ -100,7 +99,7 @@ public class GemfireMetadataStoreTests {
metadataStore.put("GemfireMetadataStoreTests-PersistEmpty", "");
String retrievedValue = metadataStore.get("GemfireMetadataStoreTests-PersistEmpty");
assertEquals("", retrievedValue);
assertThat(retrievedValue).isEqualTo("");
}
@Test
@@ -110,7 +109,7 @@ public class GemfireMetadataStoreTests {
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
assertEquals("'value' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'value' must not be null.");
}
}
@@ -119,7 +118,7 @@ public class GemfireMetadataStoreTests {
metadataStore.put("", "PersistWithEmptyKey");
String retrievedValue = metadataStore.get("");
assertEquals("PersistWithEmptyKey", retrievedValue);
assertThat(retrievedValue).isEqualTo("PersistWithEmptyKey");
}
@Test
@@ -130,7 +129,7 @@ public class GemfireMetadataStoreTests {
}
catch (IllegalArgumentException e) {
assertEquals("'key' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
}
}
@@ -140,7 +139,7 @@ public class GemfireMetadataStoreTests {
metadataStore.get(null);
}
catch (IllegalArgumentException e) {
assertEquals("'key' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
return;
}
@@ -154,8 +153,8 @@ public class GemfireMetadataStoreTests {
metadataStore.put(testKey, testValue);
assertEquals(testValue, metadataStore.remove(testKey));
assertNull(metadataStore.remove(testKey));
assertThat(metadataStore.remove(testKey)).isEqualTo(testValue);
assertThat(metadataStore.remove(testKey)).isNull();
}
@Test
@@ -164,7 +163,8 @@ public class GemfireMetadataStoreTests {
GemfireTemplate gemfireTemplate = new GemfireTemplate(region);
assertEquals("Integration", gemfireTemplate.get("GemfireMetadataStoreTests-Spring"));
Object v = gemfireTemplate.get("GemfireMetadataStoreTests-Spring");
assertThat(v).isEqualTo("Integration");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.outbound;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Collections;
@@ -82,7 +82,7 @@ public class CacheWritingMessageHandlerTests {
@Test
public void mapPayloadWritesToCache() throws Exception {
assertEquals(0, region.size());
assertThat(region.size()).isEqualTo(0);
CacheWritingMessageHandler handler = new CacheWritingMessageHandler(region);
handler.setBeanFactory(mock(BeanFactory.class));
@@ -92,13 +92,13 @@ public class CacheWritingMessageHandlerTests {
map.put("foo", "bar");
Message<?> message = MessageBuilder.withPayload(map).build();
handler.handleMessage(message);
assertEquals(1, region.size());
assertEquals("bar", region.get("foo"));
assertThat(region.size()).isEqualTo(1);
assertThat(region.get("foo")).isEqualTo("bar");
}
@Test
public void ExpressionsWriteToCache() throws Exception {
assertEquals(0, region.size());
assertThat(region.size()).isEqualTo(0);
CacheWritingMessageHandler handler = new CacheWritingMessageHandler(region);
@@ -113,16 +113,16 @@ public class CacheWritingMessageHandlerTests {
.copyHeaders(Collections.singletonMap("bar", "bar"))
.build();
handler.handleMessage(message);
assertEquals(2, region.size());
assertEquals("BAR", region.get("FOO"));
assertEquals("bar", region.get("foo"));
assertThat(region.size()).isEqualTo(2);
assertThat(region.get("FOO")).isEqualTo("BAR");
assertThat(region.get("foo")).isEqualTo("bar");
handler.setCacheEntryExpressions(Collections.<Expression, Expression>singletonMap(new LiteralExpression("baz"),
new ValueExpression<Long>(10L)));
handler.handleMessage(new GenericMessage<String>("test"));
assertEquals(3, region.size());
assertEquals(10L, region.get("baz"));
assertThat(region.size()).isEqualTo(3);
assertThat(region.get("baz")).isEqualTo(10L);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.gemfire.outbound;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -74,17 +74,17 @@ public class GemfireOutboundChannelAdapterTests {
Message<?> message = MessageBuilder.withPayload(map).build();
cacheChannel1.send(message);
assertEquals(1, region1.size());
assertEquals("bar", region1.get("foo"));
assertThat(region1.size()).isEqualTo(1);
assertThat(region1.get("foo")).isEqualTo("bar");
}
@Test
public void testWriteExpressions() {
Message<?> message = MessageBuilder.withPayload("Hello").build();
cacheChannel2.send(message);
assertEquals(2, region2.size());
assertEquals("hello", region2.get("HELLO"));
assertEquals("bar", region2.get("foo"));
assertThat(region2.size()).isEqualTo(2);
assertThat(region2.get("HELLO")).isEqualTo("hello");
assertThat(region2.get("foo")).isEqualTo("bar");
}
@Test //INT-2275
@@ -94,8 +94,8 @@ public class GemfireOutboundChannelAdapterTests {
Message<?> message = MessageBuilder.withPayload(map).build();
cacheChainChannel.send(message);
assertEquals(1, region1.size());
assertEquals("bar", region1.get("foo"));
assertThat(region1.size()).isEqualTo(1);
assertThat(region1.get("foo")).isEqualTo("bar");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,8 @@
package org.springframework.integration.gemfire.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.concurrent.TimeUnit;
@@ -108,42 +105,43 @@ public class DelayerHandlerRescheduleIntegrationTests {
fail("IllegalStateException expected");
}
catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
assertTrue(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"));
assertThat(e instanceof IllegalStateException).isTrue();
assertThat(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"))
.isTrue();
}
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(delayerMessageGroupId, messageStore.iterator().next().getGroupId());
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
assertEquals(2, messageStore.getMessageCountForAllMessageGroups());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
assertThat(messageStore.iterator().next().getGroupId()).isEqualTo(delayerMessageGroupId);
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(2);
assertThat(messageStore.getMessageCountForAllMessageGroups()).isEqualTo(2);
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
Message<?> messageInStore = messageGroup.getMessages().iterator().next();
Object payload = messageInStore.getPayload();
// INT-3049
assertTrue(payload instanceof DelayHandler.DelayedMessageWrapper);
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal());
assertThat(payload instanceof DelayHandler.DelayedMessageWrapper).isTrue();
assertThat(((DelayHandler.DelayedMessageWrapper) payload).getOriginal()).isEqualTo(message1);
context.refresh();
PollableChannel output = context.getBean("output", PollableChannel.class);
Message<?> message = output.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload1 = message.getPayload();
message = output.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload2 = message.getPayload();
assertNotSame(payload1, payload2);
assertThat(payload2).isNotSameAs(payload1);
assertEquals(1, messageStore.getMessageGroupCount());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
int n = 0;
while (n++ < 200 && messageStore.messageGroupSize(delayerMessageGroupId) > 0) {
Thread.sleep(100);
}
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(0);
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2017 the original author or authors.
* Copyright 2007-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@
package org.springframework.integration.gemfire.store;
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.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Iterator;
@@ -70,9 +66,9 @@ public class GemfireGroupStoreTests {
public void testNonExistingEmptyMessageGroup() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
MessageGroup messageGroup = store.getMessageGroup(1);
assertNotNull(messageGroup);
assertTrue(messageGroup instanceof SimpleMessageGroup);
assertEquals(0, messageGroup.size());
assertThat(messageGroup).isNotNull();
assertThat(messageGroup instanceof SimpleMessageGroup).isTrue();
assertThat(messageGroup.size()).isEqualTo(0);
}
@Test
@@ -81,13 +77,13 @@ public class GemfireGroupStoreTests {
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
messageGroup = store.addMessageToGroup(1, message);
assertEquals(1, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(1);
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
messageGroup = store.getMessageGroup(1);
assertEquals(1, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(1);
}
@Test
@@ -98,28 +94,28 @@ public class GemfireGroupStoreTests {
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<String>("1"));
messageGroup = store.getMessageGroup(1);
assertEquals(1, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(1);
Thread.sleep(1); //since it adds to a local region some times CREATED_DATE ends up to be the same
// Unrealistic in a real scenario
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
messageGroup = store.getMessageGroup(1);
assertEquals(2, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(2);
Thread.sleep(1);
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<String>("3"));
messageGroup = store.getMessageGroup(1);
assertEquals(3, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(3);
store.removeMessagesFromGroup(messageGroup.getGroupId(), message);
messageGroup = store.getMessageGroup(1);
assertEquals(2, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(2);
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
messageGroup = store.getMessageGroup(1);
assertEquals(2, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(2);
}
@@ -129,21 +125,21 @@ public class GemfireGroupStoreTests {
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
assertEquals(1, messageGroup.size());
assertThat(messageGroup.size()).isEqualTo(1);
store.removeMessageGroup(1);
MessageGroup messageGroupA = store.getMessageGroup(1);
assertNotSame(messageGroup, messageGroupA);
assertEquals(0, messageGroupA.getMessages().size());
assertEquals(0, messageGroupA.size());
assertThat(messageGroupA).isNotSameAs(messageGroup);
assertThat(messageGroupA.getMessages().size()).isEqualTo(0);
assertThat(messageGroupA.size()).isEqualTo(0);
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
messageGroup = store.getMessageGroup(1);
assertEquals(0, messageGroup.getMessages().size());
assertEquals(0, messageGroup.size());
assertThat(messageGroup.getMessages().size()).isEqualTo(0);
assertThat(messageGroup.size()).isEqualTo(0);
}
@Test
@@ -168,7 +164,7 @@ public class GemfireGroupStoreTests {
store.addMessagesToGroup(messageGroup.getGroupId(), messageToMark);
store.completeGroup(messageGroup.getGroupId());
messageGroup = store.getMessageGroup(1);
assertTrue(messageGroup.isComplete());
assertThat(messageGroup.isComplete()).isTrue();
}
@Test
@@ -179,7 +175,7 @@ public class GemfireGroupStoreTests {
store.addMessagesToGroup(messageGroup.getGroupId(), messageToMark);
store.setLastReleasedSequenceNumberForGroup(messageGroup.getGroupId(), 5);
messageGroup = store.getMessageGroup(1);
assertEquals(5, messageGroup.getLastReleasedMessageSequenceNumber());
assertThat(messageGroup.getLastReleasedMessageSequenceNumber()).isEqualTo(5);
}
@Test
@@ -192,14 +188,14 @@ public class GemfireGroupStoreTests {
store1.addMessagesToGroup(1, message);
MessageGroup messageGroup = store2.addMessageToGroup(1, new GenericMessage<String>("2"));
assertEquals(2, messageGroup.getMessages().size());
assertThat(messageGroup.getMessages().size()).isEqualTo(2);
GemfireMessageStore store3 = new GemfireMessageStore(region);
store3.removeMessagesFromGroup(1, message);
messageGroup = store3.getMessageGroup(1);
assertEquals(1, messageGroup.getMessages().size());
assertThat(messageGroup.getMessages().size()).isEqualTo(1);
}
@Test
@@ -221,11 +217,11 @@ public class GemfireGroupStoreTests {
message = store.getMessageGroup(1).getMessages().iterator().next();
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
assertThat(messageHistory).isNotNull();
assertThat(messageHistory.size()).isEqualTo(2);
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
}
@Test
@@ -243,7 +239,7 @@ public class GemfireGroupStoreTests {
messageGroups.next();
counter++;
}
assertEquals(3, counter);
assertThat(counter).isEqualTo(3);
store2.removeMessageGroup(3);
@@ -253,7 +249,7 @@ public class GemfireGroupStoreTests {
messageGroups.next();
counter++;
}
assertEquals(2, counter);
assertThat(counter).isEqualTo(2);
}
@Test
@@ -292,7 +288,7 @@ public class GemfireGroupStoreTests {
executor.awaitTermination(10, TimeUnit.SECONDS);
store2.removeMessagesFromGroup(1, message); // ensures that if ADD thread executed after REMOVE, the store is empty for the next cycle
}
assertTrue(failures.size() == 0);
assertThat(failures.size() == 0).isTrue();
}
@Test
@@ -308,9 +304,9 @@ public class GemfireGroupStoreTests {
Message<?> m2 = MessageBuilder.withPayload("2").setSequenceNumber(2).setSequenceSize(3).setCorrelationId(1)
.build();
input.send(m1);
assertNull(output.receive(1000));
assertThat(output.receive(1000)).isNull();
input.send(m2);
assertNull(output.receive(1000));
assertThat(output.receive(1000)).isNull();
ClassPathXmlApplicationContext context2 = new ClassPathXmlApplicationContext("gemfire-aggregator-config-a.xml",
this.getClass());
@@ -320,7 +316,7 @@ public class GemfireGroupStoreTests {
Message<?> m3 = MessageBuilder.withPayload("3").setSequenceNumber(3).setSequenceSize(3).setCorrelationId(1)
.build();
inputA.send(m3);
assertNotNull(outputA.receive(1000));
assertThat(outputA.receive(1000)).isNotNull();
context1.close();
context2.close();
}
@@ -338,9 +334,9 @@ public class GemfireGroupStoreTests {
Thread.sleep(1);
}
for (int i = 0; i < 20; i++) {
assertNotNull(outputQueue.receive(5000));
assertThat(outputQueue.receive(5000)).isNotNull();
}
assertNull(outputQueue.receive(1));
assertThat(outputQueue.receive(1)).isNull();
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.integration.gemfire.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -63,7 +61,7 @@ public class GemfireMessageStoreTests {
Message<?> message = MessageBuilder.withPayload("test").build();
store.addMessage(message);
Message<?> retrieved = store.getMessage(message.getHeaders().getId());
assertEquals(message, retrieved);
assertThat(retrieved).isEqualTo(message);
}
@Test
@@ -74,7 +72,7 @@ public class GemfireMessageStoreTests {
region.afterPropertiesSet();
GemfireMessageStore store = new GemfireMessageStore(region.getObject());
assertSame(region.getObject(), TestUtils.getPropertyValue(store, "messageStoreRegion"));
assertThat(TestUtils.getPropertyValue(store, "messageStoreRegion")).isSameAs(region.getObject());
region.destroy();
}
@@ -94,11 +92,11 @@ public class GemfireMessageStoreTests {
store.addMessage(message);
message = store.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
assertThat(messageHistory).isNotNull();
assertThat(messageHistory.size()).isEqualTo(2);
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
}
@Test
@@ -113,10 +111,10 @@ public class GemfireMessageStoreTests {
messages.add(message);
}
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(25, group.size());
assertThat(group.size()).isEqualTo(25);
messageStore.removeMessagesFromGroup(groupId, messages);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -134,12 +132,12 @@ public class GemfireMessageStoreTests {
MessageGroupMetadata messageGroupMetadata =
(MessageGroupMetadata) region.get("foo_" + "MESSAGE_GROUP_" + groupId);
assertNotNull(messageGroupMetadata);
assertEquals(25, messageGroupMetadata.size());
assertThat(messageGroupMetadata).isNotNull();
assertThat(messageGroupMetadata.size()).isEqualTo(25);
messageStore.removeMessagesFromGroup(groupId, messages);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Before

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,7 @@
package org.springframework.integration.gemfire.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -72,11 +69,12 @@ public class AggregatorWithGemfireLocksTests {
this.releaseStrategy.reset(1);
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 1));
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertEquals(1, this.releaseStrategy.maxCallers.get());
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
assertThat(this.out.receive(10000)).isNotNull();
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(1);
assertThat(this.exception)
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
}
@Test
@@ -88,15 +86,16 @@ public class AggregatorWithGemfireLocksTests {
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 2));
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 3));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 3));
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
this.releaseStrategy.latch1.countDown();
this.releaseStrategy.latch1.countDown();
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertNotNull(this.out.receive(10000));
assertNotNull(this.out.receive(10000));
assertEquals(3, this.releaseStrategy.maxCallers.get());
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
assertThat(this.out.receive(10000)).isNotNull();
assertThat(this.out.receive(10000)).isNotNull();
assertThat(this.out.receive(10000)).isNotNull();
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(3);
assertThat(this.exception)
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
}
@Test
@@ -111,11 +110,12 @@ public class AggregatorWithGemfireLocksTests {
exception = e;
}
});
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertEquals(1, this.releaseStrategy.maxCallers.get());
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
assertThat(this.out.receive(10000)).isNotNull();
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(1);
assertThat(this.exception)
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
}
private Runnable asyncSend(final String payload, final int sequence, final int correlation) {