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 2013 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,7 +16,7 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -77,13 +77,13 @@ public class Int3164Jsr223RefreshTests {
@Test
public void testRefreshingScript() throws Exception {
this.referencedScriptInput.send(new GenericMessage<Object>("test"));
assertEquals(1, this.outputChannel.receive(100).getPayload());
assertThat(this.outputChannel.receive(100).getPayload()).isEqualTo(1);
FileCopyUtils.copy("2".getBytes(), scriptFile);
scriptFile.setLastModified(System.currentTimeMillis() + 10000); // force refresh
this.referencedScriptInput.send(new GenericMessage<Object>("test"));
assertEquals(2, this.outputChannel.receive(100).getPayload());
assertThat(this.outputChannel.receive(100).getPayload()).isEqualTo(2);
}
}

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.scripting.config.jsr223;
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 org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,8 +59,8 @@ public class Jsr223FilterTests {
.build();
this.referencedScriptInput.send(message1);
this.referencedScriptInput.send(message2);
assertEquals("test-2", replyChannel.receive(0).getPayload());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("test-2");
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -74,10 +72,10 @@ public class Jsr223FilterTests {
this.inlineScriptInput.send(message1);
this.inlineScriptInput.send(message2);
Message<?> received = replyChannel.receive(0);
assertNotNull(received);
assertEquals("good", received.getPayload());
assertEquals(message2, received);
assertNull(replyChannel.receive(0));
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo("good");
assertThat(received).isEqualTo(message2);
assertThat(replyChannel.receive(0)).isNull();
}
}

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.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -53,12 +53,12 @@ public class Jsr223HeaderEnricherTests {
@Test
public void referencedScript() throws Exception {
inputA.send(new GenericMessage<String>("Hello"));
assertEquals("jruby", outputA.receive(20000).getHeaders().get("TEST_HEADER"));
assertThat(outputA.receive(20000).getHeaders().get("TEST_HEADER")).isEqualTo("jruby");
}
@Test
public void inlineScript() throws Exception {
inputB.send(new GenericMessage<String>("Hello"));
assertEquals("js", outputB.receive(20000).getHeaders().get("TEST_HEADER"));
assertThat(outputB.receive(20000).getHeaders().get("TEST_HEADER")).isEqualTo("js");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 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,7 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Date;
@@ -52,15 +48,15 @@ public class Jsr223InboundChannelAdapterTests {
@Test
public void testInt2867InboundChannelAdapter() throws Exception {
Message<?> message = this.inboundChannelAdapterChannel.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload = message.getPayload();
Thread.sleep(2);
assertThat(payload, instanceOf(Date.class));
assertTrue(((Date) payload).before(new Date()));
assertEquals("bar", message.getHeaders().get("foo"));
assertThat(payload).isInstanceOf(Date.class);
assertThat(((Date) payload).before(new Date())).isTrue();
assertThat(message.getHeaders().get("foo")).isEqualTo("bar");
message = this.inboundChannelAdapterChannel.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
}
}

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.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.beans.PropertyEditorSupport;
import java.io.ByteArrayInputStream;
@@ -52,10 +51,10 @@ public class Jsr223RefreshTests {
QueueChannel replyChannel = new QueueChannel();
replyChannel.setBeanName("returnAddress");
this.referencedScriptInput.send(MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build());
assertEquals("ruby-test-1", replyChannel.receive(0).getPayload());
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("ruby-test-1");
this.referencedScriptInput.send(MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build());
assertEquals("ruby-test-0", replyChannel.receive(0).getPayload());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("ruby-test-0");
assertThat(replyChannel.receive(0)).isNull();
}
public static class ResourceEditor extends PropertyEditorSupport {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,13 +67,13 @@ public class Jsr223RouterTests {
this.referencedScriptInput.send(message3);
this.referencedScriptInput.send(message4);
this.referencedScriptInput.send(message5);
assertEquals("cat", shortStrings.receive(0).getPayload());
assertEquals("dog", shortStrings.receive(0).getPayload());
assertEquals("aardvark", longStrings.receive(0).getPayload());
assertEquals("bear", longStrings.receive(0).getPayload());
assertEquals("elephant", longStrings.receive(0).getPayload());
assertNull(shortStrings.receive(0));
assertNull(longStrings.receive(0));
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("cat");
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("dog");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("aardvark");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("bear");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("elephant");
assertThat(shortStrings.receive(0)).isNull();
assertThat(longStrings.receive(0)).isNull();
}
@Test
@@ -89,13 +88,13 @@ public class Jsr223RouterTests {
this.inlineScriptInput.send(message3);
this.inlineScriptInput.send(message4);
this.inlineScriptInput.send(message5);
assertEquals("bear", shortStrings.receive(0).getPayload());
assertEquals("cat", shortStrings.receive(0).getPayload());
assertEquals("dog", shortStrings.receive(0).getPayload());
assertEquals("aardvark", longStrings.receive(0).getPayload());
assertEquals("elephant", longStrings.receive(0).getPayload());
assertNull(shortStrings.receive(0));
assertNull(longStrings.receive(0));
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("bear");
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("cat");
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("dog");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("aardvark");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("elephant");
assertThat(shortStrings.receive(0)).isNull();
assertThat(longStrings.receive(0)).isNull();
}
@Test
@@ -110,13 +109,13 @@ public class Jsr223RouterTests {
this.scriptRouterWithinChainInput.send(message3);
this.scriptRouterWithinChainInput.send(message4);
this.scriptRouterWithinChainInput.send(message5);
assertEquals("bear", shortStrings.receive(0).getPayload());
assertEquals("cat", shortStrings.receive(0).getPayload());
assertEquals("dog", shortStrings.receive(0).getPayload());
assertEquals("aardvark", longStrings.receive(0).getPayload());
assertEquals("elephant", longStrings.receive(0).getPayload());
assertNull(shortStrings.receive(0));
assertNull(longStrings.receive(0));
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("bear");
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("cat");
assertThat(shortStrings.receive(0).getPayload()).isEqualTo("dog");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("aardvark");
assertThat(longStrings.receive(0).getPayload()).isEqualTo("elephant");
assertThat(shortStrings.receive(0)).isNull();
assertThat(longStrings.receive(0)).isNull();
}
}

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,13 +16,8 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
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.Date;
import java.util.HashMap;
@@ -75,26 +70,26 @@ public class Jsr223ServiceActivatorTests {
String value1 = (String) replyChannel.receive(0).getPayload();
String value2 = (String) replyChannel.receive(0).getPayload();
String value3 = (String) replyChannel.receive(0).getPayload();
assertTrue(value1.startsWith("python-test-1-foo (foo2) - bar"));
assertTrue(value2.startsWith("python-test-2-foo (foo2) - bar"));
assertTrue(value3.startsWith("python-test-3-foo (foo2) - bar"));
assertThat(value1.startsWith("python-test-1-foo (foo2) - bar")).isTrue();
assertThat(value2.startsWith("python-test-2-foo (foo2) - bar")).isTrue();
assertThat(value3.startsWith("python-test-3-foo (foo2) - bar")).isTrue();
// because we are using 'prototype bean the suffix date will be
// different
assertFalse(value1.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))));
assertFalse(value1.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value1.substring(value1.lastIndexOf(":"))));
assertThat(value1.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":")))).isFalse();
assertThat(value1.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value1.substring(value1.lastIndexOf(":")))).isFalse();
assertFalse(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value3.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))));
assertThat(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
.equals(value3.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":")))).isFalse();
assertFalse(value1.substring(value1.lastIndexOf(":") + 1)
.equals(value2.substring(value1.lastIndexOf(":") + 1)));
assertFalse(value2.substring(value1.lastIndexOf(":") + 1)
.equals(value3.substring(value1.lastIndexOf(":") + 1)));
assertThat(value1.substring(value1.lastIndexOf(":") + 1)
.equals(value2.substring(value1.lastIndexOf(":") + 1))).isFalse();
assertThat(value2.substring(value1.lastIndexOf(":") + 1)
.equals(value3.substring(value1.lastIndexOf(":") + 1))).isFalse();
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -110,16 +105,16 @@ public class Jsr223ServiceActivatorTests {
String value1 = (String) replyChannel.receive(0).getPayload();
String value2 = (String) replyChannel.receive(0).getPayload();
String value3 = (String) replyChannel.receive(0).getPayload();
assertTrue(value1.startsWith("ruby-test-1-foo - bar"));
assertTrue(value2.startsWith("ruby-test-2-foo - bar"));
assertTrue(value3.startsWith("ruby-test-3-foo - bar"));
assertThat(value1.startsWith("ruby-test-1-foo - bar")).isTrue();
assertThat(value2.startsWith("ruby-test-2-foo - bar")).isTrue();
assertThat(value3.startsWith("ruby-test-3-foo - bar")).isTrue();
// because we are using 'prototype bean the suffix date will be
// different
assertFalse(value1.substring(26).equals(value2.substring(26)));
assertFalse(value2.substring(26).equals(value3.substring(26)));
assertThat(value1.substring(26).equals(value2.substring(26))).isFalse();
assertThat(value2.substring(26).equals(value3.substring(26))).isFalse();
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -133,16 +128,16 @@ public class Jsr223ServiceActivatorTests {
}
String payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, startsWith("inline-test-1 - FOO"));
assertThat(payload).startsWith("inline-test-1 - FOO");
payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, startsWith("inline-test-2 - FOO"));
assertThat(payload).startsWith("inline-test-2 - FOO");
payload = (String) replyChannel.receive(0).getPayload();
assertThat(payload, startsWith("inline-test-3 - FOO"));
assertTrue(payload.substring(payload.indexOf(":") + 1).matches(".+\\d{2}:\\d{2}:\\d{2}.+"));
assertThat(payload).startsWith("inline-test-3 - FOO");
assertThat(payload.substring(payload.indexOf(":") + 1).matches(".+\\d{2}:\\d{2}:\\d{2}.+")).isTrue();
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
}
@@ -154,8 +149,8 @@ public class Jsr223ServiceActivatorTests {
fail("BeansException expected.");
}
catch (BeansException e) {
assertThat(e.getMessage(),
containsString("'script-variable-generator' and 'variable' sub-elements are mutually exclusive."));
assertThat(e.getMessage())
.contains("'script-variable-generator' and 'variable' sub-elements are mutually exclusive.");
}
}
@@ -167,7 +162,7 @@ public class Jsr223ServiceActivatorTests {
fail("BeansException expected.");
}
catch (BeansException e) {
assertThat(e.getMessage(), containsString("Duplicated variable: foo"));
assertThat(e.getMessage()).contains("Duplicated variable: foo");
}
}

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.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,10 +50,10 @@ public class Jsr223SplitterTests {
replyChannel.setBeanName("returnAddress");
Message<?> message = MessageBuilder.withPayload("x,y,z").setReplyChannel(replyChannel).build();
this.referencedScriptInput.send(message);
assertEquals("x", replyChannel.receive(0).getPayload());
assertEquals("y", replyChannel.receive(0).getPayload());
assertEquals("z", replyChannel.receive(0).getPayload());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("x");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("y");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("z");
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -63,10 +62,10 @@ public class Jsr223SplitterTests {
replyChannel.setBeanName("returnAddress");
Message<?> message = MessageBuilder.withPayload("a b c").setReplyChannel(replyChannel).build();
this.inlineScriptInput.send(message);
assertEquals("a", replyChannel.receive(0).getPayload());
assertEquals("b", replyChannel.receive(0).getPayload());
assertEquals("c", replyChannel.receive(0).getPayload());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("a");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("b");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("c");
assertThat(replyChannel.receive(0)).isNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.scripting.config.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashSet;
import java.util.Set;
@@ -65,10 +64,10 @@ public class Jsr223TransformerTests {
Message<?> message = MessageBuilder.withPayload("test-" + i).setReplyChannel(replyChannel).build();
this.referencedScriptInput.send(message);
}
assertEquals("ruby-test-1", replyChannel.receive(0).getPayload());
assertEquals("ruby-test-2", replyChannel.receive(0).getPayload());
assertEquals("ruby-test-3", replyChannel.receive(0).getPayload());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("ruby-test-1");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("ruby-test-2");
assertThat(replyChannel.receive(0).getPayload()).isEqualTo("ruby-test-3");
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -79,10 +78,10 @@ public class Jsr223TransformerTests {
Message<?> message = MessageBuilder.withPayload("test-" + i).setReplyChannel(replyChannel).build();
this.inlineScriptInput.send(message);
}
assertEquals("inline-test-1", replyChannel.receive(0).getPayload().toString());
assertEquals("inline-test-2", replyChannel.receive(0).getPayload().toString());
assertEquals("inline-test-3", replyChannel.receive(0).getPayload().toString());
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0).getPayload().toString()).isEqualTo("inline-test-1");
assertThat(replyChannel.receive(0).getPayload().toString()).isEqualTo("inline-test-2");
assertThat(replyChannel.receive(0).getPayload().toString()).isEqualTo("inline-test-3");
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -98,7 +97,7 @@ public class Jsr223TransformerTests {
result.add(message.getPayload());
}
assertEquals(100, result.size());
assertThat(result.size()).isEqualTo(100);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-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,17 +16,12 @@
package org.springframework.integration.scripting.dsl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -117,9 +112,9 @@ public class ScriptsTests {
@Test
public void splitterTest() {
this.splitterInput.send(new GenericMessage<>("x,y,z"));
assertEquals("x", this.results.receive(10000).getPayload());
assertEquals("y", this.results.receive(10000).getPayload());
assertEquals("z", this.results.receive(10000).getPayload());
assertThat(this.results.receive(10000).getPayload()).isEqualTo("x");
assertThat(this.results.receive(10000).getPayload()).isEqualTo("y");
assertThat(this.results.receive(10000).getPayload()).isEqualTo("z");
}
@Test
@@ -127,9 +122,9 @@ public class ScriptsTests {
for (int i = 1; i <= 3; i++) {
this.transformerInput.send(new GenericMessage<>("test-" + i));
}
assertEquals("ruby-test-1-bar", this.results.receive(10000).getPayload());
assertEquals("ruby-test-2-bar", this.results.receive(10000).getPayload());
assertEquals("ruby-test-3-bar", this.results.receive(10000).getPayload());
assertThat(this.results.receive(10000).getPayload()).isEqualTo("ruby-test-1-bar");
assertThat(this.results.receive(10000).getPayload()).isEqualTo("ruby-test-2-bar");
assertThat(this.results.receive(10000).getPayload()).isEqualTo("ruby-test-3-bar");
}
@Test
@@ -138,22 +133,22 @@ public class ScriptsTests {
Message<?> message2 = MessageBuilder.withPayload("good").setHeader("type", "good").build();
this.filterInput.send(message1);
this.filterInput.send(message2);
assertEquals("good", this.results.receive(10000).getPayload());
assertNull(this.results.receive(0));
assertEquals("bad", this.discardChannel.receive(10000).getPayload());
assertNull(this.discardChannel.receive(0));
assertThat(this.results.receive(10000).getPayload()).isEqualTo("good");
assertThat(this.results.receive(0)).isNull();
assertThat(this.discardChannel.receive(10000).getPayload()).isEqualTo("bad");
assertThat(this.discardChannel.receive(0)).isNull();
}
@Test
public void serviceWithRefreshCheckDelayTest() throws IOException {
this.scriptServiceInput.send(new GenericMessage<Object>("test"));
assertEquals(1, this.results.receive(10000).getPayload());
assertThat(this.results.receive(10000).getPayload()).isEqualTo(1);
FileCopyUtils.copy("2".getBytes(), SCRIPT_FILE);
SCRIPT_FILE.setLastModified(System.currentTimeMillis() + 10000); // force refresh
this.scriptServiceInput.send(new GenericMessage<Object>("test"));
assertEquals(2, this.results.receive(10000).getPayload());
assertThat(this.results.receive(10000).getPayload()).isEqualTo(2);
}
@Test
@@ -163,26 +158,26 @@ public class ScriptsTests {
this.scriptRouterInput.send(new GenericMessage<>("cat"));
this.scriptRouterInput.send(new GenericMessage<>("dog"));
this.scriptRouterInput.send(new GenericMessage<>("elephant"));
assertEquals("bear", this.shortStrings.receive(10000).getPayload());
assertEquals("cat", this.shortStrings.receive(10000).getPayload());
assertEquals("dog", this.shortStrings.receive(10000).getPayload());
assertEquals("aardvark", this.longStrings.receive(10000).getPayload());
assertEquals("elephant", this.longStrings.receive(10000).getPayload());
assertThat(this.shortStrings.receive(10000).getPayload()).isEqualTo("bear");
assertThat(this.shortStrings.receive(10000).getPayload()).isEqualTo("cat");
assertThat(this.shortStrings.receive(10000).getPayload()).isEqualTo("dog");
assertThat(this.longStrings.receive(10000).getPayload()).isEqualTo("aardvark");
assertThat(this.longStrings.receive(10000).getPayload()).isEqualTo("elephant");
}
@Test
public void messageSourceTest() throws IOException, InterruptedException {
Message<?> message = this.messageSourceChannel.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload = message.getPayload();
assertThat(payload, Matchers.instanceOf(Date.class));
assertThat(payload).isInstanceOf(Date.class);
// Some time window to avoid dates collision
Thread.sleep(2);
assertTrue(((Date) payload).before(new Date()));
assertThat(((Date) payload).before(new Date())).isTrue();
assertNotNull(this.messageSourceChannel.receive(20000));
assertThat(this.messageSourceChannel.receive(20000)).isNotNull();
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.scripting.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
@@ -53,7 +52,7 @@ public class DeriveLanguageFromExtensionTests {
Map<String, ScriptExecutingMessageProcessor> scriptProcessors = ctx
.getBeansOfType(ScriptExecutingMessageProcessor.class);
assertEquals(4, scriptProcessors.size());
assertThat(scriptProcessors.size()).isEqualTo(4);
for (int i = 0; i < 4; i++) {
@@ -63,8 +62,8 @@ public class DeriveLanguageFromExtensionTests {
AbstractScriptExecutor executor = (AbstractScriptExecutor) TestUtils.getPropertyValue(processor,
"scriptExecutor");
assertEquals(langs[i], executor.language);
assertEquals(executors[i], executor.getClass());
assertThat(executor.language).isEqualTo(langs[i]);
assertThat(executor.getClass()).isEqualTo(executors[i]);
}
}
@@ -75,7 +74,7 @@ public class DeriveLanguageFromExtensionTests {
.close();
}
catch (Exception e) {
assertTrue(e.getMessage().contains("No suitable scripting engine found for extension 'xx'"));
assertThat(e.getMessage().contains("No suitable scripting engine found for extension 'xx'")).isTrue();
}
}
@@ -86,7 +85,7 @@ public class DeriveLanguageFromExtensionTests {
.close();
}
catch (Exception e) {
assertTrue(e.getMessage().contains("Unable to determine language for script 'foo'"));
assertThat(e.getMessage().contains("Unable to determine language for script 'foo'")).isTrue();
}
}

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.scripting.jsr223;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -62,7 +62,7 @@ public class Jsr223ScriptExecutingMessageProcessorTests {
Object obj = messageProcessor.processMessage(message);
assertEquals("hello modified", obj.toString().substring(0, "hello modified".length()));
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
}
@Test
@@ -76,7 +76,7 @@ public class Jsr223ScriptExecutingMessageProcessorTests {
Object obj = messageProcessor.processMessage(message);
assertEquals("hello modified", obj.toString().substring(0, "hello modified".length()));
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
}
}

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.scripting.jsr223;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -54,24 +54,24 @@ public class Jsr223ScriptExecutorTests {
Resource resource = new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb");
String result = (String) executor.executeScript(new ResourceScriptSource(resource), variables);
assertEquals("payload modified", result.substring(0, "payload modified".length()));
assertThat(result.substring(0, "payload modified".length())).isEqualTo("payload modified");
}
@Test
public void testJs() {
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("js");
Object obj = executor.executeScript(new StaticScriptSource("function js(){ return 'js';} js();"));
assertEquals("js", obj.toString());
assertThat(obj.toString()).isEqualTo("js");
}
@Test
public void testPython() {
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("python");
Object obj = executor.executeScript(new StaticScriptSource("x=2"));
assertEquals(2, obj);
assertThat(obj).isEqualTo(2);
obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)"));
assertEquals(2, obj);
assertThat(obj).isEqualTo(2);
}
@Test(expected = IllegalArgumentException.class)

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.scripting.jsr223;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +34,7 @@ import org.springframework.scripting.support.StaticScriptSource;
/**
* @author David Turanski
* @author Gary Russell
* @author Artem Bilan
*
*/
public class PythonScriptExecutorTests {
@@ -49,23 +49,23 @@ public class PythonScriptExecutorTests {
@Test
public void testLiteral() {
Object obj = executor.executeScript(new StaticScriptSource("3+4"));
assertEquals(7, obj);
assertThat(obj).isEqualTo(7);
obj = executor.executeScript(new StaticScriptSource("'hello,world'"));
assertEquals("hello,world", obj);
assertThat(obj).isEqualTo("hello,world");
}
@Test
public void test1() {
Object obj = executor.executeScript(new StaticScriptSource("x=2"));
assertEquals(2, obj);
assertThat(obj).isEqualTo(2);
}
@Test
public void test2() {
Object obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)"));
assertEquals(2, obj);
assertThat(obj).isEqualTo(2);
}
@Test
@@ -75,7 +75,7 @@ public class PythonScriptExecutorTests {
new ClassPathResource("/org/springframework/integration/scripting/jsr223/test3.py"));
Object obj = executor.executeScript(source);
PyTuple tuple = (PyTuple) obj;
assertEquals(1, tuple.get(0));
assertThat(tuple.get(0)).isEqualTo(1);
}
@Test
@@ -83,19 +83,20 @@ public class PythonScriptExecutorTests {
ScriptSource source =
new ResourceScriptSource(
new ClassPathResource("/org/springframework/integration/scripting/jsr223/test3.py"));
HashMap<String, Object> variables = new HashMap<String, Object>();
HashMap<String, Object> variables = new HashMap<>();
variables.put("foo", "bar");
Object obj = executor.executeScript(source, variables);
assertThat(obj).isNotNull();
PyTuple tuple = (PyTuple) obj;
assertNotNull(tuple);
assertEquals(1, tuple.get(0));
assertThat(tuple.get(0)).isEqualTo(1);
}
@Test
public void testEmbeddedVariable() {
Map<String, Object> variables = new HashMap<String, Object>();
Map<String, Object> variables = new HashMap<>();
variables.put("scope", "world");
Object obj = executor.executeScript(new StaticScriptSource("\"hello, %s\"% scope"), variables);
assertEquals("hello, world", obj);
assertThat(obj).isEqualTo("hello, world");
}
}

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.scripting.jsr223;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
@@ -35,10 +35,10 @@ public class PythonVariableParserTests {
@Test
public void testBasic() throws IOException {
String var = PythonScriptExecutor.PythonVariableParser.parseReturnVariable("x=2");
assertEquals("x", var);
assertThat(var).isEqualTo("x");
var = PythonScriptExecutor.PythonVariableParser.parseReturnVariable("\n\n\nx = 2\n\n\n");
assertEquals("x", var);
assertThat(var).isEqualTo("x");
var = PythonScriptExecutor.PythonVariableParser.parseReturnVariable("\n\n\nx\n\n\n");
}
@@ -49,6 +49,6 @@ public class PythonVariableParserTests {
ScriptSource source =
new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/test2.py"));
String var = PythonScriptExecutor.PythonVariableParser.parseReturnVariable(source.getScriptAsString());
assertEquals("bar", var);
assertThat(var).isEqualTo("bar");
}
}