This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 5906212 CAMEL-11807: Migrated camel-gson tests to JUnit 5 5906212 is described below commit 5906212aac8b4df435c7cfdf03cbdded0bdb39d8 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Fri Feb 7 16:11:37 2020 +0100 CAMEL-11807: Migrated camel-gson tests to JUnit 5 --- components/camel-gson/pom.xml | 7 +------ .../apache/camel/component/gson/GsonConcurrentTest.java | 6 ++++-- .../apache/camel/component/gson/GsonDataFormatTest.java | 16 ++++++++-------- .../camel/component/gson/GsonFieldNamePolicyTest.java | 15 +++++++++------ .../camel/component/gson/GsonJsonDataFormatTest.java | 12 +++++++----- .../camel/component/gson/GsonMarshalExclusionTest.java | 10 ++++++---- .../apache/camel/component/gson/GsonMarshalListTest.java | 12 ++++++------ .../org/apache/camel/component/gson/GsonMarshalTest.java | 10 ++++++---- .../component/gson/SpringGsonFieldNamePolicyTest.java | 11 +++++++---- .../component/gson/SpringGsonJsonDataFormatTest.java | 6 ++++-- 10 files changed, 58 insertions(+), 47 deletions(-) diff --git a/components/camel-gson/pom.xml b/components/camel-gson/pom.xml index 2fe0a55..883b39f 100644 --- a/components/camel-gson/pom.xml +++ b/components/camel-gson/pom.xml @@ -49,7 +49,7 @@ <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> + <artifactId>camel-test-spring-junit5</artifactId> <scope>test</scope> </dependency> <dependency> @@ -67,11 +67,6 @@ <artifactId>log4j-slf4j-impl</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonConcurrentTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonConcurrentTest.java index ea418f4..22f6a8f 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonConcurrentTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonConcurrentTest.java @@ -22,8 +22,10 @@ import java.util.concurrent.Executors; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.dataformat.JsonLibrary; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.apache.camel.test.junit5.TestSupport.body; public class GsonConcurrentTest extends CamelTestSupport { diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java index 4770f49..455d311 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java @@ -19,9 +19,9 @@ package org.apache.camel.component.gson; import java.io.*; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class GsonDataFormatTest { @Test @@ -41,12 +41,12 @@ public class GsonDataFormatTest { private void testJson(String json, Object expected) throws Exception { Object unmarshalled; - GsonDataFormat gsonDataFormat = new GsonDataFormat(); - gsonDataFormat.doStart(); - try (InputStream in = new ByteArrayInputStream(json.getBytes())) { - unmarshalled = gsonDataFormat.unmarshal(null, in); + try (GsonDataFormat gsonDataFormat = new GsonDataFormat()) { + gsonDataFormat.doStart(); + try (InputStream in = new ByteArrayInputStream(json.getBytes())) { + unmarshalled = gsonDataFormat.unmarshal(null, in); + } + assertEquals(expected, unmarshalled); } - - assertEquals(expected, unmarshalled); } } diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java index a53bd1d..23c616f 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java @@ -18,13 +18,16 @@ package org.apache.camel.component.gson; import com.google.gson.FieldNamingPolicy; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class GsonFieldNamePolicyTest extends CamelTestSupport { @Test - public void testUnmarshalPojo() throws Exception { + public void testUnmarshalPojo() { String json = "{\"id\":\"123\",\"first_name\":\"Donald\",\"last_name\":\"Duck\"}"; PersonPojo pojo = template.requestBody("direct:backPojo", json, PersonPojo.class); assertNotNull(pojo); @@ -35,7 +38,7 @@ public class GsonFieldNamePolicyTest extends CamelTestSupport { } @Test - public void testMarshalPojo() throws Exception { + public void testMarshalPojo() { PersonPojo pojo = new PersonPojo(); pojo.setId(123); pojo.setFirstName("Donald"); @@ -47,10 +50,10 @@ public class GsonFieldNamePolicyTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { GsonDataFormat formatPojo = new GsonDataFormat(); formatPojo.setUnmarshalType(PersonPojo.class); formatPojo.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonJsonDataFormatTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonJsonDataFormatTest.java index 4c83a84..75e1a5f 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonJsonDataFormatTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonJsonDataFormatTest.java @@ -20,23 +20,25 @@ import java.util.Map; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.dataformat.JsonLibrary; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GsonJsonDataFormatTest extends GsonMarshalTest { @Test - public void testUnmarshalMap() throws Exception { + public void testUnmarshalMap() { Map<?, ?> unmarshalled = template.requestBody("direct:json", "{\"pointsOfSale\":{\"pointOfSale\":{\"prodcut\":\"newpad\"}}}", Map.class); Map<?, ?> map1 = (Map<?, ?>) unmarshalled.get("pointsOfSale"); Map<?, ?> map2 = (Map<?, ?>) map1.get("pointOfSale"); - assertEquals("Don't get the right value", "newpad", map2.get("prodcut")); + assertEquals("newpad", map2.get("prodcut"), "Don't get the right value"); } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:in").marshal().json(JsonLibrary.Gson); from("direct:back").unmarshal().json(JsonLibrary.Gson).to("mock:reverse"); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java index d3cdb2b..7ad27f9 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java @@ -24,8 +24,10 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.gson.annotation.ExcludeAge; import org.apache.camel.component.gson.annotation.ExcludeWeight; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GsonMarshalExclusionTest extends CamelTestSupport { @@ -102,11 +104,11 @@ public class GsonMarshalExclusionTest extends CamelTestSupport { //END SNIPPET: strategy @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { GsonDataFormat weightExclusionFormat = new GsonDataFormat(TestPojoExclusion.class); weightExclusionFormat.setExclusionStrategies(Arrays.<ExclusionStrategy>asList(new WeightExclusionStrategy())); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalListTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalListTest.java index 523adc1..e8efd15 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalListTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalListTest.java @@ -23,12 +23,12 @@ import java.util.List; import com.google.gson.reflect.TypeToken; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class GsonMarshalListTest extends CamelTestSupport { +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +public class GsonMarshalListTest extends CamelTestSupport { @Test public void testMarshalAndUnmarshalPojo() throws Exception { @@ -58,10 +58,10 @@ public class GsonMarshalListTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { GsonDataFormat formatPojo = new GsonDataFormat(); Type genericType = new TypeToken<List<TestPojo>>() { }.getType(); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalTest.java index 946cc4d..953e262 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalTest.java @@ -21,8 +21,10 @@ import java.util.Map; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GsonMarshalTest extends CamelTestSupport { @@ -65,10 +67,10 @@ public class GsonMarshalTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { GsonDataFormat format = new GsonDataFormat(); from("direct:in").marshal(format); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java index 40a0b07..5931bb9 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java @@ -16,11 +16,14 @@ */ package org.apache.camel.component.gson; -import org.apache.camel.test.spring.CamelSpringTestSupport; -import org.junit.Test; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; +import org.junit.jupiter.api.Test; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + public class SpringGsonFieldNamePolicyTest extends CamelSpringTestSupport { @Override @@ -29,7 +32,7 @@ public class SpringGsonFieldNamePolicyTest extends CamelSpringTestSupport { } @Test - public void testUnmarshalPojo() throws Exception { + public void testUnmarshalPojo() { String json = "{\"id\":\"123\",\"first_name\":\"Donald\",\"last_name\":\"Duck\"}"; PersonPojo pojo = template.requestBody("direct:backPojo", json, PersonPojo.class); assertNotNull(pojo); @@ -40,7 +43,7 @@ public class SpringGsonFieldNamePolicyTest extends CamelSpringTestSupport { } @Test - public void testMarshalPojo() throws Exception { + public void testMarshalPojo() { PersonPojo pojo = new PersonPojo(); pojo.setId(123); pojo.setFirstName("Donald"); diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonJsonDataFormatTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonJsonDataFormatTest.java index fad0833..c1ec743 100644 --- a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonJsonDataFormatTest.java +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonJsonDataFormatTest.java @@ -17,11 +17,13 @@ package org.apache.camel.component.gson; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.spring.CamelSpringTestSupport; -import org.junit.Test; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; +import org.junit.jupiter.api.Test; import org.springframework.context.support.AbstractXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class SpringGsonJsonDataFormatTest extends CamelSpringTestSupport { @Test