This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit d3e6ccdad3f1a6a8a6bafdac26133f2b9ee04f00 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Thu Jun 25 11:41:59 2020 +0200 [CAMEL-11807] Upgrade camel-gora to junit5 --- components/camel-gora/pom.xml | 8 ++--- .../component/gora/GoraConfigurationTest.java | 39 +++++++++++++--------- .../camel/component/gora/GoraConsumerTest.java | 8 ++--- .../camel/component/gora/GoraProducerTest.java | 29 ++++++++-------- .../camel/component/gora/GoraTestSupport.java | 2 +- .../camel/component/gora/utils/GoraUtilsTest.java | 12 ++++--- 6 files changed, 56 insertions(+), 42 deletions(-) diff --git a/components/camel-gora/pom.xml b/components/camel-gora/pom.xml index d2a60b7..9b222e9 100644 --- a/components/camel-gora/pom.xml +++ b/components/camel-gora/pom.xml @@ -49,18 +49,18 @@ <!-- testing --> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java index dfd5d10..770bf04 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java @@ -16,53 +16,62 @@ */ package org.apache.camel.component.gora; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * GORA Configuration Tests */ public class GoraConfigurationTest { - @Test(expected = IllegalArgumentException.class) + @Test public void setKeyClassClassShouldThrowExceptionIfNull() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setValueClass(null); + assertThrows(IllegalArgumentException.class, + () -> conf.setValueClass(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void setKeyClassShouldThrowExceptionIfEmpty() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setValueClass(""); + assertThrows(IllegalArgumentException.class, + () -> conf.setValueClass("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void setValueClassClassShouldThrowExceptionIfNull() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setValueClass(null); + assertThrows(IllegalArgumentException.class, + () -> conf.setValueClass(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void setValueClassClassShouldThrowExceptionIfEmpty() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setValueClass(""); + assertThrows(IllegalArgumentException.class, + () -> conf.setValueClass("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void setDataStoreClassShouldThrowExceptionIfNull() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setDataStoreClass(null); + assertThrows(IllegalArgumentException.class, + () -> conf.setDataStoreClass(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void setDataStoreClassShouldThrowExceptionIfEmpty() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setDataStoreClass(""); + assertThrows(IllegalArgumentException.class, + () -> conf.setDataStoreClass("")); } - @Test(expected = NullPointerException.class) + @Test public void setHadoopConfigurationShouldThrowExceptionIfNull() { final GoraConfiguration conf = new GoraConfiguration(); - conf.setHadoopConfiguration(null); + assertThrows(NullPointerException.class, + () -> conf.setHadoopConfiguration(null)); } } diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java index d4de99b..b6492ce 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java @@ -24,17 +24,17 @@ import org.apache.camel.Processor; import org.apache.gora.persistency.Persistent; import org.apache.gora.query.Query; import org.apache.gora.store.DataStore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.when; /** * GORA Consumer Tests */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GoraConsumerTest extends GoraTestSupport { /** diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java index 2ff47ee..5f2dda46 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java @@ -20,12 +20,13 @@ import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.gora.persistency.Persistent; import org.apache.gora.store.DataStore; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.mock; @@ -35,7 +36,7 @@ import static org.mockito.Mockito.when; /** * GORA Producer Tests */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GoraProducerTest extends GoraTestSupport { // TODO: Query methods does not yet has tests @@ -71,7 +72,7 @@ public class GoraProducerTest extends GoraTestSupport { private DataStore<Object, Persistent> mockDatastore; @Override - @Before + @BeforeEach public void setUp() { //setup mocks mockCamelExchange = mock(Exchange.class); @@ -83,19 +84,21 @@ public class GoraProducerTest extends GoraTestSupport { when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); } - @Test(expected = RuntimeException.class) + @Test public void processShouldThrowExceptionIfOperationIsNull() throws Exception { final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore); - producer.process(mockCamelExchange); + assertThrows(RuntimeException.class, + () -> producer.process(mockCamelExchange)); } - @Test(expected = RuntimeException.class) + @Test public void shouldThrowExceptionIfOperationIsUnknown() throws Exception { when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("dah"); final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore); - producer.process(mockCamelExchange); + assertThrows(RuntimeException.class, + () -> producer.process(mockCamelExchange)); verify(mockCamelExchange, atMost(1)).getIn(); verify(mockCamelMessage, atMost(1)).getHeader(GoraAttribute.GORA_OPERATION.value); @@ -106,7 +109,7 @@ public class GoraProducerTest extends GoraTestSupport { when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("PUT"); - final Long sampleKey = new Long(2); + final Long sampleKey = 2L; when(mockCamelMessage.getHeader(GoraAttribute.GORA_KEY.value)).thenReturn(sampleKey); final Persistent sampleValue = mock(Persistent.class); @@ -130,7 +133,7 @@ public class GoraProducerTest extends GoraTestSupport { when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("get"); - final Long sampleKey = new Long(2); + final Long sampleKey = 2L; when(mockCamelMessage.getHeader(GoraAttribute.GORA_KEY.value)).thenReturn(sampleKey); final Message outMessage = mock(Message.class); @@ -150,7 +153,7 @@ public class GoraProducerTest extends GoraTestSupport { when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("dEletE"); - final Long sampleKey = new Long(2); + final Long sampleKey = 2L; when(mockCamelMessage.getHeader(GoraAttribute.GORA_KEY.value)).thenReturn(sampleKey); final Message outMessage = mock(Message.class); diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java index 8769fac..4c71983 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java @@ -16,7 +16,7 @@ */ package org.apache.camel.component.gora; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; /** * GORA Test Support diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java index ff01be7..1169611 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java @@ -18,10 +18,11 @@ package org.apache.camel.component.gora.utils; import org.apache.camel.component.gora.GoraAttribute; import org.apache.camel.component.gora.GoraConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * GORA Utils Tests @@ -34,10 +35,11 @@ public class GoraUtilsTest { assertTrue(GoraUtils.configurationExist(GoraAttribute.GORA_QUERY_LIMIT, conf)); } - @Test(expected = NoSuchMethodException.class) + @Test public void configurationExistShouldThrowExceptionIfMethodDoesNotExist() throws Exception { final GoraConfiguration conf = new GoraConfiguration(); - GoraUtils.configurationExist(GoraAttribute.GORA_KEY, conf); + assertThrows(NoSuchMethodException.class, + () -> GoraUtils.configurationExist(GoraAttribute.GORA_KEY, conf)); } @Test