You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/04/12 11:45:12 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2443] update junit version to 4.13.2 (#2775)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 33c1f4a51 [SCB-2443] update junit version to 4.13.2 (#2775)
33c1f4a51 is described below
commit 33c1f4a51da49b72b0c0d0bfcb819317554ff927
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Tue Apr 12 19:45:06 2022 +0800
[SCB-2443] update junit version to 4.13.2 (#2775)
---
clients/config-center-client/pom.xml | 14 +-
clients/http-client-common/pom.xml | 14 +-
clients/service-center-client/pom.xml | 11 -
.../element/impl/InvocationContextItemTest.java | 19 +-
.../core/element/impl/TraceIdItemTest.java | 20 +-
.../common/rest/TestAbstractRestInvocation.java | 37 +--
.../common/rest/TestRestEngineSchemaListener.java | 36 +-
.../common/rest/TestRestProducerInvocation.java | 12 +-
.../common/rest/codec/param/TestFormProcessor.java | 7 +-
.../rest/codec/param/TestHeaderProcessor.java | 7 +-
.../rest/codec/param/TestQueryProcessor.java | 5 +-
.../codec/param/TestRestClientRequestImpl.java | 3 +-
.../rest/definition/TestRestOperationMeta.java | 16 +-
.../common/rest/filter/TestHttpServerFilter.java | 17 +-
...HttpServerFilterBeforeSendResponseExecutor.java | 13 +-
.../common/rest/locator/TestMicroservicePaths.java | 13 +-
.../apache/servicecomb/core/TestInvocation.java | 3 +-
.../org/apache/servicecomb/core/TestSCBEngine.java | 142 --------
.../servicecomb/demo/crossapp/CrossAppIT.java | 4 +-
.../servicecomb/demo/edge/consumer/EdgeDemoIT.java | 4 +-
.../demo/filter/retry/FilterClientIT.java | 4 +-
.../org/apache/servicecomb/demo/jaxrs/JaxrsIT.java | 4 +-
.../demo/localRegistryClient/LocalRegistryIT.java | 4 +-
.../demo/registry/MultiRegistriesIT.java | 4 +-
.../MultiServiceCenterIT.java | 4 +-
.../org/apache/servicecomb/demo/pojo/PojoIT.java | 4 +-
.../demo/prefix/RegisterUrlPrefixIT.java | 4 +-
.../springboot/jaxrs/SpringBootJaxrsIT.java | 4 +-
.../springboot/pojo/client/PojoClientIT.java | 4 +-
.../springmvc/client/SpringmvcClientIT.java | 4 +-
.../servicecomb/demo/springmvc/SpringMvcIT.java | 4 +-
.../zeroconfig/tests/ZeroConfigRegistryIT.java | 5 +-
dependencies/default/pom.xml | 4 +-
.../edge/core/TestCompatiblePathVersionMapper.java | 42 +--
.../foundation/common/event/TestEventBus.java | 12 +-
.../common/http/TestHttpStatusUtils.java | 14 +-
.../foundation/common/http/TestHttpUtils.java | 25 +-
.../foundation/common/part/TestAbstractPart.java | 47 +--
.../common/utils/TestLambdaMetafactoryUtils.java | 5 +-
.../apache/servicecomb/config/TestConfigUtil.java | 76 +++--
.../config/inject/TestPlaceholderResolver.java | 22 +-
.../foundation/metrics/TestMetricsBootstrap.java | 7 +-
.../meter/TestLatencyDistributionConfig.java | 23 +-
.../meter/TestLatencyDistributionMeter.java | 4 -
.../spectator/TestMeasurementGroupConfig.java | 19 +-
.../publish/spectator/TestMeasurementNode.java | 3 +-
.../publish/spectator/TestMeasurementTree.java | 18 +-
.../metrics/publish/spectator/TestTagFinder.java | 20 +-
.../protobuf/internal/TestSchemaBase.java | 5 -
.../protobuf/internal/schema/TestAnySchema.java | 9 +-
.../internal/schema/TestMessageSchema.java | 3 +-
.../internal/schema/scalar/TestBoolSchema.java | 15 +-
.../internal/schema/scalar/TestBytesSchema.java | 18 +-
.../internal/schema/scalar/TestEnumSchema.java | 45 ++-
.../schema/scalar/TestNumberBaseSchema.java | 48 +--
.../internal/schema/scalar/TestStringSchema.java | 16 +-
.../TestAbstractTransportDiscoveryFilter.java | 12 +-
.../registry/discovery/TestDiscoveryTree.java | 24 +-
.../servicecomb/registry/version/TestVersion.java | 92 +++---
.../registry/version/TestVersionRuleUtils.java | 24 +-
.../common/utils/TestSPIServiceUtils.java | 19 +-
.../foundation/ssl/TestSSLOptionFactory.java | 12 +-
.../vertx/TestAddressResolverConfig.java | 13 +-
.../vertx/client/TestClientPoolManager.java | 3 +-
.../vertx/client/tcp/TestNetClientWrapper.java | 3 +-
.../client/tcp/TestTcpClientConnectionPool.java | 5 +-
.../vertx/http/TestAbstractHttpServletRequest.java | 362 +++++++++------------
.../http/TestAbstractHttpServletResponse.java | 225 ++++++-------
.../foundation/vertx/http/TestReadStreamPart.java | 36 +-
.../http/TestStandardHttpServletRequestEx.java | 9 +-
.../http/TestStandardHttpServletResponseEx.java | 13 +-
...TestVertxClientRequestToHttpServletRequest.java | 9 +-
...stVertxClientResponseToHttpServletResponse.java | 5 +-
...TestVertxServerRequestToHttpServletRequest.java | 15 +-
...stVertxServerResponseToHttpServletResponse.java | 43 +--
.../foundation/vertx/stream/TestPumpFromPart.java | 5 +-
.../qps/TestConsumerQpsFlowControlHandler.java | 5 -
.../qps/TestProviderQpsFlowControlHandler.java | 16 +-
.../loadbalance/TestLoadbalanceHandler.java | 15 -
.../filter/IsolationDiscoveryFilterTest.java | 21 +-
.../tracing/zipkin/ZipkinTracingHandlerTest.java | 4 +-
.../inspector/internal/TestInspectorImpl.java | 5 +-
.../servicecomb/it/schema/TestApiOperation.java | 21 +-
.../servicecomb/it/testcase/TestAsyncInvoke.java | 5 +-
.../it/testcase/TestRestVertxTransportConfig.java | 3 +-
.../apache/servicecomb/it/testcase/TestUpload.java | 84 ++---
.../servicecomb/it/testcase/base/TestGeneric.java | 18 +-
.../thirdparty/Test3rdPartyInvocation.java | 7 +-
.../demo/jaxrs/tests/JaxrsIntegrationTestBase.java | 20 +-
.../demo/pojo/test/PojoIntegrationTestBase.java | 84 ++---
.../tests/SpringMvcIntegrationTestBase.java | 130 ++++----
.../servicecomb/tests/tracing/TracingTestBase.java | 7 +-
.../tracing/ZipkinTracingIntegrationTest.java | 8 +-
.../metrics/core/TestHealthBootListener.java | 9 +-
.../metrics/core/TestMetricsBootListener.java | 10 +-
.../core/TestThreadPoolMetersInitializer.java | 4 +-
.../model/invocation/TestOperationPerfGroup.java | 3 +-
.../prometheus/TestPrometheusPublisher.java | 30 +-
.../provider/pojo/TestPojoConsumerProvider.java | 4 +-
.../pojo/reference/PojoReferenceMetaTest.java | 5 +-
.../common/TestInvocationToHttpServletRequest.java | 9 +-
.../ServiceCombRestTemplateConfigTest.java | 4 +-
.../reference/TestCommonToHttpServletRequest.java | 9 +-
.../reference/TestRestTemplateBuilder.java | 8 +-
.../TestRestTemplateCopyHeaderFilter.java | 3 +-
.../reference/TestRestTemplateWrapper.java | 97 +++---
.../serviceregistry/MockMicroserviceVersions.java | 3 +-
.../servicecomb/serviceregistry/TestConsumers.java | 7 +-
.../api/registry/TestMicroserviceFactory.java | 14 +-
.../client/LocalServiceRegistryClientImplTest.java | 29 +-
.../client/http/TestServiceRegistryClientImpl.java | 3 +-
.../registry/TestRemoteServiceRegistry.java | 11 -
.../serviceregistry/swagger/TestSwaggerLoader.java | 87 +++--
.../servicecomb/swagger/TestSwaggerUtils.java | 32 +-
.../property/creator/TestPartPropertyCreator.java | 6 +-
.../swagger/generator/core/TestApiOperation.java | 4 +-
.../generator/core/TestOperationGenerator.java | 12 +-
.../generator/core/TestSwaggerGenerator.java | 4 +-
.../swagger/generator/core/TestSwaggerUtils.java | 19 +-
.../core/model/TestSwaggerOperations.java | 13 +-
.../annotation/ApiOperationProcessorTest.java | 15 +-
.../processor/annotation/ApiProcessorTest.java | 23 +-
.../annotation/SwaggerDefinitionProcessorTest.java | 11 +-
.../RequestPartAnnotationProcessorTest.java | 39 +--
.../creator/MultipartFilePropertyCreatorTest.java | 7 +-
.../swagger/engine/TestSwaggerEnvironment.java | 8 +-
.../part/PartListToPartArrayConverterTest.java | 3 +-
.../impl/part/TestBytesToPartConverter.java | 3 +-
.../impl/part/TestFileToPartConverter.java | 3 +-
.../impl/part/TestInputStreamToPartConverter.java | 3 +-
.../impl/part/TestResourceToPartConverter.java | 3 +-
.../response/TestJaxrsConsumerResponseMapper.java | 3 +-
.../response/TestJaxrsProducerResponseMapper.java | 3 +-
.../TestJaxrsProducerResponseMapperFactory.java | 3 +-
.../converter/TestPartToMultipartFile.java | 14 +-
.../TestSpringmvcConsumerResponseMapper.java | 5 +-
.../TestSpringmvcProducerResponseMapper.java | 5 +-
...TestSpringmvcProducerResponseMapperFactory.java | 5 +-
.../TestDefaultParameterNameProvider.java | 14 +-
.../tracing/zipkin/ZipkinSpanAspectTest.java | 15 +-
.../tracing/zipkin/ZipkinTracingAdviserTest.java | 26 +-
.../transport/highway/message/TestHeaders.java | 11 +-
.../rest/client/http/TestRestClientInvocation.java | 13 +-
.../servlet/TestCseXmlWebApplicationContext.java | 13 +-
.../transport/rest/servlet/TestServletUtils.java | 13 +-
.../rest/vertx/TestRestServerVerticle.java | 6 +-
.../transport/rest/vertx/TestTransportConfig.java | 25 +-
.../rest/vertx/TestVertxRestDispatcher.java | 27 +-
148 files changed, 1299 insertions(+), 1787 deletions(-)
diff --git a/clients/config-center-client/pom.xml b/clients/config-center-client/pom.xml
index 51ebd26a5..a6c6c8a9c 100644
--- a/clients/config-center-client/pom.xml
+++ b/clients/config-center-client/pom.xml
@@ -41,17 +41,5 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>config-clients-common</artifactId>
</dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/clients/http-client-common/pom.xml b/clients/http-client-common/pom.xml
index 9f51d0455..4d3c61817 100644
--- a/clients/http-client-common/pom.xml
+++ b/clients/http-client-common/pom.xml
@@ -71,17 +71,5 @@
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
</dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/clients/service-center-client/pom.xml b/clients/service-center-client/pom.xml
index c85819976..bf987c61a 100755
--- a/clients/service-center-client/pom.xml
+++ b/clients/service-center-client/pom.xml
@@ -37,17 +37,6 @@
<artifactId>http-client-common</artifactId>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
diff --git a/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/InvocationContextItemTest.java b/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/InvocationContextItemTest.java
index 27b44497c..efd6f595b 100644
--- a/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/InvocationContextItemTest.java
+++ b/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/InvocationContextItemTest.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.event.ServerAccessLogEvent;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -71,7 +72,7 @@ public class InvocationContextItemTest {
when(invocation.getContext(INVOCATION_CONTEXT_KEY)).thenReturn(INVOCATION_CONTEXT_VALUE);
ITEM.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(INVOCATION_CONTEXT_VALUE));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(INVOCATION_CONTEXT_VALUE));
}
@Test
@@ -82,7 +83,7 @@ public class InvocationContextItemTest {
context.put(INVOCATION_CONTEXT_KEY, INVOCATION_CONTEXT_VALUE);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(INVOCATION_CONTEXT_VALUE));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(INVOCATION_CONTEXT_VALUE));
}
@Test
@@ -94,7 +95,7 @@ public class InvocationContextItemTest {
when(invocation.getContext(INVOCATION_CONTEXT_KEY)).thenReturn(null);
ITEM.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
@@ -105,7 +106,7 @@ public class InvocationContextItemTest {
context.put(INVOCATION_CONTEXT_KEY, null);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
@@ -114,7 +115,7 @@ public class InvocationContextItemTest {
when(routingContext.data()).thenReturn(routingContextData);
ITEM.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
@@ -124,14 +125,14 @@ public class InvocationContextItemTest {
when(invocation.getContext()).thenReturn(context);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
public void testGetFormattedItemOnRoutingContextDataNotFound() {
when(routingContext.data()).thenReturn(null);
ITEM.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
@@ -139,13 +140,13 @@ public class InvocationContextItemTest {
when(finishEvent.getInvocation()).thenReturn(invocation);
when(invocation.getContext()).thenReturn(null);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
@Test
public void clientGetFormattedItemOnInvocationNotFound() {
when(finishEvent.getInvocation()).thenReturn(null);
ITEM.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
+ MatcherAssert.assertThat(strBuilder.toString(), Matchers.is(InvocationContextAccessItem.NOT_FOUND));
}
}
\ No newline at end of file
diff --git a/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/TraceIdItemTest.java b/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/TraceIdItemTest.java
index 96cb04ac8..325e257da 100644
--- a/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/TraceIdItemTest.java
+++ b/common/common-access-log/src/test/java/org/apache/servicecomb/common/accessLog/core/element/impl/TraceIdItemTest.java
@@ -28,7 +28,7 @@ import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.event.ServerAccessLogEvent;
-import org.junit.Assert;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -75,7 +75,7 @@ public class TraceIdItemTest {
data.put(RestConst.REST_INVOCATION_CONTEXT, invocation);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is(traceIdTest));
+ MatcherAssert.assertThat(strBuilder.toString(), is(traceIdTest));
}
@Test
@@ -86,7 +86,7 @@ public class TraceIdItemTest {
when(invocation.getContext()).thenReturn(clientContext);
ELEMENT.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is(traceIdTest));
+ MatcherAssert.assertThat(strBuilder.toString(), is(traceIdTest));
}
@Test
@@ -100,7 +100,7 @@ public class TraceIdItemTest {
when(serverRequest.getHeader(Const.TRACE_ID_NAME)).thenReturn(traceIdTest);
when(routingContext.request()).thenReturn(serverRequest);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is(traceIdTest));
+ MatcherAssert.assertThat(strBuilder.toString(), is(traceIdTest));
}
@Test
@@ -113,12 +113,12 @@ public class TraceIdItemTest {
when(serverRequest.getHeader(Const.TRACE_ID_NAME)).thenReturn(null);
when(routingContext.request()).thenReturn(serverRequest);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
strBuilder = new StringBuilder();
when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(null);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
}
@Test
@@ -128,7 +128,7 @@ public class TraceIdItemTest {
when(invocation.getContext()).thenReturn(clientContext);
ELEMENT.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
}
@Test
@@ -137,7 +137,7 @@ public class TraceIdItemTest {
when(routingContext.request()).thenReturn(serverRequest);
when(serverRequest.getHeader(Const.TRACE_ID_NAME)).thenReturn(null);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
}
@Test
@@ -146,7 +146,7 @@ public class TraceIdItemTest {
when(invocation.getContext()).thenReturn(null);
ELEMENT.appendClientFormattedItem(finishEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
}
@Test
@@ -155,6 +155,6 @@ public class TraceIdItemTest {
when(routingContext.request()).thenReturn(serverRequest);
when(routingContext.data()).thenReturn(null);
ELEMENT.appendServerFormattedItem(accessLogEvent, strBuilder);
- Assert.assertThat(strBuilder.toString(), is("-"));
+ MatcherAssert.assertThat(strBuilder.toString(), is("-"));
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
index 0cb92a87e..b53724b09 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -72,13 +72,13 @@ import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.context.HttpStatus;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import com.google.common.eventbus.Subscribe;
@@ -107,9 +107,6 @@ public class TestAbstractRestInvocation {
Invocation invocation;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
static SCBEngine scbEngine;
static OperationMeta operationMeta;
@@ -202,12 +199,9 @@ public class TestAbstractRestInvocation {
};
initRestInvocation();
- expectedException.expect(InvocationException.class);
- expectedException
- .expectMessage(
- "InvocationException: code=406;msg=CommonExceptionData [message=Accept notExistType is not supported]");
-
- restInvocation.initProduceProcessor();
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> restInvocation.initProduceProcessor());
+ Assertions.assertEquals("InvocationException: code=406;msg=CommonExceptionData [message=Accept notExistType is not supported]", exception.getMessage());
}
@Test
@@ -262,8 +256,8 @@ public class TestAbstractRestInvocation {
};
restInvocation.setContext();
- Assert.assertThat(invocation.getContext().size(), Matchers.is(1));
- Assert.assertThat(invocation.getContext(), Matchers.hasEntry("name", "value"));
+ MatcherAssert.assertThat(invocation.getContext().size(), Matchers.is(1));
+ MatcherAssert.assertThat(invocation.getContext(), Matchers.hasEntry("name", "value"));
}
@Test
@@ -278,8 +272,8 @@ public class TestAbstractRestInvocation {
invocation.addContext("X-B3-traceId", "value1");
//if request has no traceId, use invocation's traceId
restInvocation.setContext();
- Assert.assertThat(invocation.getContext().size(), Matchers.is(1));
- Assert.assertThat(invocation.getContext(), Matchers.hasEntry("X-B3-traceId", "value1"));
+ MatcherAssert.assertThat(invocation.getContext().size(), Matchers.is(1));
+ MatcherAssert.assertThat(invocation.getContext(), Matchers.hasEntry("X-B3-traceId", "value1"));
context.put("X-B3-traceId", "value2");
new Expectations() {
@@ -290,8 +284,8 @@ public class TestAbstractRestInvocation {
};
//if request has traceId, use request's traceId
restInvocation.setContext();
- Assert.assertThat(invocation.getContext().size(), Matchers.is(1));
- Assert.assertThat(invocation.getContext(), Matchers.hasEntry("X-B3-traceId", "value2"));
+ MatcherAssert.assertThat(invocation.getContext().size(), Matchers.is(1));
+ MatcherAssert.assertThat(invocation.getContext(), Matchers.hasEntry("X-B3-traceId", "value2"));
}
@Test
@@ -818,16 +812,15 @@ public class TestAbstractRestInvocation {
public void findRestOperationServicePathManagerNull(@Mocked MicroserviceMeta microserviceMeta) {
new Expectations(ServicePathManager.class) {
{
- requestEx.getHeader(Const.TARGET_MICROSERVICE);
- result = "ms";
ServicePathManager.getServicePathManager(microserviceMeta);
result = null;
}
};
- expectedException.expect(InvocationException.class);
- expectedException.expectMessage("CommonExceptionData [message=Not Found]");
- restInvocation.findRestOperation(microserviceMeta);
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> restInvocation.findRestOperation(microserviceMeta));
+ Assertions.assertEquals("InvocationException: code=404;msg=CommonExceptionData [message=Not Found]",
+ exception.getMessage());
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
index d1d3e0725..f4a874b54 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
@@ -28,18 +28,14 @@ import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestRestEngineSchemaListener {
static SCBEngine scbEngine;
static ServicePathManager spm;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@BeforeClass
public static void setup() {
ConfigUtil.installDynamicConfig();
@@ -57,36 +53,30 @@ public class TestRestEngineSchemaListener {
@Test
public void testLocateNotFound() {
- expectedException.expect(InvocationException.class);
- expectedException.expectMessage("InvocationException: code=404;msg=CommonExceptionData [message=Not Found]");
-
- spm.producerLocateOperation("/notExist", "GET");
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> spm.producerLocateOperation("/notExist", "GET"));
+ Assertions.assertEquals("InvocationException: code=404;msg=CommonExceptionData [message=Not Found]", exception.getMessage());
}
@Test
public void testLocateNotFoundDynamicRemained() {
- expectedException.expect(InvocationException.class);
- expectedException.expectMessage("InvocationException: code=404;msg=CommonExceptionData [message=Not Found]");
-
- spm.producerLocateOperation("/dynamic/1/2", "GET");
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> spm.producerLocateOperation("/dynamic/1/2", "GET"));
+ Assertions.assertEquals("InvocationException: code=404;msg=CommonExceptionData [message=Not Found]", exception.getMessage());
}
@Test
public void testLocateStaticMethodNotAllowed() {
- expectedException.expect(InvocationException.class);
- expectedException
- .expectMessage("InvocationException: code=405;msg=CommonExceptionData [message=Method Not Allowed]");
-
- spm.producerLocateOperation("/staticEx", "POST");
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> spm.producerLocateOperation("/staticEx", "POST"));
+ Assertions.assertEquals("InvocationException: code=405;msg=CommonExceptionData [message=Method Not Allowed]", exception.getMessage());
}
@Test
public void testLocateDynamicMethodNotAllowed() {
- expectedException.expect(InvocationException.class);
- expectedException
- .expectMessage("InvocationException: code=405;msg=CommonExceptionData [message=Method Not Allowed]");
-
- spm.producerLocateOperation("/dynamic/1", "POST");
+ InvocationException exception = Assertions.assertThrows(InvocationException.class,
+ () -> spm.producerLocateOperation("/dynamic/1", "POST"));
+ Assertions.assertEquals("InvocationException: code=405;msg=CommonExceptionData [message=Method Not Allowed]", exception.getMessage());
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
index b0d6eeb23..d69f1719f 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestProducerInvocation.java
@@ -43,9 +43,8 @@ import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import mockit.Expectations;
import mockit.Mock;
@@ -78,9 +77,6 @@ public class TestRestProducerInvocation {
static MicroserviceMeta microserviceMeta;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@BeforeClass
public static void classSetup() {
ConfigUtil.installDynamicConfig();
@@ -167,9 +163,9 @@ public class TestRestProducerInvocation {
restProducerInvocation = new RestProducerInvocation();
initRestProducerInvocation();
- expectedException.expect(Exception.class);
- expectedException.expectMessage("[message=Not Found]");
- restProducerInvocation.findRestOperation();
+ Exception exception = Assertions.assertThrows(Exception.class,
+ () -> restProducerInvocation.findRestOperation());
+ Assertions.assertTrue(exception.getMessage().contains("[message=Not Found]"));
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
index 6711e3fd2..5e33af9e8 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestFormProcessor.java
@@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.param.FormProcessorCreator.FormProcessor;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -168,7 +169,7 @@ public class TestFormProcessor {
ParamValueProcessor processor = createProcessor("name", String[].class);
String[] value = (String[]) processor.getValue(request);
- Assert.assertThat(value, Matchers.arrayContaining("value"));
+ MatcherAssert.assertThat(value, Matchers.arrayContaining("value"));
}
@SuppressWarnings("unchecked")
@@ -185,7 +186,7 @@ public class TestFormProcessor {
TypeFactory.defaultInstance().constructCollectionType(List.class, String.class),
null, true);
Object value = processor.getValue(request);
- Assert.assertThat((List<String>) value, Matchers.contains("value"));
+ MatcherAssert.assertThat((List<String>) value, Matchers.contains("value"));
}
@SuppressWarnings("unchecked")
@@ -202,7 +203,7 @@ public class TestFormProcessor {
TypeFactory.defaultInstance().constructCollectionType(Set.class, String.class), null,
true);
Object value = processor.getValue(request);
- Assert.assertThat((Set<String>) value, Matchers.contains("value"));
+ MatcherAssert.assertThat((Set<String>) value, Matchers.contains("value"));
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
index 866bb9ad6..a29459aab 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestHeaderProcessor.java
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.servicecomb.common.rest.codec.RestClientRequest;
import org.apache.servicecomb.common.rest.codec.param.HeaderProcessorCreator.HeaderProcessor;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -168,7 +169,7 @@ public class TestHeaderProcessor {
HeaderProcessor processor = createProcessor("h1", String[].class);
String[] value = (String[]) processor.getValue(request);
- Assert.assertThat(value, Matchers.arrayContaining("h1v"));
+ MatcherAssert.assertThat(value, Matchers.arrayContaining("h1v"));
}
@SuppressWarnings("unchecked")
@@ -185,7 +186,7 @@ public class TestHeaderProcessor {
TypeFactory.defaultInstance().constructCollectionType(List.class, String.class),
null, true);
Object value = processor.getValue(request);
- Assert.assertThat((List<String>) value, Matchers.contains("h1v"));
+ MatcherAssert.assertThat((List<String>) value, Matchers.contains("h1v"));
}
@SuppressWarnings("unchecked")
@@ -202,7 +203,7 @@ public class TestHeaderProcessor {
TypeFactory.defaultInstance().constructCollectionType(Set.class, String.class),
null, true);
Object value = processor.getValue(request);
- Assert.assertThat((Set<String>) value, Matchers.contains("h1v"));
+ MatcherAssert.assertThat((Set<String>) value, Matchers.contains("h1v"));
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
index e70a9172f..824400dcc 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestQueryProcessor.java
@@ -20,6 +20,7 @@ package org.apache.servicecomb.common.rest.codec.param;
import javax.servlet.http.HttpServletRequest;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -81,7 +82,7 @@ public class TestQueryProcessor {
ParamValueProcessor processor = createProcessor("name", String[].class, "multi");
String[] value = (String[]) processor.getValue(request);
- Assert.assertThat(value, Matchers.arrayContaining("value", "value2"));
+ MatcherAssert.assertThat(value, Matchers.arrayContaining("value", "value2"));
}
@Test
@@ -95,7 +96,7 @@ public class TestQueryProcessor {
ParamValueProcessor processor = createProcessor("name", String[].class, "csv");
String[] value = (String[]) processor.getValue(request);
- Assert.assertThat(value, Matchers.arrayContaining("value2", "value3"));
+ MatcherAssert.assertThat(value, Matchers.arrayContaining("value2", "value3"));
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
index f0baacb60..05addcd7c 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
@@ -25,6 +25,7 @@ import javax.servlet.http.Part;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -137,7 +138,7 @@ public class TestRestClientRequestImpl {
Multimap<String, Part> uploads = Deencapsulation.getField(restClientRequest, "uploads");
Assert.assertEquals(1, uploads.size());
- Assert.assertThat(uploads.asMap(), Matchers.hasEntry(fileName, Arrays.asList(part)));
+ MatcherAssert.assertThat(uploads.asMap(), Matchers.hasEntry(fileName, Arrays.asList(part)));
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
index 036bd60f9..e7022bf92 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
@@ -18,7 +18,6 @@
package org.apache.servicecomb.common.rest.definition;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.Arrays;
@@ -37,6 +36,7 @@ import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -375,7 +375,7 @@ public class TestRestOperationMeta {
public void generatesAbsolutePathWithRootBasePath() {
findOperation("textCharJsonChar");
- assertThat(operationMeta.getAbsolutePath(), is("/textCharJsonChar/"));
+ MatcherAssert.assertThat(operationMeta.getAbsolutePath(), is("/textCharJsonChar/"));
}
@Test
@@ -390,7 +390,7 @@ public class TestRestOperationMeta {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta.getOperationMeta());
- assertThat(restOperationMeta.getAbsolutePath(), is("/rest/textCharJsonChar/"));
+ MatcherAssert.assertThat(restOperationMeta.getAbsolutePath(), is("/rest/textCharJsonChar/"));
}
@Test
@@ -411,7 +411,7 @@ public class TestRestOperationMeta {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta.getOperationMeta());
- assertThat(restOperationMeta.getAbsolutePath(), is("/"));
+ MatcherAssert.assertThat(restOperationMeta.getAbsolutePath(), is("/"));
}
@Test
@@ -432,7 +432,7 @@ public class TestRestOperationMeta {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta.getOperationMeta());
- assertThat(restOperationMeta.getAbsolutePath(), is("/"));
+ MatcherAssert.assertThat(restOperationMeta.getAbsolutePath(), is("/"));
}
@Test
@@ -453,20 +453,20 @@ public class TestRestOperationMeta {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta.getOperationMeta());
- assertThat(restOperationMeta.getAbsolutePath(), is("/rest/sayHi/"));
+ MatcherAssert.assertThat(restOperationMeta.getAbsolutePath(), is("/rest/sayHi/"));
}
@Test
public void testFormDataFlagTrue() {
findOperation("form");
- assertThat(operationMeta.isFormData(), is(true));
+ MatcherAssert.assertThat(operationMeta.isFormData(), is(true));
}
@Test
public void testFormDataFlagFalse() {
findOperation("json");
- assertThat(operationMeta.isFormData(), is(false));
+ MatcherAssert.assertThat(operationMeta.isFormData(), is(false));
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java
index 1ea467d4c..34e790ff9 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilter.java
@@ -22,15 +22,11 @@ import java.util.concurrent.ExecutionException;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestHttpServerFilter {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void asyncSucc() throws InterruptedException, ExecutionException {
@@ -49,10 +45,11 @@ public class TestHttpServerFilter {
}
};
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.instanceOf(RuntimeExceptionWithoutStackTrace.class));
-
- CompletableFuture<Void> future = filter.beforeSendResponseAsync(null, null);
- future.get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class,
+ () -> {
+ CompletableFuture<Void> future = filter.beforeSendResponseAsync(null, null);
+ future.get();
+ });
+ Assertions.assertTrue(exception.getCause() instanceof RuntimeExceptionWithoutStackTrace);
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java
index c8754ac1a..0d59a3b1f 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/TestHttpServerFilterBeforeSendResponseExecutor.java
@@ -24,12 +24,10 @@ import java.util.concurrent.ExecutionException;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
-import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import mockit.Mocked;
@@ -45,9 +43,6 @@ public class TestHttpServerFilterBeforeSendResponseExecutor {
HttpServerFilterBeforeSendResponseExecutor executor =
new HttpServerFilterBeforeSendResponseExecutor(httpServerFilters, invocation, responseEx);
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setup() {
httpServerFilters.add(new HttpServerFilterBaseForTest());
@@ -71,9 +66,7 @@ public class TestHttpServerFilterBeforeSendResponseExecutor {
CompletableFuture<Void> result = executor.run();
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.instanceOf(RuntimeExceptionWithoutStackTrace.class));
-
- result.get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, result::get);
+ Assertions.assertTrue(exception.getCause() instanceof RuntimeExceptionWithoutStackTrace);
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
index f8921a664..6841a1725 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
@@ -27,9 +27,8 @@ import org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import mockit.Deencapsulation;
import mockit.Expectations;
@@ -40,9 +39,6 @@ public class TestMicroservicePaths {
static MicroservicePaths paths;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@BeforeClass
public static void setup() {
ConfigUtil.installDynamicConfig();
@@ -82,10 +78,9 @@ public class TestMicroservicePaths {
}
};
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage("operation with url /static/, method POST is duplicated.");
-
- paths.addResource(staticResPost);
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> paths.addResource(staticResPost));
+ Assertions.assertEquals("operation with url /static/, method POST is duplicated.", exception.getMessage());
}
@Test
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
index 6bda0e039..34b03301c 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
@@ -34,6 +34,7 @@ import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.swagger.invocation.Response;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -251,7 +252,7 @@ public class TestInvocation {
}
};
- Assert.assertThat(Invocation.loadTraceIdGenerators(), Matchers.contains(gen1, gen3));
+ MatcherAssert.assertThat(Invocation.loadTraceIdGenerators(), Matchers.contains(gen1, gen3));
}
InvocationBaseEvent invocationBaseEvent;
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
deleted file mode 100644
index b1e965b19..000000000
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core;
-
-public class TestSCBEngine {
-// @Rule
-// public ExpectedException expectedException = ExpectedException.none();
-//
-// @Test
-// public void test(@Injectable ProducerProviderManager producerProviderManager,
-// @Injectable ConsumerProviderManager consumerProviderManager,
-// @Injectable TransportManager transportManager,
-// @Injectable AppManager appManager) {
-// new Expectations(RegistryUtils.class) {
-// {
-// RegistryUtils.getServiceRegistry().getAppManager();
-// RegistryUtils.getInstanceCacheManager();
-// RegistryUtils.run();
-// RegistryUtils.destroy();
-// }
-// };
-// AtomicBoolean configDestroy = new AtomicBoolean();
-// new MockUp<ConfigUtil>() {
-// @Mock
-// void destroyConfigCenterConfigurationSource() {
-// configDestroy.set(true);
-// }
-// };
-//
-// SchemaListenerManager schemaListenerManager = Mockito.mock(SchemaListenerManager.class);
-//
-// VertxUtils.getOrCreateVertxByName("transport", null);
-//
-// SCBEngine engine = new SCBEngine();
-// engine.setBootListenerList(new ArrayList<>());
-// engine.setConsumerProviderManager(consumerProviderManager);
-// engine.setProducerProviderManager(producerProviderManager);
-// engine.setTransportManager(transportManager);
-// engine.setSchemaListenerManager(schemaListenerManager);
-//
-// ArchaiusUtils.setProperty(SCBEngine.CFG_KEY_WAIT_UP_TIMEOUT, 0);
-// engine.init();
-// ArchaiusUtils.updateProperty(SCBEngine.CFG_KEY_WAIT_UP_TIMEOUT, null);
-//
-// Assert.assertEquals(SCBStatus.STARTING, engine.getStatus());
-//
-// engine.destroy();
-//
-// Assert.assertEquals(SCBStatus.DOWN, engine.getStatus());
-// Assert.assertTrue(configDestroy.get());
-// }
-//
-// @Test
-// public void createReferenceConfigForInvoke_up(@Mocked ConsumerProviderManager consumerProviderManager) {
-// SCBEngine engine = new SCBEngine();
-// engine.setStatus(SCBStatus.UP);
-// engine.setConsumerProviderManager(consumerProviderManager);
-//
-// ReferenceConfig referenceConfig = engine.createReferenceConfigForInvoke(null, null, null);
-// Assert.assertTrue(ReferenceConfig.class.isInstance(referenceConfig));
-// }
-//
-// @Test
-// public void createReferenceConfigForInvoke_down(@Mocked ConsumerProviderManager consumerProviderManager) {
-// SCBEngine engine = new SCBEngine();
-// engine.setStatus(SCBStatus.DOWN);
-// engine.setConsumerProviderManager(consumerProviderManager);
-//
-// expectedException.expect(InvocationException.class);
-// expectedException.expectMessage(
-// Matchers
-// .is("InvocationException: code=503;msg=CommonExceptionData [message=The request is rejected. Cannot process the request due to STATUS = DOWN]"));
-// engine.createReferenceConfigForInvoke(null, null, null);
-// }
-//
-// @Test
-// public void getReferenceConfigForInvoke_up(@Mocked ConsumerProviderManager consumerProviderManager) {
-// SCBEngine engine = new SCBEngine();
-// engine.setStatus(SCBStatus.UP);
-// engine.setConsumerProviderManager(consumerProviderManager);
-//
-// ReferenceConfig referenceConfig = engine.getReferenceConfigForInvoke(null);
-// Assert.assertTrue(ReferenceConfig.class.isInstance(referenceConfig));
-// }
-//
-// @Test
-// public void getReferenceConfigForInvoke_down(@Mocked ConsumerProviderManager consumerProviderManager) {
-// SCBEngine engine = new SCBEngine();
-// engine.setStatus(SCBStatus.DOWN);
-// engine.setConsumerProviderManager(consumerProviderManager);
-//
-// expectedException.expect(InvocationException.class);
-// expectedException.expectMessage(
-// Matchers
-// .is("InvocationException: code=503;msg=CommonExceptionData [message=The request is rejected. Cannot process the request due to STATUS = DOWN]"));
-// engine.getReferenceConfigForInvoke(null);
-// }
-//
-// @Test
-// public void setBootListenerList(@Mocked BootListener beanListener, @Mocked BootListener spiListener) {
-// new Expectations(SPIServiceUtils.class) {
-// {
-// beanListener.getOrder();
-// result = 1;
-// spiListener.getOrder();
-// result = 0;
-// SPIServiceUtils.getOrLoadSortedService(BootListener.class);
-// result = Arrays.asList(spiListener);
-// }
-// };
-//
-// SCBEngine engine = new SCBEngine();
-// engine.setBootListenerList(Arrays.asList(beanListener));
-//
-// Assert.assertThat(engine.getBootListeners(), Matchers.contains(spiListener, beanListener));
-// }
-//
-// @Test
-// public void bootEvent_refEngine() {
-// Holder<SCBEngine> eventEngine = new Holder<>();
-// SCBEngine engine = new SCBEngine();
-// engine.setBootListenerList(Arrays.asList(event -> eventEngine.value = event.getScbEngine()));
-// engine.triggerEvent(EventType.AFTER_REGISTRY);
-//
-// Assert.assertNotNull(eventEngine.value);
-// }
-}
diff --git a/demo/demo-crossapp/crossapp-client/src/test/java/org/apache/servicecomb/demo/crossapp/CrossAppIT.java b/demo/demo-crossapp/crossapp-client/src/test/java/org/apache/servicecomb/demo/crossapp/CrossAppIT.java
index 71c7af1d3..a4cf3d4b8 100644
--- a/demo/demo-crossapp/crossapp-client/src/test/java/org/apache/servicecomb/demo/crossapp/CrossAppIT.java
+++ b/demo/demo-crossapp/crossapp-client/src/test/java/org/apache/servicecomb/demo/crossapp/CrossAppIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.crossapp;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -35,6 +35,6 @@ public class CrossAppIT {
public void clientGetsNoError() throws Exception {
CrossappClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-edge/consumer/src/test/java/org/apache/servicecomb/demo/edge/consumer/EdgeDemoIT.java b/demo/demo-edge/consumer/src/test/java/org/apache/servicecomb/demo/edge/consumer/EdgeDemoIT.java
index f5f161f1d..ee11e0ab0 100644
--- a/demo/demo-edge/consumer/src/test/java/org/apache/servicecomb/demo/edge/consumer/EdgeDemoIT.java
+++ b/demo/demo-edge/consumer/src/test/java/org/apache/servicecomb/demo/edge/consumer/EdgeDemoIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.edge.consumer;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -34,6 +34,6 @@ public class EdgeDemoIT {
public void clientGetsNoError() throws Exception {
ConsumerMain.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-filter/filter-client/src/test/java/org/apache/servicecomb/demo/filter/retry/FilterClientIT.java b/demo/demo-filter/filter-client/src/test/java/org/apache/servicecomb/demo/filter/retry/FilterClientIT.java
index b652919b0..cbdb70a80 100644
--- a/demo/demo-filter/filter-client/src/test/java/org/apache/servicecomb/demo/filter/retry/FilterClientIT.java
+++ b/demo/demo-filter/filter-client/src/test/java/org/apache/servicecomb/demo/filter/retry/FilterClientIT.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.demo.filter.retry;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.filter.FilterClient;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +36,6 @@ public class FilterClientIT {
public void clientGetsNoError() throws Exception {
FilterClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-jaxrs/jaxrs-client/src/test/java/org/apache/servicecomb/demo/jaxrs/JaxrsIT.java b/demo/demo-jaxrs/jaxrs-client/src/test/java/org/apache/servicecomb/demo/jaxrs/JaxrsIT.java
index 4ce87c800..91cf268ce 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/test/java/org/apache/servicecomb/demo/jaxrs/JaxrsIT.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/test/java/org/apache/servicecomb/demo/jaxrs/JaxrsIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.jaxrs;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -35,6 +35,6 @@ public class JaxrsIT {
public void clientGetsNoError() throws Exception {
JaxrsClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-local-registry/demo-local-registry-client/src/test/java/org/apache/servicecomb/demo/localRegistryClient/LocalRegistryIT.java b/demo/demo-local-registry/demo-local-registry-client/src/test/java/org/apache/servicecomb/demo/localRegistryClient/LocalRegistryIT.java
index d8faa9da5..81b247ef8 100644
--- a/demo/demo-local-registry/demo-local-registry-client/src/test/java/org/apache/servicecomb/demo/localRegistryClient/LocalRegistryIT.java
+++ b/demo/demo-local-registry/demo-local-registry-client/src/test/java/org/apache/servicecomb/demo/localRegistryClient/LocalRegistryIT.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.demo.localRegistryClient;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.localRegistryClient.Application;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -35,6 +35,6 @@ public class LocalRegistryIT {
public void clientGetsNoError() throws Exception {
Application.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-multi-registries/demo-multi-registries-client/src/test/java/org/apache/servicecomb/demo/registry/MultiRegistriesIT.java b/demo/demo-multi-registries/demo-multi-registries-client/src/test/java/org/apache/servicecomb/demo/registry/MultiRegistriesIT.java
index e50d92ab3..edf557d66 100644
--- a/demo/demo-multi-registries/demo-multi-registries-client/src/test/java/org/apache/servicecomb/demo/registry/MultiRegistriesIT.java
+++ b/demo/demo-multi-registries/demo-multi-registries-client/src/test/java/org/apache/servicecomb/demo/registry/MultiRegistriesIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.registry;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -34,6 +34,6 @@ public class MultiRegistriesIT {
public void clientGetsNoError() throws Exception {
Application.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java b/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java
index e1c9e8e1f..9155234c7 100644
--- a/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java
+++ b/demo/demo-multi-service-center/demo-multi-service-center-client/src/test/java/org/apache/servicecomb/demo/multiServiceCenterClient/MultiServiceCenterIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.multiServiceCenterClient;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -34,6 +34,6 @@ public class MultiServiceCenterIT {
public void clientGetsNoError() throws Exception {
Application.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-pojo/pojo-client/src/test/java/org/apache/servicecomb/demo/pojo/PojoIT.java b/demo/demo-pojo/pojo-client/src/test/java/org/apache/servicecomb/demo/pojo/PojoIT.java
index 8385ca030..715652df9 100644
--- a/demo/demo-pojo/pojo-client/src/test/java/org/apache/servicecomb/demo/pojo/PojoIT.java
+++ b/demo/demo-pojo/pojo-client/src/test/java/org/apache/servicecomb/demo/pojo/PojoIT.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.demo.pojo;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.pojo.client.PojoClient;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +36,6 @@ public class PojoIT {
public void clientGetsNoError() throws Exception {
PojoClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-register-url-prefix/demo-register-url-prefix-client/src/test/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixIT.java b/demo/demo-register-url-prefix/demo-register-url-prefix-client/src/test/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixIT.java
index 3ec07ca41..b82c03928 100644
--- a/demo/demo-register-url-prefix/demo-register-url-prefix-client/src/test/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixIT.java
+++ b/demo/demo-register-url-prefix/demo-register-url-prefix-client/src/test/java/org/apache/servicecomb/demo/prefix/RegisterUrlPrefixIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.prefix;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -37,6 +37,6 @@ public class RegisterUrlPrefixIT {
Application.runTest();
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/test/java/org/apache/servicecomb/springboot/jaxrs/SpringBootJaxrsIT.java b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/test/java/org/apache/servicecomb/springboot/jaxrs/SpringBootJaxrsIT.java
index 5e9f1f966..638c1c30a 100644
--- a/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/test/java/org/apache/servicecomb/springboot/jaxrs/SpringBootJaxrsIT.java
+++ b/demo/demo-spring-boot-provider/demo-spring-boot-jaxrs-client/src/test/java/org/apache/servicecomb/springboot/jaxrs/SpringBootJaxrsIT.java
@@ -18,11 +18,11 @@
package org.apache.servicecomb.springboot.jaxrs;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.springboot.jaxrs.client.JaxrsClient;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -38,7 +38,7 @@ public class SpringBootJaxrsIT {
try {
JaxrsClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
} catch (Throwable e) {
e.printStackTrace();
fail("test case failed, message=" + e.getMessage());
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/test/java/org/apache/servicecomb/springboot/pojo/client/PojoClientIT.java b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/test/java/org/apache/servicecomb/springboot/pojo/client/PojoClientIT.java
index 77725ac6d..d3ba72539 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/test/java/org/apache/servicecomb/springboot/pojo/client/PojoClientIT.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/test/java/org/apache/servicecomb/springboot/pojo/client/PojoClientIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.springboot.pojo.client;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -36,6 +36,6 @@ public class PojoClientIT {
public void clientGetsNoError() throws Exception {
SpringApplication.run(PojoClient.class);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
index 279d6dafc..93ca1356a 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/test/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClientIT.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.springboot.springmvc.client;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -36,7 +36,7 @@ public class SpringmvcClientIT {
try {
SpringmvcClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
} catch (Throwable e) {
e.printStackTrace();
fail("test case failed, message=" + e.getMessage());
diff --git a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
index e3f0e4ec0..0591a9af3 100644
--- a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
+++ b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java
@@ -18,9 +18,9 @@
package org.apache.servicecomb.demo.springmvc;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -35,6 +35,6 @@ public class SpringMvcIT {
public void clientGetsNoError() throws Exception {
SpringmvcClient.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/tests/ZeroConfigRegistryIT.java b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/tests/ZeroConfigRegistryIT.java
index 7c569caa3..ce07a1116 100644
--- a/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/tests/ZeroConfigRegistryIT.java
+++ b/demo/demo-zeroconfig-schemadiscovery-registry/demo-zeroconfig-schemadiscovery-registry-tests/src/test/java/org/apache/servicecomb/demo/zeroconfig/tests/ZeroConfigRegistryIT.java
@@ -19,10 +19,9 @@
package org.apache.servicecomb.demo.zeroconfig.tests;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.demo.TestMgr;
-import org.apache.servicecomb.demo.zeroconfig.tests.Application;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
@@ -36,6 +35,6 @@ public class ZeroConfigRegistryIT {
public void clientGetsNoError() throws Exception {
Application.main(new String[0]);
- assertThat(TestMgr.errors().isEmpty(), is(true));
+ MatcherAssert.assertThat(TestMgr.errors().isEmpty(), is(true));
}
}
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index f0e6a82b2..6c0ec2ed3 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -71,8 +71,8 @@
<jettison.version>1.4.0</jettison.version>
<jmockit.version>1.30</jmockit.version>
<json-lib.version>2.4</json-lib.version>
- <junit.version>4.12</junit.version>
- <junit5.version>5.6.2</junit5.version>
+ <junit.version>4.13.2</junit.version>
+ <junit5.version>5.8.2</junit5.version>
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.13.2</log4j2.version>
<logback.version>1.2.3</logback.version>
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestCompatiblePathVersionMapper.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestCompatiblePathVersionMapper.java
index 2bfe7b037..44be94f61 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestCompatiblePathVersionMapper.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestCompatiblePathVersionMapper.java
@@ -19,18 +19,13 @@ package org.apache.servicecomb.edge.core;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.registry.version.VersionRule;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestCompatiblePathVersionMapper {
CompatiblePathVersionMapper mapper = new CompatiblePathVersionMapper();
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void getOrCreate() {
VersionRule versionRule = mapper.getOrCreate("v1");
@@ -40,42 +35,37 @@ public class TestCompatiblePathVersionMapper {
@Test
public void createVersionRule_empty() {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is("pathVersion \"\" is invalid, format must be v+number or V+number."));
-
- mapper.getOrCreate("");
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> mapper.getOrCreate(""));
+ Assertions.assertEquals("pathVersion \"\" is invalid, format must be v+number or V+number.", exception.getMessage());
}
@Test
public void createVersionRule_invalidFormat() {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is("pathVersion \"a1\" is invalid, format must be v+number or V+number."));
-
- mapper.getOrCreate("a1");
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> mapper.getOrCreate("a1"));
+ Assertions.assertEquals("pathVersion \"a1\" is invalid, format must be v+number or V+number.", exception.getMessage());
}
@Test
public void createVersionRule_invalidNumber() {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is("pathVersion \"va\" is invalid, format must be v+number or V+number."));
-
- mapper.getOrCreate("va");
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> mapper.getOrCreate("va"));
+ Assertions.assertEquals("pathVersion \"va\" is invalid, format must be v+number or V+number.", exception.getMessage());
}
@Test
public void createVersionRule_tooSmall() {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is("pathVersion \"v-1\" is invalid, version range is [0, 32767]."));
-
- mapper.getOrCreate("v-1");
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> mapper.getOrCreate("v-1"));
+ Assertions.assertEquals("pathVersion \"v-1\" is invalid, version range is [0, 32767].", exception.getMessage());
}
@Test
public void createVersionRule_tooBig() {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is("pathVersion \"v32768\" is invalid, version range is [0, 32767]."));
-
- mapper.getOrCreate("v32768");
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> mapper.getOrCreate("v32768"));
+ Assertions.assertEquals("pathVersion \"v32768\" is invalid, version range is [0, 32767].", exception.getMessage());
}
@Test
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java
index 337efdaec..8cd6feb14 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java
@@ -19,8 +19,8 @@ package org.apache.servicecomb.foundation.common.event;
import java.util.ArrayList;
import java.util.List;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.Test;
import com.google.common.eventbus.AllowConcurrentEvents;
@@ -75,7 +75,7 @@ public class TestEventBus {
eventBus.register(new SubscriberWithOrderForTest(events));
eventBus.post("value");
- Assert.assertThat(events, Matchers.contains("s2:value", "s1:value"));
+ MatcherAssert.assertThat(events, Matchers.contains("s2:value", "s1:value"));
}
@Test
@@ -95,7 +95,7 @@ public class TestEventBus {
eventBus.post(0.1);
eventBus.post(1);
eventBus.post("str");
- Assert.assertThat(events, Matchers.contains(1, "str"));
+ MatcherAssert.assertThat(events, Matchers.contains(1, "str"));
eventBus.unregister(obj);
@@ -103,7 +103,7 @@ public class TestEventBus {
eventBus.post(0.1);
eventBus.post(1);
eventBus.post("str");
- Assert.assertThat(events, Matchers.empty());
+ MatcherAssert.assertThat(events, Matchers.empty());
}
@Test
@@ -117,13 +117,13 @@ public class TestEventBus {
eventBus.post(0.1);
eventBus.post(1);
eventBus.post("str");
- Assert.assertThat(events, Matchers.contains(1, 1, "str", "str"));
+ MatcherAssert.assertThat(events, Matchers.contains(1, 1, "str", "str"));
events.clear();
eventBus.unregister(obj1);
eventBus.post(0.1);
eventBus.post(1);
eventBus.post("str");
- Assert.assertThat(events, Matchers.contains(1, "str"));
+ MatcherAssert.assertThat(events, Matchers.contains(1, "str"));
}
}
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpStatusUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpStatusUtils.java
index ac5465241..28079d801 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpStatusUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpStatusUtils.java
@@ -19,20 +19,15 @@ package org.apache.servicecomb.foundation.common.http;
import javax.ws.rs.core.Response.StatusType;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestHttpStatusUtils {
HttpStatusManager mgr = new HttpStatusManager();
StatusType st;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void testStandard() {
st = HttpStatusUtils.getOrCreateByStatusCode(200);
@@ -47,9 +42,8 @@ public class TestHttpStatusUtils {
@Test
public void testAddRepeat() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("repeated status code: 200"));
-
- mgr.addStatusType(new HttpStatus(200, "ok"));
+ IllegalStateException illegalStateException = Assertions.assertThrows(IllegalStateException.class,
+ () -> mgr.addStatusType(new HttpStatus(200, "ok")));
+ Assertions.assertEquals("repeated status code: 200", illegalStateException.getMessage());
}
}
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpUtils.java
index 43587fcfb..bb3516ed2 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/http/TestHttpUtils.java
@@ -20,15 +20,11 @@ import java.net.URISyntaxException;
import javax.ws.rs.core.MediaType;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestHttpUtils {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void parseParamFromHeaderValue_normal() {
@@ -79,11 +75,10 @@ public class TestHttpUtils {
@Test
public void uriEncode_failed() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage(Matchers.is("uriEncode failed, path=\":\"."));
- expectedException.expectCause(Matchers.instanceOf(URISyntaxException.class));
-
- HttpUtils.uriEncodePath(":");
+ IllegalArgumentException illegalArgumentException = Assertions.assertThrows(IllegalArgumentException.class,
+ () -> HttpUtils.uriEncodePath(":"));
+ Assertions.assertEquals("uriEncode failed, path=\":\".", illegalArgumentException.getMessage());
+ Assertions.assertTrue(illegalArgumentException.getCause() instanceof URISyntaxException);
}
@Test
@@ -119,12 +114,10 @@ public class TestHttpUtils {
@Test
public void uriDecode_failed() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException
- .expectMessage(Matchers.is("uriDecode failed, path=\":\"."));
- expectedException.expectCause(Matchers.instanceOf(URISyntaxException.class));
-
- HttpUtils.uriDecodePath(":");
+ IllegalArgumentException illegalArgumentException = Assertions.assertThrows(IllegalArgumentException.class,
+ () -> HttpUtils.uriDecodePath(":"));
+ Assertions.assertEquals("uriDecode failed, path=\":\".", illegalArgumentException.getMessage());
+ Assertions.assertTrue(illegalArgumentException.getCause() instanceof URISyntaxException);
}
@Test
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/part/TestAbstractPart.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/part/TestAbstractPart.java
index 3b4f82858..c3d11525a 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/part/TestAbstractPart.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/part/TestAbstractPart.java
@@ -21,28 +21,21 @@ import java.io.IOException;
import javax.ws.rs.core.MediaType;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestAbstractPart {
AbstractPart part = new AbstractPart();
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private void initExpectedException() {
- expectedException.expect(Error.class);
- expectedException.expectMessage(Matchers.is("not supported method"));
+ private void checkError(Error error) {
+ Assertions.assertEquals("not supported method", error.getMessage());
}
@Test
public void getInputStream() throws IOException {
- initExpectedException();
-
- part.getInputStream();
+ Error error = Assertions.assertThrows(Error.class, () -> part.getInputStream());
+ checkError(error);
}
@Test
@@ -96,43 +89,37 @@ public class TestAbstractPart {
@Test
public void getSize() {
- initExpectedException();
-
- part.getSize();
+ Error error = Assertions.assertThrows(Error.class, () -> part.getSize());
+ checkError(error);
}
@Test
public void write() throws IOException {
- initExpectedException();
-
- part.write("file");
+ Error error = Assertions.assertThrows(Error.class, () -> part.write("file"));
+ checkError(error);
}
@Test
public void delete() throws IOException {
- initExpectedException();
-
- part.delete();
+ Error error = Assertions.assertThrows(Error.class, () -> part.delete());
+ checkError(error);
}
@Test
public void getHeader() {
- initExpectedException();
-
- part.getHeader("header");
+ Error error = Assertions.assertThrows(Error.class, () -> part.getHeader("header"));
+ checkError(error);
}
@Test
public void getHeaders() {
- initExpectedException();
-
- part.getHeaders("header");
+ Error error = Assertions.assertThrows(Error.class, () -> part.getHeaders("header"));
+ checkError(error);
}
@Test
public void getHeaderNames() {
- initExpectedException();
-
- part.getHeaderNames();
+ Error error = Assertions.assertThrows(Error.class, () -> part.getHeaderNames());
+ checkError(error);
}
}
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
index 014e9561d..11b7a04cb 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestLambdaMetafactoryUtils.java
@@ -33,6 +33,7 @@ import org.apache.servicecomb.foundation.common.utils.bean.Getter;
import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
import org.apache.servicecomb.foundation.common.utils.bean.IntSetter;
import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -80,7 +81,7 @@ public class TestLambdaMetafactoryUtils {
setter.accept(1);
int f1 = (int) getter.get();
Assert.assertEquals(1, f1);
- Assert.assertThat((List<Integer>) echo.apply(Arrays.asList(2)), Matchers.contains(2));
+ MatcherAssert.assertThat((List<Integer>) echo.apply(Arrays.asList(2)), Matchers.contains(2));
}
@SuppressWarnings("unchecked")
@@ -96,7 +97,7 @@ public class TestLambdaMetafactoryUtils {
setter.set(model, 1);
int f1 = getter.get(model);
Assert.assertEquals(1, f1);
- Assert.assertThat((List<Integer>) echo.apply(model, Arrays.asList(2)), Matchers.contains(2));
+ MatcherAssert.assertThat((List<Integer>) echo.apply(model, Arrays.asList(2)), Matchers.contains(2));
fluentSetter.set(model, 2);
int ff1 = getter.get(model);
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
index e220bc615..0f3559f01 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/TestConfigUtil.java
@@ -20,7 +20,6 @@ package org.apache.servicecomb.config;
import static com.seanyinx.github.unit.scaffolding.Randomness.uniquify;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
import java.lang.reflect.Field;
import java.util.Arrays;
@@ -38,6 +37,7 @@ import org.apache.servicecomb.config.spi.ConfigCenterConfigurationSource;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -52,6 +52,7 @@ import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
+import org.junit.jupiter.api.Assertions;
public class TestConfigUtil {
private static final String systemPropertyName = "servicecomb.cse.servicecomb.system.setting";
@@ -136,28 +137,26 @@ public class TestConfigUtil {
public void propertiesFromFileIsDuplicatedToCse() {
String expected = "value";
- assertThat(DynamicPropertyFactory
+ Assertions.assertNull(DynamicPropertyFactory
.getInstance()
.getStringProperty("cse.cse.servicecomb.file", null)
- .get(),
- equalTo(null));
+ .get());
- assertThat(DynamicPropertyFactory
+ Assertions.assertEquals(expected, DynamicPropertyFactory
.getInstance()
.getStringProperty("servicecomb.cse.servicecomb.file", null)
- .get(),
- equalTo(expected));
+ .get());
}
@Test
public void propertiesFromSystemIsDuplicatedToCse() {
- assertThat(DynamicPropertyFactory
+ MatcherAssert.assertThat(DynamicPropertyFactory
.getInstance()
.getStringProperty(systemPropertyName, null)
.get(),
equalTo(systemExpected));
- assertThat(DynamicPropertyFactory
+ MatcherAssert.assertThat(DynamicPropertyFactory
.getInstance()
.getStringProperty("servicecomb.cse.servicecomb.system.setting", null)
.get(),
@@ -166,13 +165,13 @@ public class TestConfigUtil {
@Test
public void propertiesFromEnvironmentIsDuplicatedToCse() {
- assertThat(DynamicPropertyFactory
+ MatcherAssert.assertThat(DynamicPropertyFactory
.getInstance()
.getStringProperty(environmentPropertyName, null)
.get(),
equalTo(environmentExpected));
- assertThat(DynamicPropertyFactory
+ MatcherAssert.assertThat(DynamicPropertyFactory
.getInstance()
.getStringProperty("servicecomb.cse.servicecomb.environment.setting", null)
.get(),
@@ -188,8 +187,8 @@ public class TestConfigUtil {
Deencapsulation.invoke(ConfigUtil.class, "duplicateCseConfigToServicecomb", config);
Object result = config.getProperty("servicecomb.list");
- assertThat(result, instanceOf(List.class));
- assertThat(result, equalTo(list));
+ MatcherAssert.assertThat(result, instanceOf(List.class));
+ MatcherAssert.assertThat(result, equalTo(list));
}
@Test
@@ -200,17 +199,17 @@ public class TestConfigUtil {
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
String changed = uniquify("changed");
configurationSource.addProperty(someProperty, changed);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(changed));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(changed));
expected = uniquify("ran");
@@ -219,17 +218,17 @@ public class TestConfigUtil {
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
changed = uniquify("changed");
configurationSource.addProperty(someProperty, changed);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(changed));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(changed));
}
@@ -240,34 +239,34 @@ public class TestConfigUtil {
String injectProperty = "servicecomb.cse.servicecomb.change";
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
String changed = uniquify("changed");
configurationSource.setProperty(someProperty, changed);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(changed));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(changed));
expected = uniquify("ran");
someProperty = "cse.servicecomb.cse.change";
injectProperty = "servicecomb.servicecomb.cse.change";
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
changed = uniquify("changed");
configurationSource.setProperty(someProperty, changed);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(changed));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(changed));
}
@@ -278,16 +277,16 @@ public class TestConfigUtil {
String injectProperty = "servicecomb.cse.servicecomb.delete";
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
configurationSource.deleteProperty(someProperty);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(null));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(null));
expected = uniquify("ran");
@@ -295,16 +294,16 @@ public class TestConfigUtil {
injectProperty = "servicecomb.servicecomb.cse.delete";
configurationSource.addProperty(someProperty, expected);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(expected));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(expected));
configurationSource.deleteProperty(someProperty);
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(someProperty, null).get(),
equalTo(null));
- assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
+ MatcherAssert.assertThat(DynamicPropertyFactory.getInstance().getStringProperty(injectProperty, null).get(),
equalTo(null));
}
@@ -314,8 +313,7 @@ public class TestConfigUtil {
AbstractConfiguration config = new DynamicConfiguration();
config.addProperty(someProperty, "testing");
AbstractConfiguration result = ConfigUtil.convertEnvVariable(config);
- assertThat(result.getString("cse.service.registry.address"), equalTo("testing"));
- assertThat(result.getString("cse_service_registry_address"), equalTo("testing"));
+ Assertions.assertEquals("testing", result.getString("cse.service.registry.address"));
}
@Test
diff --git a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestPlaceholderResolver.java b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestPlaceholderResolver.java
index 9e4e941d2..2f7020628 100644
--- a/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestPlaceholderResolver.java
+++ b/foundations/foundation-config/src/test/java/org/apache/servicecomb/config/inject/TestPlaceholderResolver.java
@@ -20,8 +20,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -44,49 +44,49 @@ public class TestPlaceholderResolver {
@Test
public void unknown() {
- Assert.assertThat(resolver.replace("prefix${xxx}suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix${xxx}suffix", parameters),
Matchers.contains("prefix${xxx}suffix"));
}
@Test
public void empty() {
- Assert.assertThat(resolver.replace("prefix${}suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix${}suffix", parameters),
Matchers.contains("prefix${}suffix"));
}
@Test
public void notComplete() {
- Assert.assertThat(resolver.replace("prefix${suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix${suffix", parameters),
Matchers.contains("prefix${suffix"));
}
@Test
public void normal() {
- Assert.assertThat(resolver.replace("prefix.${key}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${key}.suffix", parameters),
Matchers.contains("prefix.value.suffix"));
}
@Test
public void disable() {
- Assert.assertThat(resolver.replace("prefix.\\${key}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.\\${key}.suffix", parameters),
Matchers.contains("prefix.${key}.suffix"));
}
@Test
public void varOfVar() {
- Assert.assertThat(resolver.replace("prefix.${varOfVar}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${varOfVar}.suffix", parameters),
Matchers.contains("prefix.value.suffix"));
}
@Test
public void list() {
- Assert.assertThat(resolver.replace("prefix.${low-list}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${low-list}.suffix", parameters),
Matchers.contains("prefix.low-1.suffix", "prefix.low-2.suffix"));
}
@Test
public void multi_list() {
- Assert.assertThat(resolver.replace("prefix.${low-list}.${middle-list}.${high-list}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${low-list}.${middle-list}.${high-list}.suffix", parameters),
Matchers.contains(
"prefix.low-1.middle-1.high-1.suffix",
"prefix.low-1.middle-1.high-2.suffix",
@@ -100,13 +100,13 @@ public class TestPlaceholderResolver {
@Test
public void nested() {
- Assert.assertThat(resolver.replace("prefix.${${priority}-list}.suffix", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${${priority}-list}.suffix", parameters),
Matchers.contains("prefix.low-1.suffix", "prefix.low-2.suffix"));
}
@Test
public void mixed() {
- Assert.assertThat(resolver.replace("prefix.${${priority}-list}.${key}.${high-list}.suffix ${xxx}", parameters),
+ MatcherAssert.assertThat(resolver.replace("prefix.${${priority}-list}.${key}.${high-list}.suffix ${xxx}", parameters),
Matchers.contains(
"prefix.low-1.value.high-1.suffix ${xxx}",
"prefix.low-2.value.high-1.suffix ${xxx}",
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
index 748774578..a9450e824 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsBootstrap.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ThreadFactory;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -65,7 +66,7 @@ public class TestMetricsBootstrap {
bootstrap.start(globalRegistry, eventBus);
bootstrap.shutdown();
- Assert.assertThat(initList, Matchers.contains(metricsInitializer, metricsInitializer));
+ MatcherAssert.assertThat(initList, Matchers.contains(metricsInitializer, metricsInitializer));
}
@Test
@@ -97,7 +98,7 @@ public class TestMetricsBootstrap {
bootstrap.pollMeters();
bootstrap.shutdown();
Assert.assertEquals(meters, result.getMeters());
- Assert.assertThat(result.getMeasurements(), Matchers.contains(measurement));
+ MatcherAssert.assertThat(result.getMeasurements(), Matchers.contains(measurement));
}
@Test
@@ -145,7 +146,7 @@ public class TestMetricsBootstrap {
bootstrap.shutdown();
- Assert.assertThat(destroyList, Matchers.contains(initializer2, initializer1));
+ MatcherAssert.assertThat(destroyList, Matchers.contains(initializer2, initializer1));
}
@Test
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionConfig.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionConfig.java
index 46c7452e1..f05302a09 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionConfig.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionConfig.java
@@ -17,13 +17,10 @@
package org.apache.servicecomb.foundation.metrics.meter;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestLatencyDistributionConfig {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void testValidProperty() {
@@ -42,17 +39,19 @@ public class TestLatencyDistributionConfig {
@Test
public void testInValidProperty1() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("invalid latency scope, min=2, max=1.");
- LatencyDistributionConfig latencyDistributionConfig = new LatencyDistributionConfig("2,1,10");
- Assert.assertEquals(0, latencyDistributionConfig.getScopeConfigs().size());
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ LatencyDistributionConfig latencyDistributionConfig = new LatencyDistributionConfig("2,1,10");
+ Assert.assertEquals(0, latencyDistributionConfig.getScopeConfigs().size());
+ });
+ Assertions.assertEquals("invalid latency scope, min=2, max=1.", exception.getMessage());
}
@Test
public void testInValidProperty2() {
- expectedException.expect(NumberFormatException.class);
- expectedException.expectMessage("For input string: \"a\"");
- LatencyDistributionConfig latencyDistributionConfig = new LatencyDistributionConfig("a,1,10");
- Assert.assertEquals(0, latencyDistributionConfig.getScopeConfigs().size());
+ NumberFormatException exception = Assertions.assertThrows(NumberFormatException.class, () -> {
+ LatencyDistributionConfig latencyDistributionConfig = new LatencyDistributionConfig("a,1,10");
+ Assert.assertEquals(0, latencyDistributionConfig.getScopeConfigs().size());
+ });
+ Assertions.assertEquals("For input string: \"a\"", exception.getMessage());
}
}
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionMeter.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionMeter.java
index d58c5c458..72f900b6a 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionMeter.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/meter/TestLatencyDistributionMeter.java
@@ -21,9 +21,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Measurement;
@@ -31,8 +29,6 @@ import com.netflix.spectator.api.Measurement;
import mockit.Mocked;
public class TestLatencyDistributionMeter {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void testMeasure(@Mocked Id id) {
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementGroupConfig.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementGroupConfig.java
index 51b6a56ab..848ab57eb 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementGroupConfig.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementGroupConfig.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.foundation.metrics.publish.spectator;
import java.util.List;
import java.util.Map;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -40,10 +41,9 @@ public class TestMeasurementGroupConfig {
config = new MeasurementGroupConfig("id", "tag1");
groups = Deencapsulation.getField(config, "groups");
- Assert.assertThat(groups.keySet(), Matchers.contains("id"));
- Assert.assertThat(groups.get("id").stream().map(e -> {
- return e.getTagKey();
- }).toArray(), Matchers.arrayContaining("tag1"));
+ MatcherAssert.assertThat(groups.keySet(), Matchers.contains("id"));
+ MatcherAssert.assertThat(groups.get("id").stream().map(TagFinder::getTagKey).toArray(),
+ Matchers.arrayContaining("tag1"));
}
@Test
@@ -51,11 +51,11 @@ public class TestMeasurementGroupConfig {
config.addGroup("id1", "tag1.1", "tag1.2");
config.addGroup("id2", "tag2.1", "tag2.2");
- Assert.assertThat(groups.keySet(), Matchers.contains("id2", "id1"));
- Assert.assertThat(groups.get("id1").stream().map(e -> {
+ MatcherAssert.assertThat(groups.keySet(), Matchers.contains("id2", "id1"));
+ MatcherAssert.assertThat(groups.get("id1").stream().map(e -> {
return e.getTagKey();
}).toArray(), Matchers.arrayContaining("tag1.1", "tag1.2"));
- Assert.assertThat(groups.get("id2").stream().map(e -> {
+ MatcherAssert.assertThat(groups.get("id2").stream().map(e -> {
return e.getTagKey();
}).toArray(), Matchers.arrayContaining("tag2.1", "tag2.2"));
}
@@ -65,8 +65,7 @@ public class TestMeasurementGroupConfig {
config.addGroup("id1", "tag1.1", "tag1.2");
config.addGroup("id2", "tag2.1", "tag2.2");
- Assert.assertThat(config.findTagFinders("id2").stream().map(e -> {
- return e.getTagKey();
- }).toArray(), Matchers.arrayContaining("tag2.1", "tag2.2"));
+ MatcherAssert.assertThat(config.findTagFinders("id2").stream().map(TagFinder::getTagKey).toArray(),
+ Matchers.arrayContaining("tag2.1", "tag2.2"));
}
}
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementNode.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementNode.java
index 585fd9aec..5ae60a0e7 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementNode.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementNode.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.foundation.metrics.publish.spectator;
import java.util.HashMap;
import java.util.Map;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -78,7 +79,7 @@ public class TestMeasurementNode {
public void getMeasurements(@Mocked Measurement measurement) {
node.addMeasurement(measurement);
- Assert.assertThat(node.getMeasurements(), Matchers.contains(measurement));
+ MatcherAssert.assertThat(node.getMeasurements(), Matchers.contains(measurement));
}
@Test
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementTree.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementTree.java
index 219369603..b236b3d94 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementTree.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementTree.java
@@ -18,12 +18,10 @@ package org.apache.servicecomb.foundation.metrics.publish.spectator;
import java.util.concurrent.TimeUnit;
-import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.ManualClock;
@@ -40,9 +38,6 @@ public class TestMeasurementTree {
Timer timer;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setup() {
timer = registry.timer("id",
@@ -85,11 +80,10 @@ public class TestMeasurementTree {
@Test
public void from_failed() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("tag key \"notExist\" not exist in Measurement(id:g1=g1v:g2=g2v:statistic=count:t3=t3v:t4=t4v,0,0.0)"));
-
- MeasurementGroupConfig config = new MeasurementGroupConfig("id", "notExist");
- tree.from(registry.iterator(), config);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ MeasurementGroupConfig config = new MeasurementGroupConfig("id", "notExist");
+ tree.from(registry.iterator(), config);
+ });
+ Assertions.assertEquals("tag key \"notExist\" not exist in Measurement(id:g1=g1v:g2=g2v:statistic=count:t3=t3v:t4=t4v,0,0.0)", exception.getMessage());
}
}
diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestTagFinder.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestTagFinder.java
index 1f5551b04..249b51af2 100644
--- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestTagFinder.java
+++ b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestTagFinder.java
@@ -16,15 +16,11 @@
*/
package org.apache.servicecomb.foundation.metrics.publish.spectator;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestTagFinder {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void buildFromString() {
@@ -45,19 +41,13 @@ public class TestTagFinder {
@Test
public void buildFromInvalidType() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException
- .expectMessage(Matchers.is("only support String or TagFinder, but got " + Integer.class.getName()));
-
- TagFinder.build(1);
+ IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> TagFinder.build(1));
+ Assertions.assertEquals("only support String or TagFinder, but got " + Integer.class.getName(), exception.getMessage());
}
@Test
public void buildFromNull() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException
- .expectMessage(Matchers.is("only support String or TagFinder, but got null"));
-
- TagFinder.build(null);
+ IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> TagFinder.build(null));
+ Assertions.assertEquals("only support String or TagFinder, but got null", exception.getMessage());
}
}
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/TestSchemaBase.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/TestSchemaBase.java
index 2743aa149..6f38d89c1 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/TestSchemaBase.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/TestSchemaBase.java
@@ -29,8 +29,6 @@ import org.apache.servicecomb.foundation.protobuf.internal.model.PrimitiveWrappe
import org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot;
import org.apache.servicecomb.foundation.protobuf.internal.model.Root;
import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
import io.protostuff.compiler.model.Field;
@@ -58,9 +56,6 @@ public class TestSchemaBase {
protected static RootDeserializer<Map<String, Object>> mapRootDeserializer = protoMapper
.createRootDeserializer("Root", Map.class);
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
protected Object scbRoot;
protected byte[] scbRootBytes;
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestAnySchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestAnySchema.java
index 441bf2f7c..658c20a05 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestAnySchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestAnySchema.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.foundation.protobuf.internal.ProtoConst;
import org.apache.servicecomb.foundation.protobuf.internal.TestSchemaBase;
import org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot;
import org.apache.servicecomb.foundation.protobuf.internal.model.Root;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -55,7 +56,7 @@ public class TestAnySchema extends TestSchemaBase {
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
- Assert.assertThat(root.getAnys(), Matchers.contains("abc", "123"));
+ MatcherAssert.assertThat(root.getAnys(), Matchers.contains("abc", "123"));
}
@Test
@@ -81,12 +82,12 @@ public class TestAnySchema extends TestSchemaBase {
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
- Assert.assertThat(root.getAny(), Matchers.instanceOf(Map.class));
- Assert.assertThat((Map<? extends String, ? extends String>) root.getAny(), Matchers.hasEntry("name", "n1"));
+ MatcherAssert.assertThat(root.getAny(), Matchers.instanceOf(Map.class));
+ MatcherAssert.assertThat((Map<? extends String, ? extends String>) root.getAny(), Matchers.hasEntry("name", "n1"));
RootDeserializer<Map<String, Object>> deserializer = protoMapper.createRootDeserializer("Root", Map.class);
map = deserializer.deserialize(scbRootBytes);
- Assert.assertThat((Map<? extends String, ? extends String>) map.get("any"), Matchers.hasEntry("name", "n1"));
+ MatcherAssert.assertThat((Map<? extends String, ? extends String>) map.get("any"), Matchers.hasEntry("name", "n1"));
}
@Test
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestMessageSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestMessageSchema.java
index 56fe45337..b7ac75c99 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestMessageSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/TestMessageSchema.java
@@ -24,6 +24,7 @@ import org.apache.servicecomb.foundation.protobuf.internal.TestSchemaBase;
import org.apache.servicecomb.foundation.protobuf.internal.model.CustomGeneric;
import org.apache.servicecomb.foundation.protobuf.internal.model.ProtobufRoot;
import org.apache.servicecomb.foundation.protobuf.internal.model.User;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -49,7 +50,7 @@ public class TestMessageSchema extends TestSchemaBase {
@SuppressWarnings("unchecked")
CustomGeneric<User> generic = (CustomGeneric<User>) scbRoot;
- Assert.assertThat(generic.user, Matchers.instanceOf(User.class));
+ MatcherAssert.assertThat(generic.user, Matchers.instanceOf(User.class));
}
@Test
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBoolSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBoolSchema.java
index 61e79eba6..187264baf 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBoolSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBoolSchema.java
@@ -23,6 +23,7 @@ import org.apache.servicecomb.foundation.protobuf.internal.model.User;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
public class TestBoolSchema extends TestSchemaBase {
public TestBoolSchema() {
@@ -75,13 +76,13 @@ public class TestBoolSchema extends TestSchemaBase {
@Test
public void type_invalid() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto bool, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:bool"));
-
- scbMap = new HashMap<>();
- scbMap.put("bool", new User());
- rootSerializer.serialize(scbMap);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("bool", new User());
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto bool, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:bool",
+ exception.getMessage());
}
}
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBytesSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBytesSchema.java
index 7baac251f..325c2c37e 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBytesSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestBytesSchema.java
@@ -20,10 +20,10 @@ import java.util.HashMap;
import org.apache.servicecomb.foundation.protobuf.internal.TestSchemaBase;
import org.apache.servicecomb.foundation.protobuf.internal.model.User;
-import org.hamcrest.Matchers;
import org.junit.Test;
import com.google.protobuf.ByteString;
+import org.junit.jupiter.api.Assertions;
public class TestBytesSchema extends TestSchemaBase {
public TestBytesSchema() {
@@ -38,13 +38,13 @@ public class TestBytesSchema extends TestSchemaBase {
}
@Test
- public void type_invalid() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto bytes, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:bytes"));
-
- scbMap = new HashMap<>();
- scbMap.put("bytes", new User());
- rootSerializer.serialize(scbMap);
+ public void type_invalid() {
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("bytes", new User());
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto bytes, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:bytes",
+ exception.getMessage());
}
}
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestEnumSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestEnumSchema.java
index bba3d61db..a248702b8 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestEnumSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestEnumSchema.java
@@ -25,6 +25,7 @@ import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
public class TestEnumSchema extends TestSchemaBase {
@Test
@@ -78,34 +79,32 @@ public class TestEnumSchema extends TestSchemaBase {
@Test
public void fromInvalidEnum() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("invalid enum name ROUND for proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color"));
-
- scbMap = new HashMap<>();
- scbMap.put("color", Sharp.ROUND);
- rootSerializer.serialize(scbMap);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("color", Sharp.ROUND);
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("invalid enum name ROUND for proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color", exception.getMessage());
}
@Test
- public void fromInvalidNumber() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("invalid enum value 3 for proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color"));
-
- scbMap = new HashMap<>();
- scbMap.put("color", 3);
- rootSerializer.serialize(scbMap);
+ public void fromInvalidNumber() {
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("color", 3);
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("invalid enum value 3 for proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color", exception.getMessage());
}
@Test
- public void type_invalid() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color"));
-
- scbMap = new HashMap<>();
- scbMap.put("color", new User());
- rootSerializer.serialize(scbMap);
+ public void type_invalid() {
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("color", new User());
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto Color, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:color",
+ exception.getMessage());
}
}
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestNumberBaseSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestNumberBaseSchema.java
index 5e3d777e9..f723e26aa 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestNumberBaseSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestNumberBaseSchema.java
@@ -32,6 +32,7 @@ import org.junit.Test;
import io.protostuff.compiler.model.Field;
import io.protostuff.compiler.model.Type;
+import org.junit.jupiter.api.Assertions;
@Ignore
public abstract class TestNumberBaseSchema extends TestSchemaBase {
@@ -91,13 +92,13 @@ public abstract class TestNumberBaseSchema extends TestSchemaBase {
strings_invalid(protoField);
}
- private void strings_invalid(Field field) throws IOException {
- expectedException.expect(NumberFormatException.class);
- expectedException.expectMessage(Matchers.is("For input string: \"a\""));
-
- scbMap = new HashMap<>();
- scbMap.put(field.getName(), new String[] {"a"});
- rootSerializer.serialize(scbMap);
+ private void strings_invalid(Field field) {
+ NumberFormatException exception = Assertions.assertThrows(NumberFormatException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put(field.getName(), new String[] {"a"});
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("For input string: \"a\"", exception.getMessage());
}
@Test
@@ -110,17 +111,17 @@ public abstract class TestNumberBaseSchema extends TestSchemaBase {
string_invalid(protoField);
}
- private void string_invalid(Field field) throws IOException {
- expectedException.expect(NumberFormatException.class);
- expectedException.expectMessage(Matchers.is("For input string: \"a\""));
-
- scbMap = new HashMap<>();
- scbMap.put(field.getName(), "a");
- rootSerializer.serialize(scbMap);
+ private void string_invalid(Field field) {
+ NumberFormatException exception = Assertions.assertThrows(NumberFormatException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put(field.getName(), "a");
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("For input string: \"a\"", exception.getMessage());
}
@Test
- public void primitiveType_invalid() throws Throwable {
+ public void primitiveType_invalid() {
type_invalid(primitiveProtoField);
}
@@ -129,17 +130,16 @@ public abstract class TestNumberBaseSchema extends TestSchemaBase {
type_invalid(protoField);
}
- private void type_invalid(Field field) throws IOException {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is(String.format("not support serialize from %s to proto %s, field=%s:%s",
+ private void type_invalid(Field field) {
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put(field.getName(), new User());
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals(String.format("not support serialize from %s to proto %s, field=%s:%s",
User.class.getName(),
field.getTypeName(),
((Type) field.getParent()).getCanonicalName(),
- field.getName())));
-
- scbMap = new HashMap<>();
- scbMap.put(field.getName(), new User());
- rootSerializer.serialize(scbMap);
+ field.getName()), exception.getMessage());
}
}
diff --git a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestStringSchema.java b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestStringSchema.java
index 4c9cd625a..4de133079 100644
--- a/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestStringSchema.java
+++ b/foundations/foundation-protobuf/src/test/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/TestStringSchema.java
@@ -20,9 +20,9 @@ import java.util.HashMap;
import org.apache.servicecomb.foundation.protobuf.internal.TestSchemaBase;
import org.apache.servicecomb.foundation.protobuf.internal.model.User;
-import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
public class TestStringSchema extends TestSchemaBase {
@Test
@@ -54,12 +54,12 @@ public class TestStringSchema extends TestSchemaBase {
@Test
public void type_invalid() throws Throwable {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers
- .is("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto string, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:string"));
-
- scbMap = new HashMap<>();
- scbMap.put("string", new User());
- rootSerializer.serialize(scbMap);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ scbMap = new HashMap<>();
+ scbMap.put("string", new User());
+ rootSerializer.serialize(scbMap);
+ });
+ Assertions.assertEquals("not support serialize from org.apache.servicecomb.foundation.protobuf.internal.model.User to proto string, field=org.apache.servicecomb.foundation.protobuf.internal.model.Root:string",
+ exception.getMessage());
}
}
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestAbstractTransportDiscoveryFilter.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestAbstractTransportDiscoveryFilter.java
index c1f8da8d1..df9ef8598 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestAbstractTransportDiscoveryFilter.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestAbstractTransportDiscoveryFilter.java
@@ -25,9 +25,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.registry.discovery.AbstractEndpointDiscoveryFilter;
-import org.apache.servicecomb.registry.discovery.DiscoveryContext;
-import org.apache.servicecomb.registry.discovery.DiscoveryTreeNode;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -136,7 +134,7 @@ public class TestAbstractTransportDiscoveryFilter {
result = filter.createDiscoveryTreeNode("a", context, parent);
Assert.assertEquals("parent/a", result.name());
- Assert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().get(0)));
+ MatcherAssert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().get(0)));
}
@Test
@@ -153,7 +151,7 @@ public class TestAbstractTransportDiscoveryFilter {
List<String> expect = new ArrayList<>();
expect.addAll(instance1.getEndpoints());
expect.addAll(instance2.getEndpoints());
- Assert.assertThat(result.collectionData(), Matchers.contains(expect.toArray()));
+ MatcherAssert.assertThat(result.collectionData(), Matchers.contains(expect.toArray()));
}
@Test
@@ -166,7 +164,7 @@ public class TestAbstractTransportDiscoveryFilter {
result = filter.createDiscoveryTreeNode("", context, parent);
Assert.assertEquals("parent/", result.name());
- Assert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().toArray()));
+ MatcherAssert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().toArray()));
}
@Test
@@ -179,6 +177,6 @@ public class TestAbstractTransportDiscoveryFilter {
result = filter.createDiscoveryTreeNode("", context, parent);
Assert.assertEquals("parent/", result.name());
- Assert.assertThat(result.collectionData(), Matchers.empty());
+ MatcherAssert.assertThat(result.collectionData(), Matchers.empty());
}
}
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
index d07813bf9..7b5bcd505 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/discovery/TestDiscoveryTree.java
@@ -26,18 +26,14 @@ import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.DiscoveryManager;
-import org.apache.servicecomb.registry.discovery.DiscoveryContext;
-import org.apache.servicecomb.registry.discovery.DiscoveryFilter;
-import org.apache.servicecomb.registry.discovery.DiscoveryTree;
-import org.apache.servicecomb.registry.discovery.DiscoveryTreeNode;
import org.apache.servicecomb.registry.cache.InstanceCacheManager;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import mockit.Deencapsulation;
import mockit.Expectations;
@@ -63,9 +59,6 @@ public class TestDiscoveryTree {
DiscoveryTreeNode result;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void loadFromSPI(@Mocked DiscoveryFilter f1, @Mocked DiscoveryFilter f2) {
Class<? extends DiscoveryFilter> cls = DiscoveryFilter.class;
@@ -78,7 +71,7 @@ public class TestDiscoveryTree {
discoveryTree.loadFromSPI(cls);
- Assert.assertThat(filters, Matchers.contains(f1, f2));
+ MatcherAssert.assertThat(filters, Matchers.contains(f1, f2));
}
@Test
@@ -104,7 +97,7 @@ public class TestDiscoveryTree {
discoveryTree.addFilter(f1);
discoveryTree.sort();
- Assert.assertThat(filters, Matchers.contains(f1, f2));
+ MatcherAssert.assertThat(filters, Matchers.contains(f1, f2));
}
@Test
@@ -222,10 +215,11 @@ public class TestDiscoveryTree {
};
discoveryTree.addFilter(filter);
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage(Matchers.is(filter.getClass().getName() + " discovery return null."));
-
- result = discoveryTree.discovery(context, null, null, null);
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> {
+ result = discoveryTree.discovery(context, null, null, null);
+ });
+ Assertions.assertEquals(filter.getClass().getName() + " discovery return null.", exception.getMessage());
}
@Test
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersion.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersion.java
index 1eb629dc0..d239003e6 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersion.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersion.java
@@ -18,11 +18,9 @@
package org.apache.servicecomb.registry.version;
import org.apache.servicecomb.foundation.common.Version;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestVersion {
Version version;
@@ -31,9 +29,6 @@ public class TestVersion {
short s2 = 2;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void constructFromStringNormalOnlyMajor() {
version = new Version("1");
@@ -74,84 +69,85 @@ public class TestVersion {
@Test
public void constructFromStringInvalidNull() {
- expectedException.expect(NullPointerException.class);
-
- version = new Version(null);
+ Assertions.assertThrows(NullPointerException.class, () -> {
+ version = new Version(null);
+ });
}
@Test
public void constructFromStringInvalidEmpty() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid major \"\", version \"\"."));
- expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
-
- version = new Version("");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("");
+ });
+ Assertions.assertEquals("Invalid major \"\", version \"\".", exception.getMessage());
+ Assertions.assertTrue(exception.getCause() instanceof NumberFormatException);
}
@Test
public void constructFromStringInvalidMajorNegative() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("major \"-1\" can not be negative, version \"-1\"."));
-
- version = new Version("-1");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("-1");
+ });
+ Assertions.assertEquals("major \"-1\" can not be negative, version \"-1\".", exception.getMessage());
}
@Test
public void constructFromStringInvalidMajorDot() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid minor \"\", version \"1.\"."));
- expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
-
- version = new Version("1.");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.");
+ });
+ Assertions.assertEquals("Invalid minor \"\", version \"1.\".", exception.getMessage());
+ Assertions.assertTrue(exception.getCause() instanceof NumberFormatException);
}
@Test
public void constructFromStringInvalidMinorNegative() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("minor \"-1\" can not be negative, version \"1.-1\"."));
-
- version = new Version("1.-1");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.-1");
+ });
+ Assertions.assertEquals("minor \"-1\" can not be negative, version \"1.-1\".", exception.getMessage());
}
@Test
public void constructFromStringInvalidMinorDot() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid patch \"\", version \"1.1.\"."));
- expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
-
- version = new Version("1.1.");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.1.");
+ });
+ Assertions.assertEquals("Invalid patch \"\", version \"1.1.\".", exception.getMessage());
+ Assertions.assertTrue(exception.getCause() instanceof NumberFormatException);
}
@Test
public void constructFromStringInvalidPatchNegative() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("patch \"-1\" can not be negative, version \"1.1.-1\"."));
-
- version = new Version("1.1.-1");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.1.-1");
+ });
+ Assertions.assertEquals("patch \"-1\" can not be negative, version \"1.1.-1\".", exception.getMessage());
}
@Test
public void constructFromStringInvalidPatchDot() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid build \"\", version \"1.1.1.\"."));
- expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
-
- version = new Version("1.1.1.");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.1.1.");
+ });
+ Assertions.assertEquals("Invalid build \"\", version \"1.1.1.\".", exception.getMessage());
+ Assertions.assertTrue(exception.getCause() instanceof NumberFormatException);
}
@Test
public void constructFromStringInvalidBuildNegative() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("build \"-1\" can not be negative, version \"1.1.1.-1\"."));
-
- version = new Version("1.1.1.-1");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.1.1.-1");
+ });
+ Assertions.assertEquals("build \"-1\" can not be negative, version \"1.1.1.-1\".", exception.getMessage());
}
@Test
public void constructFromStringInvalidTooManyPart() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid version \"1.1.1.1.\"."));
- version = new Version("1.1.1.1.");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ version = new Version("1.1.1.1.");
+ });
+ Assertions.assertEquals("Invalid version \"1.1.1.1.\".", exception.getMessage());
}
@Test
diff --git a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersionRuleUtils.java b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersionRuleUtils.java
index 5ff8fc860..27f0952df 100644
--- a/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersionRuleUtils.java
+++ b/foundations/foundation-registry/src/test/java/org/apache/servicecomb/registry/version/TestVersionRuleUtils.java
@@ -18,55 +18,51 @@
package org.apache.servicecomb.registry.version;
import org.apache.servicecomb.registry.definition.DefinitionConst;
-import org.apache.servicecomb.registry.version.VersionRule;
import org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule;
import org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule;
import org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule;
import org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule;
-import org.apache.servicecomb.registry.version.VersionRuleUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestVersionRuleUtils {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void fixed() {
VersionRule versionRule = VersionRuleUtils.getOrCreate("1");
- Assert.assertThat(versionRule, Matchers.instanceOf(FixedVersionRule.class));
+ MatcherAssert.assertThat(versionRule, Matchers.instanceOf(FixedVersionRule.class));
Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1"));
}
@Test
public void latest() {
VersionRule versionRule = VersionRuleUtils.getOrCreate(DefinitionConst.VERSION_RULE_LATEST);
- Assert.assertThat(versionRule, Matchers.instanceOf(LatestVersionRule.class));
+ MatcherAssert.assertThat(versionRule, Matchers.instanceOf(LatestVersionRule.class));
Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate(DefinitionConst.VERSION_RULE_LATEST));
}
@Test
public void range() {
VersionRule versionRule = VersionRuleUtils.getOrCreate("1-2");
- Assert.assertThat(versionRule, Matchers.instanceOf(RangeVersionRule.class));
+ MatcherAssert.assertThat(versionRule, Matchers.instanceOf(RangeVersionRule.class));
Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1-2"));
}
@Test
public void startFrom() {
VersionRule versionRule = VersionRuleUtils.getOrCreate("1+");
- Assert.assertThat(versionRule, Matchers.instanceOf(StartFromVersionRule.class));
+ MatcherAssert.assertThat(versionRule, Matchers.instanceOf(StartFromVersionRule.class));
Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1+"));
}
@Test
public void invalid() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Invalid major \"\", version \"\"."));
-
- VersionRuleUtils.getOrCreate("");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ VersionRuleUtils.getOrCreate("");
+ });
+ Assertions.assertEquals("Invalid major \"\", version \"\".", exception.getMessage());
}
}
diff --git a/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java b/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
index 6b26ff9e8..51d9d1688 100644
--- a/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
+++ b/foundations/foundation-spi/src/test/java/org/apache/servicecomb/foundation/common/utils/TestSPIServiceUtils.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -32,7 +33,7 @@ import mockit.Expectations;
import mockit.Mocked;
/**
- * Test SPIServiceUtils
+ * Test SPIServiceUtils
*
*
*/
@@ -81,9 +82,9 @@ public class TestSPIServiceUtils {
}
};
- Assert.assertThat(SPIServiceUtils.getSortedService(Ordered.class), Matchers.contains(o1, o2));
- Assert.assertThat(SPIServiceUtils.getAllService(Ordered.class), Matchers.contains(o1, o2));
- Assert.assertThat(SPIServiceUtils.getPriorityHighestService(Ordered.class), Matchers.is(o1));
+ MatcherAssert.assertThat(SPIServiceUtils.getSortedService(Ordered.class), Matchers.contains(o1, o2));
+ MatcherAssert.assertThat(SPIServiceUtils.getAllService(Ordered.class), Matchers.contains(o1, o2));
+ MatcherAssert.assertThat(SPIServiceUtils.getPriorityHighestService(Ordered.class), Matchers.is(o1));
Map<Class<?>, List<Object>> cache = Deencapsulation.getField(SPIServiceUtils.class, "cache");
cache.clear();
@@ -123,9 +124,9 @@ public class TestSPIServiceUtils {
@Override
public String toString() {
return "PriorityImpl{" +
- "name='" + name + '\'' +
- ", order=" + order +
- '}';
+ "name='" + name + '\'' +
+ ", order=" + order +
+ '}';
}
}
@@ -148,8 +149,8 @@ public class TestSPIServiceUtils {
}
};
- Assert.assertThat(SPIServiceUtils.getPriorityHighestServices(inst -> inst.getName(), PriorityIntf.class),
- Matchers.containsInAnyOrder(instances.get("2"), instances.get("5")));
+ MatcherAssert.assertThat(SPIServiceUtils.getPriorityHighestServices(PriorityIntf::getName, PriorityIntf.class),
+ Matchers.containsInAnyOrder(instances.get("2"), instances.get("5")));
Map<Class<?>, List<Object>> cache = Deencapsulation.getField(SPIServiceUtils.class, "cache");
cache.clear();
diff --git a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/TestSSLOptionFactory.java b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/TestSSLOptionFactory.java
index c18c4dad3..cf3e70755 100644
--- a/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/TestSSLOptionFactory.java
+++ b/foundations/foundation-ssl/src/test/java/org/apache/servicecomb/foundation/ssl/TestSSLOptionFactory.java
@@ -17,11 +17,9 @@
package org.apache.servicecomb.foundation.ssl;
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import com.netflix.config.ConcurrentCompositeConfiguration;
@@ -31,8 +29,6 @@ import mockit.MockUp;
import mockit.Mocked;
public class TestSSLOptionFactory {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void testSSLOptionFactory() {
@@ -49,9 +45,9 @@ public class TestSSLOptionFactory {
}
};
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(Matchers.is("Failed to create SSLOptionFactory."));
- SSLOptionFactory.createSSLOptionFactory("cc", null);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class,
+ () -> SSLOptionFactory.createSSLOptionFactory("cc", null));
+ Assertions.assertEquals("Failed to create SSLOptionFactory.", exception.getMessage());
}
@Test
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
index 2cf4bb820..08741be27 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -62,8 +63,8 @@ public class TestAddressResolverConfig {
}
};
AddressResolverOptions resolverOptions = AddressResolverConfig.getAddressResover("test", finalConfig);
- Assert.assertThat(resolverOptions.getServers(), is(Arrays.asList("6.6.6.6", "6.6.4.4")));
- Assert.assertThat(resolverOptions.getSearchDomains(),
+ MatcherAssert.assertThat(resolverOptions.getServers(), is(Arrays.asList("6.6.6.6", "6.6.4.4")));
+ MatcherAssert.assertThat(resolverOptions.getSearchDomains(),
is(Collections.singletonList("default.svc.local.cluster")));
Assert.assertEquals(resolverOptions.getQueryTimeout(),
2000);
@@ -90,11 +91,11 @@ public class TestAddressResolverConfig {
ArchaiusUtils.setProperty("addressResolver.ndots", 3);
ArchaiusUtils.setProperty("addressResolver.rotateServers", true);
AddressResolverOptions aroc = AddressResolverConfig.getAddressResover("test");
- Assert.assertThat(aroc.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
- Assert.assertThat(aroc.getSearchDomains(),
+ MatcherAssert.assertThat(aroc.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
+ MatcherAssert.assertThat(aroc.getSearchDomains(),
is(Arrays.asList("test.svc.local.cluster", "svc.local.cluster", "local.cluster")));
AddressResolverOptions aroc1 = AddressResolverConfig.getAddressResover("test1");
- Assert.assertThat(aroc1.getSearchDomains(),
+ MatcherAssert.assertThat(aroc1.getSearchDomains(),
is(Arrays.asList("default.svc.local.cluster", "svc.local.cluster", "local.cluster")));
Assert.assertTrue(aroc.isOptResourceEnabled());
}
@@ -106,7 +107,7 @@ public class TestAddressResolverConfig {
ArchaiusUtils.setProperty("addressResolver.maxQueries", 3);
ArchaiusUtils.setProperty("addressResolver.rdFlag", false);
AddressResolverOptions resolverOptions = AddressResolverConfig.getAddressResover("test");
- Assert.assertThat(resolverOptions.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
+ MatcherAssert.assertThat(resolverOptions.getServers(), is(Arrays.asList("8.8.8.8", "8.8.4.4")));
Assert.assertEquals(3, resolverOptions.getMaxQueries());
Assert.assertEquals(Integer.MAX_VALUE, resolverOptions.getCacheMaxTimeToLive());
Assert.assertFalse(resolverOptions.isOptResourceEnabled());
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/TestClientPoolManager.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/TestClientPoolManager.java
index dacffc609..2bc953155 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/TestClientPoolManager.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/TestClientPoolManager.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -94,7 +95,7 @@ public class TestClientPoolManager {
Assert.assertSame(pool, poolMgr.createClientPool(context));
Assert.assertSame(pool, context.get(id));
- Assert.assertThat(pools, Matchers.contains(pool));
+ MatcherAssert.assertThat(pools, Matchers.contains(pool));
}
@Test
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestNetClientWrapper.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestNetClientWrapper.java
index 312946da1..1af3eb9fc 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestNetClientWrapper.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestNetClientWrapper.java
@@ -20,6 +20,7 @@ package org.apache.servicecomb.foundation.vertx.client.tcp;
import java.util.ArrayList;
import java.util.List;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -106,6 +107,6 @@ public class TestNetClientWrapper {
socks.add(asyncSocket.result());
});
- Assert.assertThat(socks, Matchers.contains(normalSocket, sslSocket));
+ MatcherAssert.assertThat(socks, Matchers.contains(normalSocket, sslSocket));
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
index f13e59ff7..9f83fea46 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnectionPool.java
@@ -16,13 +16,12 @@
*/
package org.apache.servicecomb.foundation.vertx.client.tcp;
-import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import io.vertx.core.impl.ContextInternal;
import mockit.Mocked;
+import org.junit.jupiter.api.Assertions;
public class TestTcpClientConnectionPool {
@Mocked
@@ -40,6 +39,6 @@ public class TestTcpClientConnectionPool {
@Test
public void create() {
- Assert.assertThat(pool.create("rest://localhost:8765"), Matchers.instanceOf(TcpClientConnection.class));
+ Assertions.assertTrue(pool.create("rest://localhost:8765") instanceof TcpClientConnection);
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletRequest.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletRequest.java
index c25b38930..c308efb88 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletRequest.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletRequest.java
@@ -17,18 +17,15 @@
package org.apache.servicecomb.foundation.vertx.http;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.Collections;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestAbstractHttpServletRequest {
HttpServletRequest request = new AbstractHttpServletRequest() {
@@ -40,477 +37,408 @@ public class TestAbstractHttpServletRequest {
String value = "abc";
request.setAttribute(key, value);
Assert.assertSame(value, request.getAttribute(key));
- Assert.assertThat(Collections.list(request.getAttributeNames()), Matchers.contains(key));
+ MatcherAssert.assertThat(Collections.list(request.getAttributeNames()), Matchers.contains(key));
request.setAttribute("a2", "v");
- Assert.assertThat(Collections.list(request.getAttributeNames()), Matchers.contains(key, "a2"));
+ MatcherAssert.assertThat(Collections.list(request.getAttributeNames()), Matchers.contains(key, "a2"));
request.removeAttribute(key);
Assert.assertNull(request.getAttribute(key));
}
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private void setExceptionExpected() {
- expectedException.expect(Error.class);
- expectedException.expectMessage(Matchers.is("not supported method"));
+ private void checkError(Error error) {
+ Assertions.assertEquals("not supported method", error.getMessage());
}
@Test
public void testGetCharacterEncoding() {
- setExceptionExpected();
-
- request.getCharacterEncoding();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getCharacterEncoding());
+ checkError(error);
}
@Test
- public void testSetCharacterEncoding() throws UnsupportedEncodingException {
- setExceptionExpected();
-
- request.setCharacterEncoding("");
+ public void testSetCharacterEncoding() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.setCharacterEncoding(""));
+ checkError(error);
}
@Test
public void testGetContentLength() {
- setExceptionExpected();
-
- request.getContentLength();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getContentLength());
+ checkError(error);
}
@Test
public void testGetContentLengthLong() {
- setExceptionExpected();
-
- request.getContentLengthLong();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getContentLengthLong());
+ checkError(error);
}
@Test
public void testGetContentType() {
- setExceptionExpected();
-
- request.getContentType();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getContentType());
+ checkError(error);
}
@Test
- public void testGetInputStream() throws IOException {
- setExceptionExpected();
-
- request.getInputStream();
+ public void testGetInputStream() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.getInputStream());
+ checkError(error);
}
@Test
public void testGetParameter() {
- setExceptionExpected();
-
- request.getParameter("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getParameter(""));
+ checkError(error);
}
@Test
public void testGetParameterNames() {
- setExceptionExpected();
-
- request.getParameterNames();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getParameterNames());
+ checkError(error);
}
@Test
public void testGetParameterValues() {
- setExceptionExpected();
-
- request.getParameterValues("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getParameterValues(""));
+ checkError(error);
}
@Test
public void testGetParameterMap() {
- setExceptionExpected();
-
- request.getParameterMap();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getParameterMap());
+ checkError(error);
}
@Test
public void testGetProtocol() {
- setExceptionExpected();
-
- request.getProtocol();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getProtocol());
+ checkError(error);
}
@Test
public void testGetScheme() {
- setExceptionExpected();
-
- request.getScheme();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getScheme());
+ checkError(error);
}
@Test
public void testGetServerName() {
- setExceptionExpected();
-
- request.getServerName();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getServerName());
+ checkError(error);
}
@Test
public void testGetServerPort() {
- setExceptionExpected();
-
- request.getServerPort();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getServerPort());
+ checkError(error);
}
@Test
- public void testGetReader() throws IOException {
- setExceptionExpected();
-
- request.getReader();
+ public void testGetReader() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.getReader());
+ checkError(error);
}
@Test
public void testGetRemoteAddr() {
- setExceptionExpected();
-
- request.getRemoteAddr();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRemoteAddr());
+ checkError(error);
}
@Test
public void testGetRemoteHost() {
- setExceptionExpected();
-
- request.getRemoteHost();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRemoteHost());
+ checkError(error);
}
@Test
public void testGetLocale() {
- setExceptionExpected();
-
- request.getLocale();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getLocale());
+ checkError(error);
}
@Test
public void testGetLocales() {
- setExceptionExpected();
-
- request.getLocales();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getLocales());
+ checkError(error);
}
@Test
public void testIsSecure() {
- setExceptionExpected();
-
- request.isSecure();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isSecure());
+ checkError(error);
}
@Test
public void testGetRequestDispatcher() {
- setExceptionExpected();
-
- request.getRequestDispatcher("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRequestDispatcher(""));
+ checkError(error);
}
@SuppressWarnings("deprecation")
@Test
public void testGetRealPath() {
- setExceptionExpected();
-
- request.getRealPath("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRealPath(""));
+ checkError(error);
}
@Test
public void testGetRemotePort() {
- setExceptionExpected();
-
- request.getRemotePort();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRemotePort());
+ checkError(error);
}
@Test
public void testGetLocalName() {
- setExceptionExpected();
-
- request.getLocalName();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getLocalName());
+ checkError(error);
}
@Test
public void testGetLocalAddr() {
- setExceptionExpected();
-
- request.getLocalAddr();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getLocalAddr());
+ checkError(error);
}
@Test
public void testGetLocalPort() {
- setExceptionExpected();
-
- request.getLocalPort();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getLocalPort());
+ checkError(error);
}
@Test
public void testGetServletContext() {
- setExceptionExpected();
-
- request.getServletContext();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getServletContext());
+ checkError(error);
}
@Test
public void testStartAsync() {
- setExceptionExpected();
-
- request.startAsync();
+ Error error = Assertions.assertThrows(Error.class, () -> request.startAsync());
+ checkError(error);
}
@Test
public void testStartAsyncWithParam() {
- setExceptionExpected();
-
- request.startAsync(null, null);
+ Error error = Assertions.assertThrows(Error.class, () -> request.startAsync(null, null));
+ checkError(error);
}
@Test
public void testIsAsyncStarted() {
- setExceptionExpected();
-
- request.isAsyncStarted();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isAsyncStarted());
+ checkError(error);
}
@Test
public void testIsAsyncSupported() {
- setExceptionExpected();
-
- request.isAsyncSupported();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isAsyncSupported());
+ checkError(error);
}
@Test
public void testGetAsyncContext() {
- setExceptionExpected();
-
- request.getAsyncContext();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getAsyncContext());
+ checkError(error);
}
@Test
public void testGetDispatcherType() {
- setExceptionExpected();
-
- request.getDispatcherType();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getDispatcherType());
+ checkError(error);
}
@Test
public void testGetAuthType() {
- setExceptionExpected();
-
- request.getAuthType();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getAuthType());
+ checkError(error);
}
@Test
public void testGetCookies() {
- setExceptionExpected();
-
- request.getCookies();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getCookies());
+ checkError(error);
}
@Test
public void testGetDateHeader() {
- setExceptionExpected();
-
- request.getDateHeader("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getDateHeader(""));
+ checkError(error);
}
@Test
public void testGetHeader() {
- setExceptionExpected();
-
- request.getHeader("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getHeader(""));
+ checkError(error);
}
@Test
public void testGetHeaders() {
- setExceptionExpected();
-
- request.getHeaders("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getHeaders(""));
+ checkError(error);
}
@Test
public void testGetHeaderNames() {
- setExceptionExpected();
-
- request.getHeaderNames();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getHeaderNames());
+ checkError(error);
}
@Test
public void testGetIntHeader() {
- setExceptionExpected();
-
- request.getIntHeader("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.getIntHeader(""));
+ checkError(error);
}
@Test
public void testGetMethod() {
- setExceptionExpected();
-
- request.getMethod();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getMethod());
+ checkError(error);
}
@Test
public void testGetPathInfo() {
- setExceptionExpected();
-
- request.getPathInfo();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getPathInfo());
+ checkError(error);
}
@Test
public void testGetPathTranslated() {
- setExceptionExpected();
-
- request.getPathTranslated();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getPathTranslated());
+ checkError(error);
}
@Test
public void testGetContextPath() {
- setExceptionExpected();
-
- request.getContextPath();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getContextPath());
+ checkError(error);
}
@Test
public void testGetQueryString() {
- setExceptionExpected();
-
- request.getQueryString();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getQueryString());
+ checkError(error);
}
@Test
public void testGetRemoteUser() {
- setExceptionExpected();
-
- request.getRemoteUser();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRemoteUser());
+ checkError(error);
}
@Test
public void testIsUserInRole() {
- setExceptionExpected();
-
- request.isUserInRole("");
+ Error error = Assertions.assertThrows(Error.class, () -> request.isUserInRole(""));
+ checkError(error);
}
@Test
public void testGetUserPrincipal() {
- setExceptionExpected();
-
- request.getUserPrincipal();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getUserPrincipal());
+ checkError(error);
}
@Test
public void testGetRequestedSessionId() {
- setExceptionExpected();
-
- request.getRequestedSessionId();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRequestedSessionId());
+ checkError(error);
}
@Test
public void testGetRequestURI() {
- setExceptionExpected();
-
- request.getRequestURI();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRequestURI());
+ checkError(error);
}
@Test
public void testGetRequestURL() {
- setExceptionExpected();
-
- request.getRequestURL();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getRequestURL());
+ checkError(error);
}
@Test
public void testGetServletPath() {
- setExceptionExpected();
-
- request.getServletPath();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getServletPath());
+ checkError(error);
}
@Test
public void testGetSessionWithParam() {
- setExceptionExpected();
-
- request.getSession(true);
+ Error error = Assertions.assertThrows(Error.class, () -> request.getSession(true));
+ checkError(error);
}
@Test
public void testGetSession() {
- setExceptionExpected();
-
- request.getSession();
+ Error error = Assertions.assertThrows(Error.class, () -> request.getSession());
+ checkError(error);
}
@Test
public void testChangeSessionId() {
- setExceptionExpected();
-
- request.changeSessionId();
+ Error error = Assertions.assertThrows(Error.class, () -> request.changeSessionId());
+ checkError(error);
}
@Test
public void testIsRequestedSessionIdValid() {
- setExceptionExpected();
-
- request.isRequestedSessionIdValid();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isRequestedSessionIdValid());
+ checkError(error);
}
@Test
public void testIsRequestedSessionIdFromCookie() {
- setExceptionExpected();
-
- request.isRequestedSessionIdFromCookie();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isRequestedSessionIdFromCookie());
+ checkError(error);
}
@Test
public void testIsRequestedSessionIdFromURL() {
- setExceptionExpected();
-
- request.isRequestedSessionIdFromURL();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isRequestedSessionIdFromURL());
+ checkError(error);
}
@SuppressWarnings("deprecation")
@Test
public void testIsRequestedSessionIdFromUrl() {
- setExceptionExpected();
-
- request.isRequestedSessionIdFromUrl();
+ Error error = Assertions.assertThrows(Error.class, () -> request.isRequestedSessionIdFromUrl());
+ checkError(error);
}
@Test
- public void testAuthenticate() throws IOException, ServletException {
- setExceptionExpected();
-
- request.authenticate(null);
+ public void testAuthenticate() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.authenticate(null));
+ checkError(error);
}
@Test
- public void testLogin() throws ServletException {
- setExceptionExpected();
-
- request.login(null, null);
+ public void testLogin() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.login(null, null));
+ checkError(error);
}
@Test
- public void testLogout() throws ServletException {
- setExceptionExpected();
-
- request.logout();
+ public void testLogout() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.logout());
+ checkError(error);
}
@Test
- public void testGetParts() throws IOException, ServletException {
- setExceptionExpected();
-
- request.getParts();
+ public void testGetParts() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.getParts());
+ checkError(error);
}
@Test
- public void testGetPart() throws IOException, ServletException {
- setExceptionExpected();
-
- request.getPart("");
+ public void testGetPart() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.getPart(""));
+ checkError(error);
}
@Test
- public void testUpgrade() throws IOException, ServletException {
- setExceptionExpected();
-
- request.upgrade(null);
+ public void testUpgrade() {
+ Error error = Assertions.assertThrows(Error.class, () -> request.upgrade(null));
+ checkError(error);
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletResponse.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletResponse.java
index ec884eeea..2e185dc2c 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletResponse.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletResponse.java
@@ -17,294 +17,252 @@
package org.apache.servicecomb.foundation.vertx.http;
-import java.io.IOException;
-
-import org.hamcrest.Matchers;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
+import org.junit.jupiter.api.Assertions;
public class TestAbstractHttpServletResponse {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
HttpServletResponseEx response = new AbstractHttpServletResponse() {
};
- private void setExceptionExpected() {
- expectedException.expect(Error.class);
- expectedException.expectMessage(Matchers.is("not supported method"));
+ private void checkError(Error error) {
+ Assertions.assertEquals("not supported method", error.getMessage());
}
@Test
public void testGetCharacterEncoding() {
- setExceptionExpected();
-
- response.getCharacterEncoding();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getCharacterEncoding());
+ checkError(error);
}
@Test
public void testGetContentType() {
- setExceptionExpected();
-
- response.getContentType();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getContentType());
+ checkError(error);
}
@Test
- public void testGetOutputStream() throws IOException {
- setExceptionExpected();
-
- response.getOutputStream();
+ public void testGetOutputStream() {
+ Error error = Assertions.assertThrows(Error.class, () -> response.getOutputStream());
+ checkError(error);
}
@Test
- public void testGetWriter() throws IOException {
- setExceptionExpected();
-
- response.getWriter();
+ public void testGetWriter() {
+ Error error = Assertions.assertThrows(Error.class, () -> response.getWriter());
+ checkError(error);
}
@Test
public void testSetCharacterEncoding() {
- setExceptionExpected();
-
- response.setCharacterEncoding("");
+ Error error = Assertions.assertThrows(Error.class, () -> response.setCharacterEncoding(""));
+ checkError(error);
}
@Test
public void testSetContentLength() {
- setExceptionExpected();
-
- response.setContentLength(0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setContentLength(0));
+ checkError(error);
}
@Test
public void testSetContentLengthLong() {
- setExceptionExpected();
-
- response.setContentLengthLong(0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setContentLengthLong(0));
+ checkError(error);
}
@Test
public void testSetContentType() {
- setExceptionExpected();
-
- response.setContentType("");
+ Error error = Assertions.assertThrows(Error.class, () -> response.setContentType(""));
+ checkError(error);
}
@Test
public void testSetBufferSize() {
- setExceptionExpected();
-
- response.setBufferSize(0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setBufferSize(0));
+ checkError(error);
}
@Test
public void testGetBufferSize() {
- setExceptionExpected();
-
- response.getBufferSize();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getBufferSize());
+ checkError(error);
}
@Test
- public void testFlushBuffer() throws IOException {
- setExceptionExpected();
-
- response.flushBuffer();
+ public void testFlushBuffer() {
+ Error error = Assertions.assertThrows(Error.class, () -> {
+ response.flushBuffer();
+ });
+ checkError(error);
}
@Test
public void testResetBuffer() {
- setExceptionExpected();
-
- response.resetBuffer();
+ Error error = Assertions.assertThrows(Error.class, () -> response.resetBuffer());
+ checkError(error);
}
@Test
public void testIsCommitted() {
- setExceptionExpected();
-
- response.isCommitted();
+ Error error = Assertions.assertThrows(Error.class, () -> response.isCommitted());
+ checkError(error);
}
@Test
public void testReset() {
- setExceptionExpected();
-
- response.reset();
+ Error error = Assertions.assertThrows(Error.class, () -> response.reset());
+ checkError(error);
}
@Test
public void testSetLocale() {
- setExceptionExpected();
-
- response.setLocale(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setLocale(null));
+ checkError(error);
}
@Test
public void testGetLocale() {
- setExceptionExpected();
-
- response.getLocale();
+ Error error = Assertions.assertThrows(Error.class, () -> {
+ response.getLocale();
+ });
+ checkError(error);
}
@Test
public void testAddCookie() {
- setExceptionExpected();
-
- response.addCookie(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.addCookie(null));
+ checkError(error);
}
@Test
public void testContainsHeader() {
- setExceptionExpected();
-
- response.containsHeader(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.containsHeader(null));
+ checkError(error);
}
@Test
public void testEncodeURL() {
- setExceptionExpected();
-
- response.encodeURL(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.encodeURL(null));
+ checkError(error);
}
@Test
public void testEncodeRedirectURL() {
- setExceptionExpected();
-
- response.encodeRedirectURL(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.encodeRedirectURL(null));
+ checkError(error);
}
@SuppressWarnings("deprecation")
@Test
public void testEncodeUrl() {
- setExceptionExpected();
-
- response.encodeUrl(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.encodeUrl(null));
+ checkError(error);
}
@SuppressWarnings("deprecation")
@Test
public void testEncodeRedirectUrl() {
- setExceptionExpected();
-
- response.encodeRedirectUrl(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.encodeRedirectUrl(null));
+ checkError(error);
}
@Test
- public void testSendErrorScAndMsg() throws IOException {
- setExceptionExpected();
-
- response.sendError(0, null);
+ public void testSendErrorScAndMsg() {
+ Error error = Assertions.assertThrows(Error.class, () -> response.sendError(0, null));
+ checkError(error);
}
@Test
- public void testSendErrorSc() throws IOException {
- setExceptionExpected();
-
- response.sendError(0);
+ public void testSendErrorSc() {
+ Error error = Assertions.assertThrows(Error.class, () -> response.sendError(0));
+ checkError(error);
}
@Test
- public void testSendRedirect() throws IOException {
- setExceptionExpected();
-
- response.sendRedirect(null);
+ public void testSendRedirect() {
+ Error error = Assertions.assertThrows(Error.class, () -> response.sendRedirect(null));
+ checkError(error);
}
@Test
public void testSetDateHeader() {
- setExceptionExpected();
-
- response.setDateHeader(null, 0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setDateHeader(null, 0));
+ checkError(error);
}
@Test
public void testAddDateHeader() {
- setExceptionExpected();
-
- response.addDateHeader(null, 0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.addDateHeader(null, 0));
+ checkError(error);
}
@Test
public void testSetHeader() {
- setExceptionExpected();
-
- response.setHeader(null, null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setHeader(null, null));
+ checkError(error);
}
@Test
public void testAddHeader() {
- setExceptionExpected();
-
- response.addHeader(null, null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.addHeader(null, null));
+ checkError(error);
}
@Test
public void testSetIntHeader() {
- setExceptionExpected();
-
- response.setIntHeader(null, 0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setIntHeader(null, 0));
+ checkError(error);
}
@Test
public void testAddIntHeader() {
- setExceptionExpected();
-
- response.addIntHeader(null, 0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.addIntHeader(null, 0));
+ checkError(error);
}
@Test
public void testSetStatusSc() {
- setExceptionExpected();
-
- response.setStatus(0);
+ Error error = Assertions.assertThrows(Error.class, () -> response.setStatus(0));
+ checkError(error);
}
@SuppressWarnings("deprecation")
@Test
public void testSetStatusScAndSm() {
- setExceptionExpected();
-
- response.setStatus(0, "");
+ Error error = Assertions.assertThrows(Error.class, () -> response.setStatus(0, ""));
+ checkError(error);
}
@Test
public void testGetStatus() {
- setExceptionExpected();
-
- response.getStatus();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getStatus());
+ checkError(error);
}
@Test
public void testGetHeader() {
- setExceptionExpected();
-
- response.getHeader("");
+ Error error = Assertions.assertThrows(Error.class, () -> response.getHeader(""));
+ checkError(error);
}
@Test
public void testGetHeaders() {
- setExceptionExpected();
-
- response.getHeaders("");
+ Error error = Assertions.assertThrows(Error.class, () -> response.getHeaders(""));
+ checkError(error);
}
@Test
public void testGetHeaderNames() {
- setExceptionExpected();
-
- response.getHeaderNames();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getHeaderNames());
+ checkError(error);
}
@Test
public void testGetStatusType() {
- setExceptionExpected();
-
- response.getStatusType();
+ Error error = Assertions.assertThrows(Error.class, () -> response.getStatusType());
+ checkError(error);
}
@Test
@@ -315,8 +273,7 @@ public class TestAbstractHttpServletResponse {
@Test
public void sendPart() {
- setExceptionExpected();
-
- response.sendPart(null);
+ Error error = Assertions.assertThrows(Error.class, () -> response.sendPart(null));
+ checkError(error);
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestReadStreamPart.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestReadStreamPart.java
index 50c151da2..c07648d89 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestReadStreamPart.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestReadStreamPart.java
@@ -29,13 +29,11 @@ import javax.ws.rs.core.HttpHeaders;
import org.apache.commons.io.FileUtils;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream;
-import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
@@ -64,9 +62,6 @@ public class TestReadStreamPart {
ReadStreamPart part = new ReadStreamPart(context, readStream);
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setup() throws IOException {
context.setOwner((VertxInternal)vertx);
@@ -147,15 +142,14 @@ public class TestReadStreamPart {
}
}.getMockInstance();
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.sameInstance(error));
-
- part.saveToWriteStream(writeStream).get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> {
+ part.saveToWriteStream(writeStream).get();
+ });
+ Assertions.assertTrue(exception.getCause() instanceof RuntimeException);
}
@Test
- public void saveToWrite_readException(@Mocked WriteStream<Buffer> writeStream)
- throws InterruptedException, ExecutionException {
+ public void saveToWrite_readException(@Mocked WriteStream<Buffer> writeStream) {
RuntimeException error = new RuntimeExceptionWithoutStackTrace();
new MockUp<InputStream>(inputStream) {
@Mock
@@ -164,10 +158,10 @@ public class TestReadStreamPart {
}
};
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.sameInstance(error));
-
- part.saveToWriteStream(writeStream).get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> {
+ part.saveToWriteStream(writeStream).get();
+ });
+ Assertions.assertTrue(exception.getCause() instanceof RuntimeException);
}
@Test
@@ -202,10 +196,10 @@ public class TestReadStreamPart {
Assert.assertFalse(dir.exists());
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.instanceOf(FileSystemException.class));
-
- OpenOptions openOptions = new OpenOptions().setCreateNew(false);
- part.saveToFile(file, openOptions).get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> {
+ OpenOptions openOptions = new OpenOptions().setCreateNew(false);
+ part.saveToFile(file, openOptions).get();
+ });
+ Assertions.assertTrue(exception.getCause() instanceof FileSystemException);
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
index 3486d3ee4..10a5a7d39 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.MediaType;
import org.apache.commons.io.IOUtils;
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -104,7 +105,7 @@ public class TestStandardHttpServletRequestEx {
};
Assert.assertSame(inherited, requestEx.getParameterMap());
- Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1"));
+ MatcherAssert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1"));
Assert.assertSame(v1, requestEx.getParameterValues("p1"));
Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}
@@ -130,8 +131,8 @@ public class TestStandardHttpServletRequestEx {
}
};
- Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1", "p2"));
- Assert.assertThat(requestEx.getParameterValues("p1"), Matchers.arrayContaining("v1-1", "v1-2", "v1-3"));
+ MatcherAssert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1", "p2"));
+ MatcherAssert.assertThat(requestEx.getParameterValues("p1"), Matchers.arrayContaining("v1-1", "v1-2", "v1-3"));
Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}
@@ -148,6 +149,6 @@ public class TestStandardHttpServletRequestEx {
Assert.assertSame(parameterMap, requestEx.getParameterMap());
- Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("k1", "k2"));
+ MatcherAssert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("k1", "k2"));
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
index beebcddf3..7e3c5856f 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletResponseEx.java
@@ -29,12 +29,10 @@ import javax.servlet.http.Part;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.servicecomb.foundation.common.part.InputStreamPart;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
-import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.vertx.core.buffer.Buffer;
import mockit.Expectations;
@@ -48,9 +46,6 @@ public class TestStandardHttpServletResponseEx {
StandardHttpServletResponseEx responseEx;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setup() {
responseEx = new StandardHttpServletResponseEx(response);
@@ -168,8 +163,8 @@ public class TestStandardHttpServletResponseEx {
}
};
- expectedException.expect(Matchers.sameInstance(error));
-
- responseEx.sendPart(part).get();
+ Assertions.assertThrows(RuntimeException.class, () -> {
+ responseEx.sendPart(part).get();
+ });
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientRequestToHttpServletRequest.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientRequestToHttpServletRequest.java
index 41536970f..0c15700b2 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientRequestToHttpServletRequest.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientRequestToHttpServletRequest.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import javax.ws.rs.core.HttpHeaders;
import org.apache.servicecomb.foundation.common.http.HttpUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -96,7 +97,7 @@ public class TestVertxClientRequestToHttpServletRequest {
}
};
- Assert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
}
@Test
@@ -110,7 +111,7 @@ public class TestVertxClientRequestToHttpServletRequest {
}
};
- Assert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
}
@Test
@@ -125,7 +126,7 @@ public class TestVertxClientRequestToHttpServletRequest {
request.setHeader("name", "v1");
request.setHeader("name", "v2");
- Assert.assertThat(headers.getAll("name"), Matchers.contains("v2"));
+ MatcherAssert.assertThat(headers.getAll("name"), Matchers.contains("v2"));
}
@Test
@@ -140,7 +141,7 @@ public class TestVertxClientRequestToHttpServletRequest {
request.addHeader("name", "v1");
request.addHeader("name", "v2");
- Assert.assertThat(headers.getAll("name"), Matchers.contains("v1", "v2"));
+ MatcherAssert.assertThat(headers.getAll("name"), Matchers.contains("v1", "v2"));
}
@Test
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientResponseToHttpServletResponse.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientResponseToHttpServletResponse.java
index 5d38fa3cc..9618ed8d5 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientResponseToHttpServletResponse.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxClientResponseToHttpServletResponse.java
@@ -20,6 +20,7 @@ package org.apache.servicecomb.foundation.vertx.http;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response.StatusType;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -109,7 +110,7 @@ public class TestVertxClientResponseToHttpServletResponse {
}
};
- Assert.assertThat(response.getHeaders("name"), Matchers.contains("v1", "v2"));
+ MatcherAssert.assertThat(response.getHeaders("name"), Matchers.contains("v1", "v2"));
}
@Test
@@ -124,6 +125,6 @@ public class TestVertxClientResponseToHttpServletResponse {
}
};
- Assert.assertThat(response.getHeaderNames(), Matchers.contains("n1", "n2"));
+ MatcherAssert.assertThat(response.getHeaderNames(), Matchers.contains("n1", "n2"));
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
index e51c99fee..4740bc3fd 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
@@ -30,6 +30,7 @@ import javax.ws.rs.core.HttpHeaders;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.http.HttpUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -165,7 +166,7 @@ public class TestVertxServerRequestToHttpServletRequest {
}
};
- Assert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
+ MatcherAssert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
}
@Test
@@ -181,8 +182,8 @@ public class TestVertxServerRequestToHttpServletRequest {
};
Map<String, String[]> result = request.getParameterMap();
- Assert.assertThat(result.keySet(), Matchers.contains("name"));
- Assert.assertThat(result.get("name"), Matchers.arrayContaining("value"));
+ MatcherAssert.assertThat(result.keySet(), Matchers.contains("name"));
+ MatcherAssert.assertThat(result.get("name"), Matchers.arrayContaining("value"));
Assert.assertSame(result, request.getParameterMap());
}
@@ -218,7 +219,7 @@ public class TestVertxServerRequestToHttpServletRequest {
result = null;
}
};
- Assert.assertEquals(null, request.getRemoteAddr());
+ Assert.assertNull(request.getRemoteAddr());
}
@Test
@@ -296,7 +297,7 @@ public class TestVertxServerRequestToHttpServletRequest {
}
};
- Assert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
}
@Test
@@ -310,7 +311,7 @@ public class TestVertxServerRequestToHttpServletRequest {
}
};
- Assert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
}
@Test
@@ -472,6 +473,6 @@ public class TestVertxServerRequestToHttpServletRequest {
Assert.assertSame(parameterMap, request.getParameterMap());
- Assert.assertThat(Collections.list(request.getParameterNames()), Matchers.contains("k1", "k2"));
+ MatcherAssert.assertThat(Collections.list(request.getParameterNames()), Matchers.contains("k1", "k2"));
}
}
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerResponseToHttpServletResponse.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerResponseToHttpServletResponse.java
index da1d9d258..78a20bc7e 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerResponseToHttpServletResponse.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerResponseToHttpServletResponse.java
@@ -33,12 +33,12 @@ import org.apache.commons.io.FileUtils;
import org.apache.servicecomb.foundation.common.http.HttpStatus;
import org.apache.servicecomb.foundation.common.part.FilePart;
import org.apache.servicecomb.foundation.vertx.stream.PumpFromPart;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
@@ -75,9 +75,6 @@ public class TestVertxServerResponseToHttpServletResponse {
@Mocked
Context context;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
boolean chunked;
@Before
@@ -176,10 +173,10 @@ public class TestVertxServerResponseToHttpServletResponse {
}
};
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage(Matchers.is("must run in vertx context."));
-
- new VertxServerResponseToHttpServletResponse(serverResponse);
+ NullPointerException exception = Assertions.assertThrows(NullPointerException.class, () -> {
+ new VertxServerResponseToHttpServletResponse(serverResponse);
+ });
+ Assertions.assertEquals("must run in vertx context.", exception.getMessage());
}
@Test
@@ -212,8 +209,8 @@ public class TestVertxServerResponseToHttpServletResponse {
response.addHeader("n2", "v2");
Assert.assertEquals(2, headers.size());
- Assert.assertThat(headers.getAll("n1"), Matchers.contains("v1_1", "v1_2"));
- Assert.assertThat(headers.getAll("n2"), Matchers.contains("v2"));
+ MatcherAssert.assertThat(headers.getAll("n1"), Matchers.contains("v1_1", "v1_2"));
+ MatcherAssert.assertThat(headers.getAll("n2"), Matchers.contains("v2"));
}
@Test
@@ -223,8 +220,8 @@ public class TestVertxServerResponseToHttpServletResponse {
response.setHeader("n2", "v2");
Assert.assertEquals(2, headers.size());
- Assert.assertThat(headers.getAll("n1"), Matchers.contains("v1_2"));
- Assert.assertThat(headers.getAll("n2"), Matchers.contains("v2"));
+ MatcherAssert.assertThat(headers.getAll("n1"), Matchers.contains("v1_2"));
+ MatcherAssert.assertThat(headers.getAll("n2"), Matchers.contains("v2"));
}
@Test
@@ -249,7 +246,7 @@ public class TestVertxServerResponseToHttpServletResponse {
headers.add("h1", "h1_1");
headers.add("h1", "h1_2");
- Assert.assertThat(response.getHeaders("h1"), Matchers.contains("h1_1", "h1_2"));
+ MatcherAssert.assertThat(response.getHeaders("h1"), Matchers.contains("h1_1", "h1_2"));
}
@Test
@@ -257,7 +254,7 @@ public class TestVertxServerResponseToHttpServletResponse {
headers.add("h1", "h1");
headers.add("h2", "h2");
- Assert.assertThat(response.getHeaderNames(), Matchers.contains("h1", "h2"));
+ MatcherAssert.assertThat(response.getHeaderNames(), Matchers.contains("h1", "h2"));
}
@Test
@@ -329,7 +326,7 @@ public class TestVertxServerResponseToHttpServletResponse {
@Test
public void sendPart_openInputStreamFailed(@Mocked Part part)
- throws IOException, InterruptedException, ExecutionException {
+ throws IOException {
IOException ioException = new IOException("forbid open stream");
new Expectations() {
{
@@ -340,10 +337,8 @@ public class TestVertxServerResponseToHttpServletResponse {
CompletableFuture<Void> future = response.sendPart(part);
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.sameInstance(ioException));
-
- future.get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, future::get);
+ Assertions.assertTrue(exception.getCause() instanceof IOException);
}
@Test
@@ -354,7 +349,7 @@ public class TestVertxServerResponseToHttpServletResponse {
@Test
public void sendPart_inputStreamBreak(@Mocked Part part, @Mocked InputStream inputStream)
- throws IOException, InterruptedException, ExecutionException {
+ throws IOException {
IOException ioException = new IOException("forbid read");
new Expectations() {
{
@@ -367,10 +362,8 @@ public class TestVertxServerResponseToHttpServletResponse {
CompletableFuture<Void> future = response.sendPart(part);
- expectedException.expect(ExecutionException.class);
- expectedException.expectCause(Matchers.sameInstance(ioException));
-
- future.get();
+ ExecutionException exception = Assertions.assertThrows(ExecutionException.class, future::get);
+ Assertions.assertTrue(exception.getCause() instanceof IOException);
}
@Test
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
index befcc2e71..49bbcae6d 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpFromPart.java
@@ -28,6 +28,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.servicecomb.foundation.common.part.InputStreamPart;
import org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream.ReadResult;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -109,8 +110,8 @@ public class TestPumpFromPart {
run(context, true);
Assert.fail("must throw exception");
} catch (Throwable e) {
- Assert.assertThat(e, Matchers.instanceOf(ExecutionException.class));
- Assert.assertThat(e.getCause(), Matchers.sameInstance(error));
+ MatcherAssert.assertThat(e, Matchers.instanceOf(ExecutionException.class));
+ MatcherAssert.assertThat(e.getCause(), Matchers.sameInstance(error));
}
Assert.assertTrue(inputStreamClosed);
diff --git a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestConsumerQpsFlowControlHandler.java b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestConsumerQpsFlowControlHandler.java
index e346c86a9..a0242393b 100644
--- a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestConsumerQpsFlowControlHandler.java
+++ b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestConsumerQpsFlowControlHandler.java
@@ -32,9 +32,7 @@ import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -52,9 +50,6 @@ public class TestConsumerQpsFlowControlHandler {
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setUP() {
ArchaiusUtils.resetConfig();
diff --git a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestProviderQpsFlowControlHandler.java b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestProviderQpsFlowControlHandler.java
index 0328d545a..546a9bb53 100644
--- a/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestProviderQpsFlowControlHandler.java
+++ b/handlers/handler-flowcontrol-qps/src/test/java/org/apache/servicecomb/qps/TestProviderQpsFlowControlHandler.java
@@ -33,9 +33,8 @@ import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -51,9 +50,6 @@ public class TestProviderQpsFlowControlHandler {
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setUP() {
ArchaiusUtils.resetConfig();
@@ -89,11 +85,11 @@ public class TestProviderQpsFlowControlHandler {
ArchaiusUtils.setProperty(Config.PROVIDER_LIMIT_KEY_GLOBAL, 3);
- expectedException.expect(RuntimeException.class);
- expectedException.expectMessage("test error");
-
- gHandler.handle(invocation, asyncResp);
- gHandler.handle(invocation, asyncResp);
+ RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> {
+ gHandler.handle(invocation, asyncResp);
+ gHandler.handle(invocation, asyncResp);
+ });
+ Assertions.assertEquals("test error", exception.getMessage());
}
@Test
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadbalanceHandler.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadbalanceHandler.java
index 026fd94af..d608f88ad 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadbalanceHandler.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadbalanceHandler.java
@@ -22,8 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
import javax.ws.rs.core.Response.Status;
@@ -38,17 +36,13 @@ import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.cache.CacheEndpoint;
-import org.apache.servicecomb.registry.cache.InstanceCacheManager;
import org.apache.servicecomb.registry.discovery.DiscoveryFilter;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.Response;
-import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import com.netflix.loadbalancer.LoadBalancerStats;
@@ -66,14 +60,10 @@ import mockit.Mocked;
public class TestLoadbalanceHandler {
static SCBEngine scbEngine;
- static InstanceCacheManager instanceCacheManager;
-
static TransportManager transportManager;
String microserviceName = "ms";
-// IRule rule = Mockito.mock(IRule.class);
-
LoadbalanceHandler handler;
Map<String, LoadBalancer> loadBalancerMap;
@@ -86,11 +76,6 @@ public class TestLoadbalanceHandler {
Response sendResponse;
-// List<String> results = new ArrayList<>();
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setUp() {
ConfigUtil.installDynamicConfig();
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/IsolationDiscoveryFilterTest.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/IsolationDiscoveryFilterTest.java
index f2ad8c60e..5f573f85a 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/IsolationDiscoveryFilterTest.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/filter/IsolationDiscoveryFilterTest.java
@@ -32,6 +32,7 @@ import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.cache.CacheEndpoint;
import org.apache.servicecomb.registry.discovery.DiscoveryContext;
import org.apache.servicecomb.registry.discovery.DiscoveryTreeNode;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -96,7 +97,7 @@ public class IsolationDiscoveryFilterTest {
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -110,7 +111,7 @@ public class IsolationDiscoveryFilterTest {
}
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -121,7 +122,7 @@ public class IsolationDiscoveryFilterTest {
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
Assert.assertTrue(ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server0).isIsolated());
@@ -142,7 +143,7 @@ public class IsolationDiscoveryFilterTest {
Assert.assertNull(TestServiceCombServerStats.getTryingIsolatedServerInvocation());
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -167,7 +168,7 @@ public class IsolationDiscoveryFilterTest {
// The first invocation can occupy the trying chance
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -176,7 +177,7 @@ public class IsolationDiscoveryFilterTest {
// Other invocation cannot get trying chance concurrently
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -186,7 +187,7 @@ public class IsolationDiscoveryFilterTest {
// Other invocation can get the trying chance
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -209,7 +210,7 @@ public class IsolationDiscoveryFilterTest {
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i1", "i2"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -219,7 +220,7 @@ public class IsolationDiscoveryFilterTest {
System.currentTimeMillis() - Configuration.INSTANCE.getMinIsolationTime(invocation.getMicroserviceName()) - 1);
childNode = filter.discovery(discoveryContext, discoveryTreeNode);
childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
@@ -238,7 +239,7 @@ public class IsolationDiscoveryFilterTest {
DiscoveryTreeNode childNode = filter.discovery(discoveryContext, discoveryTreeNode);
Map<String, MicroserviceInstance> childNodeData = childNode.data();
- Assert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
+ MatcherAssert.assertThat(childNodeData.keySet(), Matchers.containsInAnyOrder("i0", "i1", "i2"));
Assert.assertEquals(data.get("i0"), childNodeData.get("i0"));
Assert.assertEquals(data.get("i1"), childNodeData.get("i1"));
Assert.assertEquals(data.get("i2"), childNodeData.get("i2"));
diff --git a/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java b/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
index ffe27ce58..5358bc8b8 100644
--- a/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
+++ b/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.tracing.zipkin;
import static com.seanyinx.github.unit.scaffolding.AssertUtils.expectFailing;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
@@ -28,6 +27,7 @@ import static org.mockito.Mockito.when;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.Response;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -102,7 +102,7 @@ public class ZipkinTracingHandlerTest {
tracingHandler.handle(invocation, asyncResponse);
expectFailing(RuntimeException.class);
} catch (Exception e) {
- assertThat(e, is(exception));
+ MatcherAssert.assertThat(e, is(exception));
}
verify(delegate).onResponse(span, null, exception);
diff --git a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
index d8411bbc6..ff076ad5e 100644
--- a/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
+++ b/inspector/src/test/java/org/apache/servicecomb/inspector/internal/TestInspectorImpl.java
@@ -55,6 +55,7 @@ import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.apache.servicecomb.transport.rest.servlet.ServletRestTransport;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -124,7 +125,7 @@ public class TestInspectorImpl {
@Test
public void getSchemaIds() {
- Assert.assertThat(inspector.getSchemaIds(), Matchers.contains("schema1", "schema2"));
+ MatcherAssert.assertThat(inspector.getSchemaIds(), Matchers.contains("schema1", "schema2"));
}
@Test
@@ -356,7 +357,7 @@ public class TestInspectorImpl {
List<PriorityPropertyView> views = inspector.priorityProperties();
Assert.assertEquals(1, views.size());
- Assert.assertThat(
+ MatcherAssert.assertThat(
views.get(0).getDynamicProperties().stream().map(DynamicPropertyView::getKey).collect(Collectors.toList()),
Matchers.contains("high", "low"));
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/TestApiOperation.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/TestApiOperation.java
index dee269958..f75326230 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/TestApiOperation.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/TestApiOperation.java
@@ -22,6 +22,7 @@ import javax.ws.rs.core.MediaType;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -40,35 +41,35 @@ public class TestApiOperation {
@Test
public void jaxrs_TestMediaType1() {
Operation operation = getOperation("apiOperationJaxrsSchema", "testMediaType1");
- Assert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- Assert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
}
@Test
public void jaxrs_TestMediaType2() {
Operation operation = getOperation("apiOperationJaxrsSchema", "testMediaType2");
- Assert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- Assert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
}
@Test
public void springMVC_TestMediaType1() {
Operation operation = getOperation("apiOperationSpringMVCSchema", "testMediaType1");
- Assert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- Assert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
}
@Test
public void springMVC_TestMediaType2() {
Operation operation = getOperation("apiOperationSpringMVCSchema", "testMediaType2");
- Assert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- Assert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(operation.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(operation.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
}
@Test
public void springMVC_TestSwaggerDefinitionMediaType() {
Swagger swagger = microserviceMeta.findSchemaMeta("apiOperationSpringMVCSchema").getSwagger();
- Assert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- Assert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
}
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAsyncInvoke.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAsyncInvoke.java
index efd89d3c1..fbf68f5df 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAsyncInvoke.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAsyncInvoke.java
@@ -29,6 +29,7 @@ import org.apache.servicecomb.it.Consumers;
import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.apache.servicecomb.it.schema.DefaultJsonValueResponse;
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -52,7 +53,7 @@ public class TestAsyncInvoke {
public void responseEntity_string_intf() {
BiConsumer<ResponseEntity<String>, Throwable> checkLogic = (responseEntity, ex) -> {
Assert.assertEquals(203, responseEntity.getStatusCodeValue());
- Assert.assertThat(responseEntity.getHeaders().get("testH"), Matchers.containsInAnyOrder("testV1", "testV2"));
+ MatcherAssert.assertThat(responseEntity.getHeaders().get("testH"), Matchers.containsInAnyOrder("testV1", "testV2"));
Assert.assertEquals("TestOK", responseEntity.getBody());
Assert.assertNull(ex);
};
@@ -82,7 +83,7 @@ public class TestAsyncInvoke {
public void responseEntity_dataObject_intf() {
BiConsumer<ResponseEntity<DefaultJsonValueResponse>, Throwable> checkLogic = (responseEntity, ex) -> {
Assert.assertEquals(203, responseEntity.getStatusCodeValue());
- Assert.assertThat(responseEntity.getHeaders().get("testH"), Matchers.containsInAnyOrder("testV1", "testV2"));
+ MatcherAssert.assertThat(responseEntity.getHeaders().get("testH"), Matchers.containsInAnyOrder("testV1", "testV2"));
Assert.assertEquals(DefaultJsonValueResponse.class, responseEntity.getBody().getClass());
Assert.assertEquals("TestOK", responseEntity.getBody().getMessage());
Assert.assertEquals(2, responseEntity.getBody().getType());
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
index 7333e70dd..8c33a131c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestVertxTransportConfig.java
@@ -24,6 +24,7 @@ import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
import org.apache.servicecomb.it.Consumers;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.hamcrest.CoreMatchers;
+import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Test;
@@ -87,7 +88,7 @@ public class TestRestVertxTransportConfig {
fail("an exception is expected!");
} catch (InvocationException e) {
// in slow environment, may cause connection close.
- Assert.assertThat(ExceptionUtils.getExceptionMessageWithoutTrace(e),
+ MatcherAssert.assertThat(ExceptionUtils.getExceptionMessageWithoutTrace(e),
CoreMatchers.anyOf(CoreMatchers.containsString("HTTP header is larger than 10000 bytes"),
CoreMatchers.containsString("Connection was closed")));
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestUpload.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestUpload.java
index 76f5b80c7..4dcf93d42 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestUpload.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestUpload.java
@@ -35,6 +35,7 @@ import org.apache.servicecomb.core.invocation.endpoint.EndpointUtils;
import org.apache.servicecomb.it.Consumers;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.assertj.core.api.Condition;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -158,19 +159,6 @@ public class TestUpload {
Assert.assertTrue(containsAll(result, "hello1", "中文 2", "cse3"));
}
-// @Test
-// public void testJarxUploadArrayList1() {
-// Map<String, Object> map = new HashMap<>();
-// ArrayList<FileSystemResource> list = new ArrayList<>();
-// list.add(fileSystemResource1);
-// list.add(fileSystemResource2);
-// map.put("file1", list);
-// map.put("file2", fileSystemResource3);
-// String result = consumersJaxrs.getSCBRestTemplate()
-// .postForObject("/uploadArrayList1", new HttpEntity<>(map), String.class);
-// Assert.assertTrue(containsAll(result, "hello1", "中文 2", "cse3"));
-// }
-
@Test
public void testJarxUpload2() {
Map<String, Object> map = new HashMap<>();
@@ -205,19 +193,6 @@ public class TestUpload {
Assert.assertTrue(containsAll(result, "cse3", "中文 2", message));
}
-// @Test
-// public void testJarxUploadArrayList2() {
-// Map<String, Object> map = new HashMap<>();
-// ArrayList<FileSystemResource> list = new ArrayList<>();
-// list.add(fileSystemResource2);
-// list.add(fileSystemResource3);
-// map.put("file1", list);
-// map.put("message", message);
-// String result = consumersJaxrs.getSCBRestTemplate()
-// .postForObject("/uploadArrayList2", new HttpEntity<>(map), String.class);
-// Assert.assertTrue(containsAll(result, "cse3", "中文 2", message));
-// }
-
@Test
public void testJarxUploadMix() {
Map<String, Object> map = new HashMap<>();
@@ -281,27 +256,6 @@ public class TestUpload {
Assert.assertTrue(containsAll(result, "hello1", "cse4", "cse3", "中文 2", message));
}
-// @Test
-// public void testFileUploadArrayList() {
-// ITJUnitUtils.initForDebug("it-producer", "rest");
-//
-// Map<String, Object> map = new HashMap<>();
-// ArrayList<FileSystemResource> list1 = new ArrayList<>();
-// ArrayList<FileSystemResource> list2 = new ArrayList<>();
-// list1.add(fileSystemResource1);
-// list1.add(fileSystemResource2);
-// list2.add(fileSystemResource3);
-// list2.add(fileSystemResource4);
-// map.put("file1", list1);
-// map.put("file2", list2);
-// map.put("name", message);
-// HttpHeaders headers = new HttpHeaders();
-// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
-// String result = consumersSpringmvc.getSCBRestTemplate()
-// .postForObject("/uploadArrayList", new HttpEntity<>(map, headers), String.class);
-// Assert.assertTrue(containsAll(result, "hello1", "cse4", "cse3", "中文 2", message));
-// }
-
@Test
public void testFileUploadWithoutAnnotation() {
Map<String, Object> map = new HashMap<>();
@@ -382,11 +336,11 @@ public class TestUpload {
new HttpEntity<>(map, headers), new ParameterizedTypeReference<Map<String, String>>() {
});
Map<String, String> responseBody = response.getBody();
- Assert.assertThat(responseBody, Matchers.notNullValue());
- Assert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
- Assert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
- Assert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
- Assert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
+ MatcherAssert.assertThat(responseBody, Matchers.notNullValue());
+ MatcherAssert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
+ MatcherAssert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
+ MatcherAssert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
+ MatcherAssert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
}
@Test
@@ -396,10 +350,10 @@ public class TestUpload {
Map<String, String> responseBody =
consumersSpringmvc.getIntf().uploadMultiformMix(
fileSystemResource1, fileList, message, singletonList("2.中文测试"));
- Assert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
- Assert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
- Assert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
- Assert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
+ MatcherAssert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
+ MatcherAssert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
+ MatcherAssert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
+ MatcherAssert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
}
@Test
@@ -418,11 +372,11 @@ public class TestUpload {
new HttpEntity<>(map, headers), new ParameterizedTypeReference<Map<String, String>>() {
});
Map<String, String> responseBody = response.getBody();
- Assert.assertThat(responseBody, Matchers.notNullValue());
- Assert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
- Assert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
- Assert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
- Assert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
+ MatcherAssert.assertThat(responseBody, Matchers.notNullValue());
+ MatcherAssert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
+ MatcherAssert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
+ MatcherAssert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
+ MatcherAssert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
}
@Test
@@ -432,10 +386,10 @@ public class TestUpload {
Map<String, String> responseBody =
consumersJaxrs.getIntf().uploadMultiformMix(
fileSystemResource1, fileList, message, singletonList("2.中文测试"));
- Assert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
- Assert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
- Assert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
- Assert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
+ MatcherAssert.assertThat(responseBody.get("file"), Matchers.is("hello1"));
+ MatcherAssert.assertThat(responseBody.get("fileList"), Matchers.is("中文 2"));
+ MatcherAssert.assertThat(responseBody.get("str"), Matchers.is("cseMessage"));
+ MatcherAssert.assertThat(responseBody.get("strList"), Matchers.is("[2.中文测试]"));
}
private static boolean containsAll(String str, String... strings) {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
index 6df7b5b82..7f4c79f39 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.it.testcase.base;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -33,6 +32,7 @@ import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.it.Consumers;
import org.apache.servicecomb.it.schema.Generic;
import org.apache.servicecomb.it.schema.User;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.http.HttpStatus;
@@ -270,15 +270,15 @@ public class TestGeneric {
List<List<String>> response = consumers.getIntf().genericNestedListString(nestedListString);
assertEquals(2, response.size());
- assertThat(response.get(0), Matchers.contains("abc", "def"));
- assertThat(response.get(1), Matchers.contains("ghi", "jkl"));
+ MatcherAssert.assertThat(response.get(0), Matchers.contains("abc", "def"));
+ MatcherAssert.assertThat(response.get(1), Matchers.contains("ghi", "jkl"));
@SuppressWarnings("unchecked")
List<List<String>> response2 = consumers.getSCBRestTemplate()
.postForObject("/genericNestedListString", nestedListString, List.class);
assertEquals(2, response2.size());
- assertThat(response2.get(0), Matchers.contains("abc", "def"));
- assertThat(response2.get(1), Matchers.contains("ghi", "jkl"));
+ MatcherAssert.assertThat(response2.get(0), Matchers.contains("abc", "def"));
+ MatcherAssert.assertThat(response2.get(1), Matchers.contains("ghi", "jkl"));
}
@Test
@@ -309,14 +309,14 @@ public class TestGeneric {
List<List<User>> response = consumers.getIntf().genericNestedListUser(nestedListUser);
assertEquals(2, response.size());
- assertThat(response.get(0), Matchers.contains(user1, user2));
- assertThat(response.get(1), Matchers.contains(user3, user4));
+ MatcherAssert.assertThat(response.get(0), Matchers.contains(user1, user2));
+ MatcherAssert.assertThat(response.get(1), Matchers.contains(user3, user4));
@SuppressWarnings("unchecked")
List<List<User>> response2 = consumers.getSCBRestTemplate()
.postForObject("/genericNestedListUser", nestedListUser, List.class);
assertEquals(2, response2.size());
- assertThat(response2.get(0), Matchers.contains(user1, user2));
- assertThat(response2.get(1), Matchers.contains(user3, user4));
+ MatcherAssert.assertThat(response2.get(0), Matchers.contains(user1, user2));
+ MatcherAssert.assertThat(response2.get(1), Matchers.contains(user3, user4));
}
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
index 7f67ecc9b..64268310f 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
@@ -41,6 +41,7 @@ import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -112,17 +113,17 @@ public class Test3rdPartyInvocation {
String testParam2 = "test2";
List<String> response = dataTypeJaxrsSchema.getRequestHeaders(testParam, testParam2);
// user defined header, even though start with x-cse, will not be removed
- Assert.assertThat(response, Matchers.contains("host", "x_cse_test", "x_cse_test2"));
+ MatcherAssert.assertThat(response, Matchers.contains("host", "x_cse_test", "x_cse_test2"));
ArchaiusUtils.setProperty("servicecomb.request.clientRequestHeaderFilterEnabled", "false");
response = dataTypeJaxrsSchema.getRequestHeaders(testParam, testParam2);
- Assert.assertThat(response,
+ MatcherAssert.assertThat(response,
Matchers.contains("host", "x-cse-context", "x-cse-target-microservice", "x_cse_test", "x_cse_test2"));
ArchaiusUtils.setProperty("servicecomb.request.clientRequestHeaderFilterEnabled", "true");
ArchaiusUtils.setProperty("servicecomb.request.clientRequestHeaderFilterEnabled.3rdPartyDataTypeJaxrs", "false");
response = dataTypeJaxrsSchema.getRequestHeaders(testParam, testParam2);
- Assert.assertThat(response,
+ MatcherAssert.assertThat(response,
Matchers.contains("host", "x-cse-context", "x-cse-target-microservice", "x_cse_test", "x_cse_test2"));
ArchaiusUtils.setProperty("servicecomb.request.clientRequestHeaderFilterEnabled.3rdPartyDataTypeJaxrs", "true");
diff --git a/integration-tests/jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java b/integration-tests/jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
index 70b456096..75936a55c 100644
--- a/integration-tests/jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
+++ b/integration-tests/jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
@@ -21,7 +21,6 @@ import static java.time.temporal.ChronoUnit.SECONDS;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
@@ -40,6 +39,7 @@ import java.util.Map;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.demo.compute.Person;
import org.apache.servicecomb.demo.server.User;
+import org.hamcrest.MatcherAssert;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.core.ParameterizedTypeReference;
@@ -69,8 +69,8 @@ public class JaxrsIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.getForEntity(baseUrl + "sayHi?name=Mike", String.class);
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Hi Mike"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Hi Mike"));
}
@Test
@@ -78,8 +78,8 @@ public class JaxrsIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.getForEntity(baseUrl, String.class);
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Welcome home"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Welcome home"));
}
@Test
@@ -96,7 +96,7 @@ public class JaxrsIntegrationTestBase {
jsonRequest(users),
reference);
- assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
Map<String, User> body = responseEntity.getBody();
assertArrayEquals(body.get("user1").getNames(), new String[] {"name11", "name12"});
@@ -198,7 +198,7 @@ public class JaxrsIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.exchange(url + "sayhi/{name}", PUT, null, String.class, "world");
- assertThat(responseEntity.getStatusCode(), is(ACCEPTED));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(ACCEPTED));
assertEquals("world sayhi", jsonBodyOf(responseEntity, String.class));
}
}
@@ -299,7 +299,7 @@ public class JaxrsIntegrationTestBase {
Integer.class,
params);
- assertThat(result.getBody(), is(2));
+ MatcherAssert.assertThat(result.getBody(), is(2));
}
@Test
@@ -313,7 +313,7 @@ public class JaxrsIntegrationTestBase {
Integer.class,
params);
- assertThat(result.getBody(), is(2));
+ MatcherAssert.assertThat(result.getBody(), is(2));
}
@Test
@@ -321,7 +321,7 @@ public class JaxrsIntegrationTestBase {
for (String url : urls) {
int result = restTemplate.getForObject(url, Integer.class);
- assertThat(result, is(100));
+ MatcherAssert.assertThat(result, is(100));
}
}
diff --git a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
index e1db07468..5a33b3e7c 100644
--- a/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
+++ b/integration-tests/pojo-test/src/test/java/org/apache/servicecomb/demo/pojo/test/PojoIntegrationTestBase.java
@@ -25,7 +25,6 @@ import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -42,6 +41,7 @@ import org.apache.servicecomb.demo.smartcare.Application;
import org.apache.servicecomb.demo.smartcare.Group;
import org.apache.servicecomb.demo.smartcare.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.hamcrest.MatcherAssert;
import org.junit.Ignore;
import org.junit.Test;
@@ -51,7 +51,7 @@ public class PojoIntegrationTestBase {
@Test
public void remoteHelloPojo_sayHello() {
String result = PojoService.hello.SayHello("whatever");
- assertThat(result, is("Hello Message fast"));
+ MatcherAssert.assertThat(result, is("Hello Message fast"));
}
@Test
@@ -61,8 +61,8 @@ public class PojoIntegrationTestBase {
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
- assertThat(result, is("Hello Message slow"));
- assertThat(elapsedTime,
+ MatcherAssert.assertThat(result, is("Hello Message slow"));
+ MatcherAssert.assertThat(elapsedTime,
is(both(greaterThan(4000L)).and(lessThan(7000L))));
}
@@ -80,63 +80,63 @@ public class PojoIntegrationTestBase {
application.setGroups(groups);
Response result = PojoService.smartCare.addApplication(application);
- assertThat(result.getResultCode(), is(0));
- assertThat(result.getResultMessage(), is("add application app0 success"));
+ MatcherAssert.assertThat(result.getResultCode(), is(0));
+ MatcherAssert.assertThat(result.getResultMessage(), is("add application app0 success"));
}
@Test
public void remoteSmartCarePojo_delApplication() {
Response result = PojoService.smartCare.delApplication("app0");
- assertThat(result.getResultCode(), is(1));
- assertThat(result.getResultMessage(), is("delete application app0 failed"));
+ MatcherAssert.assertThat(result.getResultCode(), is(1));
+ MatcherAssert.assertThat(result.getResultMessage(), is("delete application app0 failed"));
}
@Test
public void remoteTestPojo_testStringArray() {
String result = PojoService.test.testStringArray(new String[] {"a", "b"});
- assertThat(result, is("arr is '[a, b]'"));
+ MatcherAssert.assertThat(result, is("arr is '[a, b]'"));
}
@Test
public void remoteTestPojo_getTestString() {
// test empty string
String result = PojoService.test.getTestString("");
- assertThat(result, is("code is ''"));
+ MatcherAssert.assertThat(result, is("code is ''"));
// test null
result = PojoService.test.getTestString(null);
- assertThat(result, is("code is 'null'"));
+ MatcherAssert.assertThat(result, is("code is 'null'"));
// test Chinese
result = PojoService.test.getTestString("测试");
- assertThat(result, is("code is '测试'"));
+ MatcherAssert.assertThat(result, is("code is '测试'"));
// test String with space
result = PojoService.test.getTestString("a b");
- assertThat(result, is("code is 'a b'"));
+ MatcherAssert.assertThat(result, is("code is 'a b'"));
}
@Test
public void remoteTestPojo_postTestStatic() {
String result = PojoService.test.postTestStatic(1);
- assertThat(result, is(nullValue()));
+ MatcherAssert.assertThat(result, is(nullValue()));
result = PojoService.test.patchTestStatic(1);
- assertThat(result, is(nullValue()));
+ MatcherAssert.assertThat(result, is(nullValue()));
}
@Test
public void remoteTestPojo_testException() {
// when code is 200
String result = PojoService.test.testException(200);
- assertThat(result, is("200"));
+ MatcherAssert.assertThat(result, is("200"));
// when code is 456
try {
PojoService.test.testException(456);
fail("Exception expected, but threw nothing");
} catch (InvocationException e) {
- assertThat(e.getErrorData(), is("456 error"));
+ MatcherAssert.assertThat(e.getErrorData(), is("456 error"));
} catch (Exception e) {
fail("InvocationException expected, but threw " + e);
}
@@ -146,8 +146,8 @@ public class PojoIntegrationTestBase {
PojoService.test.testException(556);
fail("InvocationException expected, but threw nothing");
} catch (InvocationException e) {
- assertThat(e.getStatusCode(), is(556));
- assertThat(e.getErrorData().toString(), is("[556 error]"));
+ MatcherAssert.assertThat(e.getStatusCode(), is(556));
+ MatcherAssert.assertThat(e.getErrorData().toString(), is("[556 error]"));
} catch (Exception e) {
fail("InvocationException expected, but threw " + e);
}
@@ -157,21 +157,21 @@ public class PojoIntegrationTestBase {
PojoService.test.testException(557);
fail("InvocationException expected, but threw nothing");
} catch (InvocationException e) {
- assertThat(e.getStatusCode(), is(557));
- assertThat(e.getErrorData().toString(), is("[[557 error]]"));
+ MatcherAssert.assertThat(e.getStatusCode(), is(557));
+ MatcherAssert.assertThat(e.getErrorData().toString(), is("[[557 error]]"));
} catch (Exception e) {
fail("InvocationException expected, but threw " + e);
}
// when code is 123(other number, the default case)
result = PojoService.test.testException(123);
- assertThat(result, is("not expected"));
+ MatcherAssert.assertThat(result, is("not expected"));
}
@Test
public void remoteTestPojo_splitParam() {
User result = PojoService.test.splitParam(1, new User());
- assertThat(result.toString(),
+ MatcherAssert.assertThat(result.toString(),
is("User [name=nameA, users count:0, age=100, index=1]"));
}
@@ -179,7 +179,7 @@ public class PojoIntegrationTestBase {
public void remoteTestPojo_wrapParam() {
// when request is null
User result = PojoService.test.wrapParam(null);
- assertThat(result, is(nullValue()));
+ MatcherAssert.assertThat(result, is(nullValue()));
// when request is not null
User user = new User();
@@ -192,14 +192,14 @@ public class PojoIntegrationTestBase {
request.getUsers().add(user);
result = PojoService.test.wrapParam(request);
- assertThat(result.toString(),
+ MatcherAssert.assertThat(result.toString(),
is("User [name=nameA, users count:1, age=100, index=0]"));
}
@Test
public void remoteTestPojo_addString() {
String result = PojoService.test.addString(new String[] {"a", "b"});
- assertThat(result, is("[a, b]"));
+ MatcherAssert.assertThat(result, is("[a, b]"));
}
@Test
@@ -215,10 +215,10 @@ public class PojoIntegrationTestBase {
userMap.put("u2", user2);
Map<String, User> result = PojoService.codeFirst.testUserMap(userMap);
- assertThat(result.get("u1").getNames()[0], is("u1"));
- assertThat(result.get("u1").getNames()[1], is("u2"));
- assertThat(result.get("u2").getNames()[0], is("u3"));
- assertThat(result.get("u2").getNames()[1], is("u4"));
+ MatcherAssert.assertThat(result.get("u1").getNames()[0], is("u1"));
+ MatcherAssert.assertThat(result.get("u1").getNames()[1], is("u2"));
+ MatcherAssert.assertThat(result.get("u2").getNames()[0], is("u3"));
+ MatcherAssert.assertThat(result.get("u2").getNames()[1], is("u4"));
}
@Test
@@ -232,16 +232,16 @@ public class PojoIntegrationTestBase {
User[] users = new User[] {user1, user2};
List<User> result = PojoService.codeFirst.testUserArray(Arrays.asList(users));
- assertThat(result.get(0).getNames()[0], is("u1"));
- assertThat(result.get(0).getNames()[1], is("u2"));
- assertThat(result.get(1).getNames()[0], is("u3"));
- assertThat(result.get(1).getNames()[1], is("u4"));
+ MatcherAssert.assertThat(result.get(0).getNames()[0], is("u1"));
+ MatcherAssert.assertThat(result.get(0).getNames()[1], is("u2"));
+ MatcherAssert.assertThat(result.get(1).getNames()[0], is("u3"));
+ MatcherAssert.assertThat(result.get(1).getNames()[1], is("u4"));
}
@Test
public void remoteCodeFirstPojo_testStrings() {
String[] result = PojoService.codeFirst.testStrings(new String[] {"a", "b"});
- assertThat(Arrays.asList(result), contains("aa0", "b"));
+ MatcherAssert.assertThat(Arrays.asList(result), contains("aa0", "b"));
}
@Test
@@ -258,7 +258,7 @@ public class PojoIntegrationTestBase {
@Test
public void remoteCodeFirstPojo_reduce() {
int result = PojoService.codeFirst.reduce(5, 3);
- assertThat(result, is(2));
+ MatcherAssert.assertThat(result, is(2));
}
@Test
@@ -267,7 +267,7 @@ public class PojoIntegrationTestBase {
int seconds = 1;
Date result = PojoService.codeFirst.addDate(date, seconds);
- assertThat(result, equalTo(new Date(date.getTime() + seconds * 1000)));
+ MatcherAssert.assertThat(result, equalTo(new Date(date.getTime() + seconds * 1000)));
}
@Test
@@ -276,7 +276,7 @@ public class PojoIntegrationTestBase {
input.setName("person name");
Person result = PojoService.codeFirst.sayHello(input);
- assertThat(result.getName(), is("hello person name"));
+ MatcherAssert.assertThat(result.getName(), is("hello person name"));
}
@Test
@@ -285,24 +285,24 @@ public class PojoIntegrationTestBase {
person.setName("person name");
String result = PojoService.codeFirst.saySomething("prefix prefix", person);
- assertThat(result, is("prefix prefix person name"));
+ MatcherAssert.assertThat(result, is("prefix prefix person name"));
}
@Test
public void remoteCodeFirstPojo_sayHi() {
String result = PojoService.codeFirst.sayHi("world");
- assertThat(result, is("world sayhi"));
+ MatcherAssert.assertThat(result, is("world sayhi"));
}
@Test
public void remoteCodeFirstPojo_isTrue() {
boolean result = PojoService.codeFirst.isTrue();
- assertThat(result, is(true));
+ MatcherAssert.assertThat(result, is(true));
}
@Test
public void remoteCodeFirstPojo_addString() {
String result = PojoService.codeFirst.addString(Arrays.asList("a", "b"));
- assertThat(result, is("ab"));
+ MatcherAssert.assertThat(result, is("ab"));
}
}
diff --git a/integration-tests/springmvc-tests/common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTestBase.java b/integration-tests/springmvc-tests/common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTestBase.java
index 64e02789c..d1c80f092 100644
--- a/integration-tests/springmvc-tests/common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTestBase.java
+++ b/integration-tests/springmvc-tests/common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/SpringMvcIntegrationTestBase.java
@@ -22,7 +22,6 @@ import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
@@ -49,6 +48,7 @@ import org.apache.servicecomb.demo.compute.Person;
import org.apache.servicecomb.demo.server.User;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.ClassRule;
import org.junit.Ignore;
@@ -93,26 +93,26 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.getForEntity(baseUrl + "sayHi?name=Mike", String.class);
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Hi Mike"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Hi Mike"));
responseEntity = restTemplate
.getForEntity(baseUrl + "sayHi?name={name}", String.class, "小 强");
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Hi 小 强"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Hi 小 强"));
//integration test for AsyncRestTemplate
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.getForEntity(baseUrl + "sayHi?name=Mike", String.class);
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(OK));
- assertThat(futureResponse.getBody(), is("Hi Mike"));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("Hi Mike"));
listenableFuture = asyncRestTemplate.getForEntity(baseUrl + "sayHi?name={name}", String.class, "小 强");
futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(OK));
- assertThat(futureResponse.getBody(), is("Hi 小 强"));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("Hi 小 强"));
}
@Test
@@ -120,13 +120,13 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.getForEntity(baseUrl, String.class);
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Welcome home"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Welcome home"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate.getForEntity(baseUrl, String.class);
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(OK));
- assertThat(futureResponse.getBody(), is("Welcome home"));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("Welcome home"));
}
@Test
@@ -134,14 +134,14 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.getForEntity(baseUrl + "french/bonjour?name=Mike", String.class);
- assertThat(responseEntity.getStatusCode(), is(OK));
- assertThat(responseEntity.getBody(), is("Bonjour Mike"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("Bonjour Mike"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.getForEntity(baseUrl + "french/bonjour?name=Mike", String.class);
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(OK));
- assertThat(futureResponse.getBody(), is("Bonjour Mike"));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("Bonjour Mike"));
}
@Test
@@ -157,7 +157,7 @@ public class SpringMvcIntegrationTestBase {
jsonRequest(users),
reference);
- assertThat(responseEntity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(OK));
Map<String, User> body = responseEntity.getBody();
assertArrayEquals(body.get("user1").getNames(), new String[] {"name11", "name12"});
@@ -169,7 +169,7 @@ public class SpringMvcIntegrationTestBase {
jsonRequest(users),
reference);
ResponseEntity<Map<String, User>> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(OK));
body = futureResponse.getBody();
assertArrayEquals(body.get("user1").getNames(), new String[] {"name11", "name12"});
assertArrayEquals(body.get("user2").getNames(), new String[] {"name21", "name22"});
@@ -189,13 +189,13 @@ public class SpringMvcIntegrationTestBase {
body,
String.class);
- assertThat(jsonOf(result, String.class), is(body));
+ MatcherAssert.assertThat(jsonOf(result, String.class), is(body));
HttpEntity<?> entity = new HttpEntity<>(body);
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "textPlain", entity, String.class);
ResponseEntity<String> responseEntity = listenableFuture.get();
- assertThat(jsonOf(responseEntity.getBody(), String.class), is(body));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is(body));
}
@Test
@@ -244,14 +244,14 @@ public class SpringMvcIntegrationTestBase {
new HttpEntity<>(map, headers),
String.class);
- assertThat(result, is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(result, is(file1Content + file2Content + username));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "upload",
new HttpEntity<>(map, headers),
String.class);
ResponseEntity<String> responseEntity = listenableFuture.get();
- assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
}
@Test
@@ -272,14 +272,14 @@ public class SpringMvcIntegrationTestBase {
new HttpEntity<>(map, headers),
String.class);
- assertThat(result, is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(result, is(file1Content + file2Content + username));
org.springframework.web.client.AsyncRestTemplate cseAsyncRestTemplate = new CseAsyncRestTemplate();
ListenableFuture<ResponseEntity<String>> listenableFuture = cseAsyncRestTemplate
.postForEntity("cse://springmvc-tests/codeFirstSpringmvc/upload",
new HttpEntity<>(map, headers),
String.class);
ResponseEntity<String> responseEntity = listenableFuture.get();
- assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
}
@Test
@@ -300,14 +300,14 @@ public class SpringMvcIntegrationTestBase {
new HttpEntity<>(map, headers),
String.class);
- assertThat(result, is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(result, is(file1Content + file2Content + username));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "uploadWithoutAnnotation",
new HttpEntity<>(map, headers),
String.class);
ResponseEntity<String> responseEntity = listenableFuture.get();
- assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
+ MatcherAssert.assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
}
@Test
@@ -348,7 +348,7 @@ public class SpringMvcIntegrationTestBase {
Date.class,
seconds);
- assertThat(result, is(Date.from(date.plusSeconds(seconds).toInstant())));
+ MatcherAssert.assertThat(result, is(Date.from(date.plusSeconds(seconds).toInstant())));
ListenableFuture<ResponseEntity<Date>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "addDate?seconds={seconds}",
@@ -356,7 +356,7 @@ public class SpringMvcIntegrationTestBase {
Date.class,
seconds);
ResponseEntity<Date> dateResponseEntity = listenableFuture.get();
- assertThat(dateResponseEntity.getBody(), is(Date.from(date.plusSeconds(seconds).toInstant())));
+ MatcherAssert.assertThat(dateResponseEntity.getBody(), is(Date.from(date.plusSeconds(seconds).toInstant())));
}
@Test
@@ -366,23 +366,23 @@ public class SpringMvcIntegrationTestBase {
null,
String.class);
- assertThat(responseEntity.getBody(), is("ab"));
+ MatcherAssert.assertThat(responseEntity.getBody(), is("ab"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.exchange(codeFirstUrl + "addstring?s=a&s=b", HttpMethod.DELETE, null, String.class);
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getBody(), is("ab"));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("ab"));
}
@Test
public void ableToGetBoolean() throws Exception {
boolean result = restTemplate.getForObject(codeFirstUrl + "istrue", boolean.class);
- assertThat(result, is(true));
+ MatcherAssert.assertThat(result, is(true));
ListenableFuture<ResponseEntity<Boolean>> listenableFuture = asyncRestTemplate
.getForEntity(codeFirstUrl + "istrue", boolean.class);
ResponseEntity<Boolean> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getBody(), is(true));
+ MatcherAssert.assertThat(futureResponse.getBody(), is(true));
}
@Test
@@ -390,14 +390,14 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.exchange(codeFirstUrl + "sayhi/{name}", PUT, null, String.class, "world");
- assertThat(responseEntity.getStatusCode(), is(ACCEPTED));
- assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi"));
+ MatcherAssert.assertThat(responseEntity.getStatusCode(), is(ACCEPTED));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.exchange(codeFirstUrl + "sayhi/{name}", PUT, null, String.class, "world");
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getStatusCode(), is(ACCEPTED));
- assertThat(jsonOf(futureResponse.getBody(), String.class), is("world sayhi"));
+ MatcherAssert.assertThat(futureResponse.getStatusCode(), is(ACCEPTED));
+ MatcherAssert.assertThat(jsonOf(futureResponse.getBody(), String.class), is("world sayhi"));
}
@Test
@@ -405,11 +405,11 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.exchange(codeFirstUrl + "sayhi/{name}/v2", PUT, null, String.class, "world");
- assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi 2"));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi 2"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.exchange(codeFirstUrl + "sayhi/{name}/v2", PUT, null, String.class, "world");
responseEntity = listenableFuture.get();
- assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi 2"));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is("world sayhi 2"));
}
@Test
@@ -425,12 +425,12 @@ public class SpringMvcIntegrationTestBase {
ResponseEntity<String> responseEntity = restTemplate
.postForEntity(codeFirstUrl + "saysomething", requestEntity, String.class);
- assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix prefix person name"));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix prefix person name"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "saysomething", requestEntity, String.class);
responseEntity = listenableFuture.get();
- assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix prefix person name"));
+ MatcherAssert.assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix prefix person name"));
}
@Test
@@ -440,24 +440,24 @@ public class SpringMvcIntegrationTestBase {
Person person = restTemplate
.postForObject(codeFirstUrl + "sayhello", jsonRequest(personFieldMap), Person.class);
- assertThat(person.toString(), is("hello person name from map"));
+ MatcherAssert.assertThat(person.toString(), is("hello person name from map"));
Person input = new Person();
input.setName("person name from Object");
person = restTemplate.postForObject(codeFirstUrl + "sayhello", jsonRequest(input), Person.class);
- assertThat(person.toString(), is("hello person name from Object"));
+ MatcherAssert.assertThat(person.toString(), is("hello person name from Object"));
ListenableFuture<ResponseEntity<Person>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "sayhello", jsonRequest(personFieldMap), Person.class);
ResponseEntity<Person> futureResponse = listenableFuture.get();
person = futureResponse.getBody();
- assertThat(person.toString(), is("hello person name from map"));
+ MatcherAssert.assertThat(person.toString(), is("hello person name from map"));
listenableFuture = asyncRestTemplate.postForEntity(codeFirstUrl + "sayhello", jsonRequest(input), Person.class);
futureResponse = listenableFuture.get();
person = futureResponse.getBody();
- assertThat(person.toString(), is("hello person name from Object"));
+ MatcherAssert.assertThat(person.toString(), is("hello person name from Object"));
}
@Test
@@ -471,12 +471,12 @@ public class SpringMvcIntegrationTestBase {
int result = restTemplate
.postForObject(codeFirstUrl + "add", new HttpEntity<>(params, headers), Integer.class);
- assertThat(result, is(8));
+ MatcherAssert.assertThat(result, is(8));
ListenableFuture<ResponseEntity<Integer>> listenableFuture = asyncRestTemplate
.postForEntity(codeFirstUrl + "add", new HttpEntity<>(params, headers), Integer.class);
ResponseEntity<Integer> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getBody(), is(8));
+ MatcherAssert.assertThat(futureResponse.getBody(), is(8));
}
@Test
@@ -495,7 +495,7 @@ public class SpringMvcIntegrationTestBase {
Integer.class,
params);
- assertThat(result.getBody(), is(2));
+ MatcherAssert.assertThat(result.getBody(), is(2));
ListenableFuture<ResponseEntity<Integer>> listenableFuture = asyncRestTemplate
.exchange(codeFirstUrl + "reduce?a={a}",
@@ -504,7 +504,7 @@ public class SpringMvcIntegrationTestBase {
Integer.class,
params);
result = listenableFuture.get();
- assertThat(result.getBody(), is(2));
+ MatcherAssert.assertThat(result.getBody(), is(2));
}
@Test
@@ -515,14 +515,14 @@ public class SpringMvcIntegrationTestBase {
3,
4);
- assertThat(result, is(7));
+ MatcherAssert.assertThat(result, is(7));
ListenableFuture<ResponseEntity<Integer>> listenableFuture = asyncRestTemplate
.getForEntity(controllerUrl + "add?a={a}&b={b}",
Integer.class,
3,
4);
ResponseEntity<Integer> futureResponse = listenableFuture.get();
- assertThat(futureResponse.getBody(), is(7));
+ MatcherAssert.assertThat(futureResponse.getBody(), is(7));
}
@Test
@@ -533,7 +533,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"world");
- assertThat(jsonOf(result, String.class), is("hello world"));
+ MatcherAssert.assertThat(jsonOf(result, String.class), is("hello world"));
List<HttpMessageConverter<?>> convertersOld = restTemplate.getMessageConverters();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
@@ -545,7 +545,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"中 国");
- assertThat(result, is("hello 中 国"));
+ MatcherAssert.assertThat(result, is("hello 中 国"));
restTemplate.setMessageConverters(convertersOld);
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
@@ -554,14 +554,14 @@ public class SpringMvcIntegrationTestBase {
String.class,
"world");
ResponseEntity<String> futureResonse = listenableFuture.get();
- assertThat(jsonOf(futureResonse.getBody(), String.class), is("hello world"));
+ MatcherAssert.assertThat(jsonOf(futureResonse.getBody(), String.class), is("hello world"));
asyncRestTemplate.setMessageConverters(converters);
listenableFuture = asyncRestTemplate.postForEntity(controllerUrl + "sayhello/{name}",
null,
String.class,
"中 国");
futureResonse = listenableFuture.get();
- assertThat(futureResonse.getBody(), is("hello 中 国"));
+ MatcherAssert.assertThat(futureResonse.getBody(), is("hello 中 国"));
asyncRestTemplate.setMessageConverters(convertersOld);
}
@@ -576,7 +576,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"hello");
- assertThat(jsonOf(result, String.class), is("hello world"));
+ MatcherAssert.assertThat(jsonOf(result, String.class), is("hello world"));
List<HttpMessageConverter<?>> convertersOld = restTemplate.getMessageConverters();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
@@ -591,7 +591,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"hello");
- assertThat(result, is("hello 中国"));
+ MatcherAssert.assertThat(result, is("hello 中国"));
restTemplate.setMessageConverters(convertersOld);
input.setName("world");
@@ -601,7 +601,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"hello");
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(jsonOf(futureResponse.getBody(), String.class), is("hello world"));
+ MatcherAssert.assertThat(jsonOf(futureResponse.getBody(), String.class), is("hello world"));
asyncRestTemplate.setMessageConverters(converters);
input.setName("中国");
@@ -610,7 +610,7 @@ public class SpringMvcIntegrationTestBase {
String.class,
"hello");
futureResponse = listenableFuture.get();
- assertThat(futureResponse.getBody(), is("hello 中国"));
+ MatcherAssert.assertThat(futureResponse.getBody(), is("hello 中国"));
asyncRestTemplate.setMessageConverters(convertersOld);
}
@@ -620,12 +620,12 @@ public class SpringMvcIntegrationTestBase {
controllerUrl + "sayhi?name=world",
String.class);
- assertThat(jsonOf(result, String.class), is("hi world [world]"));
+ MatcherAssert.assertThat(jsonOf(result, String.class), is("hi world [world]"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate
.getForEntity(controllerUrl + "sayhi?name=world",
String.class);
ResponseEntity<String> futureResponse = listenableFuture.get();
- assertThat(jsonOf(futureResponse.getBody(), String.class), is("hi world [world]"));
+ MatcherAssert.assertThat(jsonOf(futureResponse.getBody(), String.class), is("hi world [world]"));
}
@Test
@@ -635,8 +635,8 @@ public class SpringMvcIntegrationTestBase {
.getForEntity(controllerUrl + "sayhi?name=throwexception", String.class);
assertFalse(true);
} catch (HttpServerErrorException e) {
- assertThat(e.getRawStatusCode(), is(500));
- assertThat(e.getResponseBodyAsString(),
+ MatcherAssert.assertThat(e.getRawStatusCode(), is(500));
+ MatcherAssert.assertThat(e.getResponseBodyAsString(),
Matchers.isOneOf(
"{\"message\":\"Unexpected exception when processing the request.\"}",
"{\"code\":\"SCB.50000000\",\"message\":\"Unexpected exception when processing.\"}"));
@@ -655,7 +655,7 @@ public class SpringMvcIntegrationTestBase {
requestEntity,
String.class);
- assertThat(jsonOf(result.getBody(), String.class), is("hei world"));
+ MatcherAssert.assertThat(jsonOf(result.getBody(), String.class), is("hei world"));
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate.exchange(controllerUrl + "sayhei",
GET,
@@ -670,7 +670,7 @@ public class SpringMvcIntegrationTestBase {
@Override
public void onSuccess(ResponseEntity<String> result) {
- assertThat(jsonOf(result.getBody(), String.class), is("hei world"));
+ MatcherAssert.assertThat(jsonOf(result.getBody(), String.class), is("hei world"));
}
}
);
diff --git a/integration-tests/test-common/src/test/java/org/apache/servicecomb/tests/tracing/TracingTestBase.java b/integration-tests/test-common/src/test/java/org/apache/servicecomb/tests/tracing/TracingTestBase.java
index c131420bd..7f4c712bb 100644
--- a/integration-tests/test-common/src/test/java/org/apache/servicecomb/tests/tracing/TracingTestBase.java
+++ b/integration-tests/test-common/src/test/java/org/apache/servicecomb/tests/tracing/TracingTestBase.java
@@ -19,15 +19,16 @@ package org.apache.servicecomb.tests.tracing;
import static org.apache.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_TRACING_COLLECTOR_ADDRESS;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
-import static org.junit.Assert.assertThat;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import org.apache.servicecomb.tests.EmbeddedAppender;
import org.apache.servicecomb.tests.Log4jConfig;
+import org.hamcrest.MatcherAssert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.slf4j.Logger;
@@ -78,7 +79,7 @@ public class TracingTestBase {
tracedValues.forEach(value -> log.info("Received value {}", value));
log.info("values: " + String.join(",", values));
- assertThat(tracedValues, containsInAnyOrder(values));
+ MatcherAssert.assertThat(tracedValues, containsInAnyOrder(values));
}
private List<String> tracedValues(List<Span> spans) {
@@ -89,7 +90,7 @@ public class TracingTestBase {
.filter(span -> "call.path".equals(span.getKey()) || "http.path".equals(span.getKey())
|| "http.status_code".equals(span.getKey()))
.filter(span -> span.getValue() != null)
- .map(annotation -> annotation.getValue())
+ .map(Map.Entry::getValue)
.distinct()
.collect(Collectors.toList());
}
diff --git a/integration-tests/tracing-tests/src/test/java/org/apache/servicecomb/tests/tracing/ZipkinTracingIntegrationTest.java b/integration-tests/tracing-tests/src/test/java/org/apache/servicecomb/tests/tracing/ZipkinTracingIntegrationTest.java
index 27c37f05c..c02cb1768 100644
--- a/integration-tests/tracing-tests/src/test/java/org/apache/servicecomb/tests/tracing/ZipkinTracingIntegrationTest.java
+++ b/integration-tests/tracing-tests/src/test/java/org/apache/servicecomb/tests/tracing/ZipkinTracingIntegrationTest.java
@@ -19,11 +19,11 @@ package org.apache.servicecomb.tests.tracing;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpStatus.OK;
import java.util.Collection;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
@@ -38,11 +38,11 @@ public class ZipkinTracingIntegrationTest extends TracingTestBase {
public void sendsTracingToConfiguredAddress() throws NoSuchMethodException {
ResponseEntity<String> entity = restTemplate.getForEntity("http://localhost:8080/hello", String.class);
- assertThat(entity.getStatusCode(), is(OK));
- assertThat(entity.getBody(), is("hello world, bonjour le monde, hi pojo"));
+ MatcherAssert.assertThat(entity.getStatusCode(), is(OK));
+ MatcherAssert.assertThat(entity.getBody(), is("hello world, bonjour le monde, hi pojo"));
Collection<String> tracingMessages = appender.pollLogs(".*\\[\\w+/\\w+/\\w*\\]\\s+INFO.*in /.*");
- assertThat(tracingMessages.size(), greaterThanOrEqualTo(2));
+ MatcherAssert.assertThat(tracingMessages.size(), greaterThanOrEqualTo(2));
assertThatSpansReceivedByZipkin(tracingMessages,
"/hello",
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
index aad86e416..7715abab5 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestHealthBootListener.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.core.provider.producer.ProducerMeta;
import org.apache.servicecomb.core.provider.producer.ProducerProviderManager;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -70,9 +71,9 @@ public class TestHealthBootListener {
event.setScbEngine(scbEngine);
listener.onBeforeProducerProvider(event);
- Assert.assertThat(producerMetas, Matchers.contains(producerMeta));
- Assert.assertThat(producerMeta.getSchemaId(), Matchers.equalTo("healthEndpoint"));
- Assert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(HealthCheckerRestPublisher.class));
+ MatcherAssert.assertThat(producerMetas, Matchers.contains(producerMeta));
+ MatcherAssert.assertThat(producerMeta.getSchemaId(), Matchers.equalTo("healthEndpoint"));
+ MatcherAssert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(HealthCheckerRestPublisher.class));
}
@Test
@@ -99,6 +100,6 @@ public class TestHealthBootListener {
event.setScbEngine(scbEngine);
listener.onBeforeProducerProvider(event);
- Assert.assertThat(producerMetas, Matchers.empty());
+ MatcherAssert.assertThat(producerMetas, Matchers.empty());
}
}
\ No newline at end of file
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestMetricsBootListener.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestMetricsBootListener.java
index 6e64ef422..302f5cc59 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestMetricsBootListener.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestMetricsBootListener.java
@@ -25,9 +25,9 @@ import org.apache.servicecomb.core.provider.producer.ProducerMeta;
import org.apache.servicecomb.core.provider.producer.ProducerProviderManager;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.metrics.core.publish.MetricsRestPublisher;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -68,9 +68,9 @@ public class TestMetricsBootListener {
event.setScbEngine(scbEngine);
listener.onBeforeProducerProvider(event);
- Assert.assertThat(producerMetas, Matchers.contains(producerMeta));
- Assert.assertThat(producerMeta.getSchemaId(), Matchers.equalTo("metricsEndpoint"));
- Assert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(MetricsRestPublisher.class));
+ MatcherAssert.assertThat(producerMetas, Matchers.contains(producerMeta));
+ MatcherAssert.assertThat(producerMeta.getSchemaId(), Matchers.equalTo("metricsEndpoint"));
+ MatcherAssert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(MetricsRestPublisher.class));
}
@Test
@@ -97,6 +97,6 @@ public class TestMetricsBootListener {
event.setScbEngine(scbEngine);
listener.onBeforeProducerProvider(event);
- Assert.assertThat(producerMetas, Matchers.empty());
+ MatcherAssert.assertThat(producerMetas, Matchers.empty());
}
}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestThreadPoolMetersInitializer.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestThreadPoolMetersInitializer.java
index 88b96ca7b..636d6072f 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestThreadPoolMetersInitializer.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestThreadPoolMetersInitializer.java
@@ -34,8 +34,8 @@ import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.executor.GroupExecutor;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.metrics.registry.GlobalRegistry;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
@@ -139,7 +139,7 @@ public class TestThreadPoolMetersInitializer {
result.add(meter.measure().toString());
});
- Assert.assertThat(result,
+ MatcherAssert.assertThat(result,
Matchers.containsInAnyOrder("[Measurement(threadpool.maxThreads:id=groupExecutor-group0,0,0.0)]",
"[Measurement(threadpool.completedTaskCount:id=groupExecutor-group0,0,0.0)]",
"[Measurement(threadpool.currentThreadsBusy:id=groupExecutor-group0,0,0.0)]",
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java
index a673aaf9b..88895d7a4 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/publish/model/invocation/TestOperationPerfGroup.java
@@ -20,6 +20,7 @@ import javax.ws.rs.core.Response.Status;
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.metrics.core.meter.invocation.MeterInvocationConst;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -43,7 +44,7 @@ public class TestOperationPerfGroup {
group.addOperationPerf(opPerf);
group.addOperationPerf(opPerf);
- Assert.assertThat(group.getOperationPerfs(), Matchers.contains(opPerf, opPerf));
+ MatcherAssert.assertThat(group.getOperationPerfs(), Matchers.contains(opPerf, opPerf));
OperationPerf summary = group.getSummary();
diff --git a/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java b/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
index f58949289..58aff53ea 100644
--- a/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
+++ b/metrics/metrics-integration/metrics-prometheus/src/test/java/org/apache/servicecomb/metrics/prometheus/TestPrometheusPublisher.java
@@ -31,9 +31,8 @@ import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.RegistrationManager;
import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.DefaultRegistry;
@@ -50,9 +49,6 @@ public class TestPrometheusPublisher {
PrometheusPublisher publisher = new PrometheusPublisher();
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
@AfterClass
public static void teardown() {
ArchaiusUtils.resetConfig();
@@ -60,26 +56,26 @@ public class TestPrometheusPublisher {
@Test
public void testBadPublishAddress() {
- thrown.expect(ServiceCombException.class);
-
- ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "a:b:c");
- publisher.init(globalRegistry, null, null);
+ Assertions.assertThrows(ServiceCombException.class, () -> {
+ ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "a:b:c");
+ publisher.init(globalRegistry, null, null);
+ });
}
@Test
public void testBadPublishAddress_BadPort() {
- thrown.expect(ServiceCombException.class);
-
- ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:xxxx");
- publisher.init(globalRegistry, null, null);
+ Assertions.assertThrows(ServiceCombException.class, () -> {
+ ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:xxxx");
+ publisher.init(globalRegistry, null, null);
+ });
}
@Test
public void testBadPublishAddress_TooLargePort() {
- thrown.expect(ServiceCombException.class);
-
- ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:9999999");
- publisher.init(globalRegistry, null, null);
+ Assertions.assertThrows(ServiceCombException.class, () -> {
+ ArchaiusUtils.setProperty(PrometheusPublisher.METRICS_PROMETHEUS_ADDRESS, "localhost:9999999");
+ publisher.init(globalRegistry, null, null);
+ });
}
@Test
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
index b3520d323..6a687b2da 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
@@ -19,14 +19,14 @@ package org.apache.servicecomb.provider.pojo;
import static org.apache.servicecomb.provider.pojo.PojoConst.POJO;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import org.hamcrest.MatcherAssert;
import org.junit.Test;
public class TestPojoConsumerProvider {
@Test
public void providerNameIsPojo() {
PojoConsumerProvider pojoConsumerProvider = new PojoConsumerProvider();
- assertThat(pojoConsumerProvider.getName(), is(POJO));
+ MatcherAssert.assertThat(pojoConsumerProvider.getName(), is(POJO));
}
}
diff --git a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
index 1f0ac376a..5b59cc509 100644
--- a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
+++ b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/reference/PojoReferenceMetaTest.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.provider.pojo.IPerson;
+import org.hamcrest.MatcherAssert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -53,8 +54,8 @@ public class PojoReferenceMetaTest {
pojoReferenceMeta.afterPropertiesSet();
Assert.assertEquals(IPerson.class, pojoReferenceMeta.getObjectType());
- assertThat(pojoReferenceMeta.getProxy(), instanceOf(IPerson.class));
- Assert.assertEquals(true, pojoReferenceMeta.isSingleton());
+ MatcherAssert.assertThat(pojoReferenceMeta.getProxy(), instanceOf(IPerson.class));
+ Assert.assertTrue(pojoReferenceMeta.isSingleton());
scbEngine.destroy();
}
diff --git a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
index 3faa31ff7..1b2e7296c 100644
--- a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
+++ b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
@@ -31,6 +31,7 @@ import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -145,7 +146,7 @@ public class TestInvocationToHttpServletRequest {
}
};
- Assert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
+ MatcherAssert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
}
@Test
@@ -166,9 +167,9 @@ public class TestInvocationToHttpServletRequest {
};
Map<String, String[]> params = request.getParameterMap();
- Assert.assertThat(params.size(), Matchers.is(2));
- Assert.assertThat(params, Matchers.hasEntry("p1", new String[] {"v1"}));
- Assert.assertThat(params, Matchers.hasEntry("p2", new String[] {"v2"}));
+ MatcherAssert.assertThat(params.size(), Matchers.is(2));
+ MatcherAssert.assertThat(params, Matchers.hasEntry("p1", new String[] {"v1"}));
+ MatcherAssert.assertThat(params, Matchers.hasEntry("p2", new String[] {"v2"}));
}
@Test
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/ServiceCombRestTemplateConfigTest.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/ServiceCombRestTemplateConfigTest.java
index ae35f4b7b..058ffa33a 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/ServiceCombRestTemplateConfigTest.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/ServiceCombRestTemplateConfigTest.java
@@ -18,8 +18,8 @@
package org.apache.servicecomb.provider.springmvc.reference;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertThat;
+import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
@@ -31,6 +31,6 @@ public class ServiceCombRestTemplateConfigTest {
public void exposesServiceCombRestTemplate() {
RestTemplate restTemplate = config.restTemplate();
- assertThat(restTemplate, instanceOf(RestTemplateWrapper.class));
+ MatcherAssert.assertThat(restTemplate, instanceOf(RestTemplateWrapper.class));
}
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCommonToHttpServletRequest.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCommonToHttpServletRequest.java
index 6f33899ec..bfc8aa8c4 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCommonToHttpServletRequest.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCommonToHttpServletRequest.java
@@ -34,6 +34,7 @@ import javax.ws.rs.core.HttpHeaders;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -117,7 +118,7 @@ public class TestCommonToHttpServletRequest {
queryParams.put("name", Arrays.asList("value"));
HttpServletRequest request = new CommonToHttpServletRequest(null, queryParams, null, null, false);
- Assert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
+ MatcherAssert.assertThat(request.getParameterValues("name"), Matchers.arrayContaining("value"));
}
@Test
@@ -161,7 +162,7 @@ public class TestCommonToHttpServletRequest {
httpHeaders.put("name", Arrays.asList("value"));
HttpServletRequest request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
- Assert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaderNames()), Matchers.contains("name"));
}
@Test
@@ -186,7 +187,7 @@ public class TestCommonToHttpServletRequest {
httpHeaders.put("name", Arrays.asList("value"));
HttpServletRequest request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
- Assert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("value"));
}
@Test
@@ -248,7 +249,7 @@ public class TestCommonToHttpServletRequest {
HttpServletRequestEx request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
request.addHeader("name", "v1");
request.addHeader("name", "v2");
- Assert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("v1", "v2"));
+ MatcherAssert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("v1", "v2"));
}
@Test
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateBuilder.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateBuilder.java
index b87885ecb..cafc6a7ae 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateBuilder.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateBuilder.java
@@ -19,10 +19,10 @@ package org.apache.servicecomb.provider.springmvc.reference;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertThat;
import java.net.URI;
+import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
@@ -53,11 +53,11 @@ public class TestRestTemplateBuilder {
RestTemplate restTemplate = RestTemplateBuilder.create();
- assertThat(restTemplate, instanceOf(RestTemplateWrapper.class));
+ MatcherAssert.assertThat(restTemplate, instanceOf(RestTemplateWrapper.class));
RestTemplateWrapper wrapper = (RestTemplateWrapper) restTemplate;
- assertThat(wrapper.getRestTemplate(url), is(underlying));
- assertThat(wrapper.getRestTemplate(URI.create(url)), is(underlying));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(url), is(underlying));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(URI.create(url)), is(underlying));
}
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateCopyHeaderFilter.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateCopyHeaderFilter.java
index fbfb82291..90bc5f0ae 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateCopyHeaderFilter.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateCopyHeaderFilter.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -93,7 +94,7 @@ public class TestRestTemplateCopyHeaderFilter {
HttpServletRequestEx requestEx = new CommonToHttpServletRequest(null, null, new HttpHeaders(), null, false);
filter.beforeSendRequest(invocation, requestEx);
- Assert.assertThat(Collections.list(requestEx.getHeaders("name")), Matchers.contains("value"));
+ MatcherAssert.assertThat(Collections.list(requestEx.getHeaders("name")), Matchers.contains("value"));
}
@Test
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateWrapper.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateWrapper.java
index b87231102..30294f119 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateWrapper.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestRestTemplateWrapper.java
@@ -45,6 +45,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.ParameterizedTypeReference;
@@ -109,17 +110,17 @@ public class TestRestTemplateWrapper {
when(underlying.headForHeaders(url, param1, param2)).thenReturn(expected);
actual = wrapper.headForHeaders(url, param1, param2);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).headForHeaders(url, param1, param2);
when(underlying.headForHeaders(url, paramsMap)).thenReturn(expected);
actual = wrapper.headForHeaders(url, paramsMap);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).headForHeaders(url, paramsMap);
when(underlying.headForHeaders(uri)).thenReturn(expected);
actual = wrapper.headForHeaders(uri);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).headForHeaders(uri);
}
@@ -130,17 +131,17 @@ public class TestRestTemplateWrapper {
when(underlying.optionsForAllow(url, param1, param2)).thenReturn(expected);
actual = wrapper.optionsForAllow(url, param1, param2);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).optionsForAllow(url, param1, param2);
when(underlying.optionsForAllow(url, paramsMap)).thenReturn(expected);
actual = wrapper.optionsForAllow(url, paramsMap);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).optionsForAllow(url, paramsMap);
when(underlying.optionsForAllow(uri)).thenReturn(expected);
actual = wrapper.optionsForAllow(uri);
- assertThat(actual, is(expected));
+ MatcherAssert.assertThat(actual, is(expected));
verify(underlying).optionsForAllow(uri);
}
@@ -150,17 +151,17 @@ public class TestRestTemplateWrapper {
when(underlying.getForObject(url, String.class, param1, param2)).thenReturn(response);
actual = wrapper.getForObject(url, String.class, param1, param2);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).getForObject(url, String.class, param1, param2);
when(underlying.getForObject(url, String.class, paramsMap)).thenReturn(response);
actual = wrapper.getForObject(url, String.class, paramsMap);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).getForObject(url, String.class, paramsMap);
when(underlying.getForObject(uri, String.class)).thenReturn(response);
actual = wrapper.getForObject(uri, String.class);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).getForObject(uri, String.class);
}
@@ -170,17 +171,17 @@ public class TestRestTemplateWrapper {
when(underlying.getForEntity(url, String.class, param1, param2)).thenReturn(responseEntity);
actual = wrapper.getForEntity(url, String.class, param1, param2);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).getForEntity(url, String.class, param1, param2);
when(underlying.getForEntity(url, String.class, paramsMap)).thenReturn(responseEntity);
actual = wrapper.getForEntity(url, String.class, paramsMap);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).getForEntity(url, String.class, paramsMap);
when(underlying.getForEntity(uri, String.class)).thenReturn(responseEntity);
actual = wrapper.getForEntity(uri, String.class);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).getForEntity(uri, String.class);
}
@@ -190,17 +191,17 @@ public class TestRestTemplateWrapper {
when(underlying.postForObject(url, requestEntity, String.class, param1, param2)).thenReturn(response);
actual = wrapper.postForObject(url, requestEntity, String.class, param1, param2);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).postForObject(url, requestEntity, String.class, param1, param2);
when(underlying.postForObject(url, requestEntity, String.class, paramsMap)).thenReturn(response);
actual = wrapper.postForObject(url, requestEntity, String.class, paramsMap);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).postForObject(url, requestEntity, String.class, paramsMap);
when(underlying.postForObject(uri, requestEntity, String.class)).thenReturn(response);
actual = wrapper.postForObject(uri, requestEntity, String.class);
- assertThat(actual, is(response));
+ MatcherAssert.assertThat(actual, is(response));
verify(underlying).postForObject(uri, requestEntity, String.class);
}
@@ -210,17 +211,17 @@ public class TestRestTemplateWrapper {
when(underlying.postForEntity(url, requestEntity, String.class, param1, param2)).thenReturn(responseEntity);
actual = wrapper.postForEntity(url, requestEntity, String.class, param1, param2);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).postForEntity(url, requestEntity, String.class, param1, param2);
when(underlying.postForEntity(url, requestEntity, String.class, paramsMap)).thenReturn(responseEntity);
actual = wrapper.postForEntity(url, requestEntity, String.class, paramsMap);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).postForEntity(url, requestEntity, String.class, paramsMap);
when(underlying.postForEntity(uri, requestEntity, String.class)).thenReturn(responseEntity);
actual = wrapper.postForEntity(uri, requestEntity, String.class);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).postForEntity(uri, requestEntity, String.class);
}
@@ -230,17 +231,17 @@ public class TestRestTemplateWrapper {
when(underlying.postForLocation(url, requestEntity, param1, param2)).thenReturn(uri);
actual = wrapper.postForLocation(url, requestEntity, param1, param2);
- assertThat(actual, is(uri));
+ MatcherAssert.assertThat(actual, is(uri));
verify(underlying).postForLocation(url, requestEntity, param1, param2);
when(underlying.postForLocation(url, requestEntity, paramsMap)).thenReturn(uri);
actual = wrapper.postForLocation(url, requestEntity, paramsMap);
- assertThat(actual, is(uri));
+ MatcherAssert.assertThat(actual, is(uri));
verify(underlying).postForLocation(url, requestEntity, paramsMap);
when(underlying.postForLocation(uri, requestEntity)).thenReturn(uri);
actual = wrapper.postForLocation(uri, requestEntity);
- assertThat(actual, is(uri));
+ MatcherAssert.assertThat(actual, is(uri));
verify(underlying).postForLocation(uri, requestEntity);
}
@@ -256,17 +257,17 @@ public class TestRestTemplateWrapper {
when(underlying.execute(url, method, requestCallback, responseExtractor, param1, param2))
.thenReturn(responseEntity);
actual = wrapper.execute(url, method, requestCallback, responseExtractor, param1, param2);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).execute(url, method, requestCallback, responseExtractor, param1, param2);
when(underlying.execute(url, method, requestCallback, responseExtractor, paramsMap)).thenReturn(responseEntity);
actual = wrapper.execute(url, method, requestCallback, responseExtractor, paramsMap);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).execute(url, method, requestCallback, responseExtractor, paramsMap);
when(underlying.execute(uri, method, requestCallback, responseExtractor)).thenReturn(responseEntity);
actual = wrapper.execute(uri, method, requestCallback, responseExtractor);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).execute(uri, method, requestCallback, responseExtractor);
}
}
@@ -278,23 +279,23 @@ public class TestRestTemplateWrapper {
for (HttpMethod method : httpMethods) {
when(underlying.exchange(url, method, requestEntity, String.class, param1, param2)).thenReturn(responseEntity);
actual = wrapper.exchange(url, method, requestEntity, String.class, param1, param2);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).exchange(url, method, requestEntity, String.class, param1, param2);
when(underlying.exchange(url, method, requestEntity, String.class, paramsMap)).thenReturn(responseEntity);
actual = wrapper.exchange(url, method, requestEntity, String.class, paramsMap);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).exchange(url, method, requestEntity, String.class, paramsMap);
when(underlying.exchange(uri, method, requestEntity, String.class)).thenReturn(responseEntity);
actual = wrapper.exchange(uri, method, requestEntity, String.class);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).exchange(uri, method, requestEntity, String.class);
RequestEntity<String> request = new RequestEntity<>(method, uri);
when(underlying.exchange(request, String.class)).thenReturn(responseEntity);
actual = wrapper.exchange(request, String.class);
- assertThat(actual, is(responseEntity));
+ MatcherAssert.assertThat(actual, is(responseEntity));
verify(underlying).exchange(request, String.class);
}
}
@@ -308,23 +309,23 @@ public class TestRestTemplateWrapper {
for (HttpMethod method : httpMethods) {
when(underlying.exchange(url, method, requestEntity, typeReference, param1, param2)).thenReturn(typedResponse);
actual = wrapper.exchange(url, method, requestEntity, typeReference, param1, param2);
- assertThat(actual, is(typedResponse));
+ MatcherAssert.assertThat(actual, is(typedResponse));
verify(underlying).exchange(url, method, requestEntity, typeReference, param1, param2);
when(underlying.exchange(url, method, requestEntity, typeReference, paramsMap)).thenReturn(typedResponse);
actual = wrapper.exchange(url, method, requestEntity, typeReference, paramsMap);
- assertThat(actual, is(typedResponse));
+ MatcherAssert.assertThat(actual, is(typedResponse));
verify(underlying).exchange(url, method, requestEntity, typeReference, paramsMap);
when(underlying.exchange(uri, method, requestEntity, typeReference)).thenReturn(typedResponse);
actual = wrapper.exchange(uri, method, requestEntity, typeReference);
- assertThat(actual, is(typedResponse));
+ MatcherAssert.assertThat(actual, is(typedResponse));
verify(underlying).exchange(uri, method, requestEntity, typeReference);
RequestEntity<String> request = new RequestEntity<>(method, uri);
when(underlying.exchange(request, typeReference)).thenReturn(typedResponse);
actual = wrapper.exchange(request, typeReference);
- assertThat(actual, is(typedResponse));
+ MatcherAssert.assertThat(actual, is(typedResponse));
verify(underlying).exchange(request, typeReference);
}
}
@@ -361,8 +362,8 @@ public class TestRestTemplateWrapper {
wrapper.setInterceptors(interceptors);
- assertThat(wrapper.getInterceptors(), contains(interceptor1, interceptor2));
- assertThat(wrapper.defaultRestTemplate.getInterceptors(), contains(interceptor1, interceptor2));
+ MatcherAssert.assertThat(wrapper.getInterceptors(), contains(interceptor1, interceptor2));
+ MatcherAssert.assertThat(wrapper.defaultRestTemplate.getInterceptors(), contains(interceptor1, interceptor2));
verify(underlying, never()).setInterceptors(interceptors);
}
@@ -372,8 +373,8 @@ public class TestRestTemplateWrapper {
wrapper.setRequestFactory(requestFactory);
- assertThat(wrapper.getRequestFactory(), is(requestFactory));
- assertThat(wrapper.defaultRestTemplate.getRequestFactory(), is(requestFactory));
+ MatcherAssert.assertThat(wrapper.getRequestFactory(), is(requestFactory));
+ MatcherAssert.assertThat(wrapper.defaultRestTemplate.getRequestFactory(), is(requestFactory));
verify(underlying, never()).setRequestFactory(requestFactory);
}
@@ -384,8 +385,8 @@ public class TestRestTemplateWrapper {
wrapper.setErrorHandler(errorHandler);
- assertThat(wrapper.getErrorHandler(), is(errorHandler));
- assertThat(wrapper.defaultRestTemplate.getErrorHandler(), is(errorHandler));
+ MatcherAssert.assertThat(wrapper.getErrorHandler(), is(errorHandler));
+ MatcherAssert.assertThat(wrapper.defaultRestTemplate.getErrorHandler(), is(errorHandler));
verify(underlying).setErrorHandler(errorHandler);
}
@@ -396,8 +397,8 @@ public class TestRestTemplateWrapper {
wrapper.setDefaultUriVariables(uriVariables);
- assertThat(defaultUriVariablesOf(wrapper), is(uriVariables));
- assertThat(defaultUriVariablesOf(wrapper.defaultRestTemplate), is(uriVariables));
+ MatcherAssert.assertThat(defaultUriVariablesOf(wrapper), is(uriVariables));
+ MatcherAssert.assertThat(defaultUriVariablesOf(wrapper.defaultRestTemplate), is(uriVariables));
verify(underlying).setDefaultUriVariables(uriVariables);
}
@@ -408,8 +409,8 @@ public class TestRestTemplateWrapper {
wrapper.setUriTemplateHandler(uriTemplateHandler);
- assertThat(wrapper.getUriTemplateHandler(), is(uriTemplateHandler));
- assertThat(wrapper.defaultRestTemplate.getUriTemplateHandler(), is(uriTemplateHandler));
+ MatcherAssert.assertThat(wrapper.getUriTemplateHandler(), is(uriTemplateHandler));
+ MatcherAssert.assertThat(wrapper.defaultRestTemplate.getUriTemplateHandler(), is(uriTemplateHandler));
verify(underlying, never()).setUriTemplateHandler(uriTemplateHandler);
}
@@ -421,23 +422,23 @@ public class TestRestTemplateWrapper {
wrapper.setMessageConverters(singletonList(messageConverter));
- assertThat(wrapper.getMessageConverters(), contains(messageConverter));
- assertThat(wrapper.defaultRestTemplate.getMessageConverters(), contains(messageConverter));
+ MatcherAssert.assertThat(wrapper.getMessageConverters(), contains(messageConverter));
+ MatcherAssert.assertThat(wrapper.defaultRestTemplate.getMessageConverters(), contains(messageConverter));
verify(underlying, never()).setMessageConverters(singletonList(messageConverter));
}
@Test
public void getsAcceptableRestTemplate() {
- assertThat(wrapper.getRestTemplate(uri), is(underlying));
- assertThat(wrapper.getRestTemplate(url), is(underlying));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(uri), is(underlying));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(url), is(underlying));
}
@Test
public void getsDefaultRestTemplate() {
reset(underlying);
- assertThat(wrapper.getRestTemplate(uri), is(wrapper.defaultRestTemplate));
- assertThat(wrapper.getRestTemplate(url), is(wrapper.defaultRestTemplate));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(uri), is(wrapper.defaultRestTemplate));
+ MatcherAssert.assertThat(wrapper.getRestTemplate(url), is(wrapper.defaultRestTemplate));
}
@SuppressWarnings("deprecation")
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/MockMicroserviceVersions.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/MockMicroserviceVersions.java
index a56b4f326..d8f2cfab2 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/MockMicroserviceVersions.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/MockMicroserviceVersions.java
@@ -32,6 +32,7 @@ import org.apache.servicecomb.registry.consumer.MicroserviceVersion;
import org.apache.servicecomb.registry.consumer.MicroserviceVersionRule;
import org.apache.servicecomb.registry.consumer.MicroserviceVersions;
import org.apache.servicecomb.foundation.common.Version;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
@@ -112,7 +113,7 @@ public class MockMicroserviceVersions extends MicroserviceVersions {
public void check(MicroserviceVersionRule microserviceVersionRule, String latestVersion, String... instanceVersions) {
Assert.assertSame(findMicroserviceVersion(latestVersion), microserviceVersionRule.getLatestMicroserviceVersion());
- Assert.assertThat(microserviceVersionRule.getInstances().values(),
+ MatcherAssert.assertThat(microserviceVersionRule.getInstances().values(),
Matchers.containsInAnyOrder(findInstances(instanceVersions).toArray()));
}
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
index 08d76884a..88032468c 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/TestConsumers.java
@@ -29,6 +29,7 @@ import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.registry.consumer.MicroserviceVersion;
import org.apache.servicecomb.registry.consumer.MicroserviceVersionRule;
import org.apache.servicecomb.registry.consumer.MicroserviceVersions;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -104,7 +105,7 @@ public class TestConsumers extends TestRegistryBase {
appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
Assert.assertEquals(0, microserviceManager.getVersionsByName().size());
- Assert.assertThat(collector.getEvents().stream()
+ MatcherAssert.assertThat(collector.getEvents().stream()
.filter(e -> e.getThrowableInformation() != null)
.map(e -> e.getThrowableInformation().getThrowable().getMessage())
.toArray(),
@@ -132,7 +133,7 @@ public class TestConsumers extends TestRegistryBase {
.registerMicroserviceMapping("3rd", "1.0.0", Arrays.asList(microserviceInstance), Hello.class);
MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
- Assert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(microserviceInstance));
+ MatcherAssert.assertThat(microserviceVersionRule.getInstances().values(), Matchers.contains(microserviceInstance));
}
@Test
@@ -145,7 +146,7 @@ public class TestConsumers extends TestRegistryBase {
MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, "3rd", "0+");
Assert.assertEquals(2, microserviceVersionRule.getInstances().size());
- Assert.assertThat(microserviceVersionRule.getInstances().values().stream()
+ MatcherAssert.assertThat(microserviceVersionRule.getInstances().values().stream()
.flatMap(inst -> inst.getEndpoints().stream())
.toArray(),
Matchers.arrayContainingInAnyOrder("cse://127.0.0.1:8080", "cse://127.0.0.1:8081"));
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroserviceFactory.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroserviceFactory.java
index d92064b27..c4c359e3a 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroserviceFactory.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/api/registry/TestMicroserviceFactory.java
@@ -25,13 +25,10 @@ import org.apache.servicecomb.config.ConfigUtil;
import org.apache.servicecomb.registry.api.registry.Microservice;
import org.apache.servicecomb.registry.api.registry.MicroserviceFactory;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class TestMicroserviceFactory {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void testAllowCrossApp() {
@@ -111,9 +108,10 @@ public class TestMicroserviceFactory {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_VERSION, "x.y.x.1");
- expectedException.equals(IllegalStateException.class);
- expectedException.expectMessage("Invalid major \"x\", version \"x.y.x.1\".");
- MicroserviceFactory microserviceFactory = new MicroserviceFactory();
- microserviceFactory.create(configuration);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ MicroserviceFactory microserviceFactory = new MicroserviceFactory();
+ microserviceFactory.create(configuration);
+ });
+ Assertions.assertEquals("Invalid major \"x\", version \"x.y.x.1\".", exception.getMessage());
}
}
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
index b50344bc8..a3b4a7461 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/LocalServiceRegistryClientImplTest.java
@@ -30,13 +30,13 @@ import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
import org.apache.servicecomb.serviceregistry.client.http.Holder;
import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
import org.apache.servicecomb.registry.definition.DefinitionConst;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
public class LocalServiceRegistryClientImplTest {
LocalServiceRegistryClientImpl registryClient;
@@ -45,9 +45,6 @@ public class LocalServiceRegistryClientImplTest {
String microserviceName = "ms";
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void loadRegistryFile() throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
@@ -59,7 +56,7 @@ public class LocalServiceRegistryClientImplTest {
@Test
public void testLoadRegistryFile() {
Assert.assertNotNull(registryClient);
- Assert.assertThat(registryClient.getAllMicroservices().size(), Is.is(2));
+ MatcherAssert.assertThat(registryClient.getAllMicroservices().size(), Is.is(2));
List<MicroserviceInstance> m =
registryClient.findServiceInstance("", "default", "ms2", DefinitionConst.VERSION_RULE_ALL);
Assert.assertEquals(1, m.size());
@@ -125,12 +122,12 @@ public class LocalServiceRegistryClientImplTest {
List<MicroserviceInstance> result =
registryClient.findServiceInstance("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
- Assert.assertThat(result, Matchers.nullValue());
+ MatcherAssert.assertThat(result, Matchers.nullValue());
MicroserviceInstances microserviceInstances =
registryClient.findServiceInstances("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL, null);
- Assert.assertThat(microserviceInstances.isMicroserviceNotExist(), Matchers.is(true));
- Assert.assertThat(microserviceInstances.getInstancesResponse(), Matchers.nullValue());
+ MatcherAssert.assertThat(microserviceInstances.isMicroserviceNotExist(), Matchers.is(true));
+ MatcherAssert.assertThat(microserviceInstances.getInstancesResponse(), Matchers.nullValue());
}
@Test
@@ -146,23 +143,23 @@ public class LocalServiceRegistryClientImplTest {
List<MicroserviceInstance> result =
registryClient.findServiceInstance("self", appId, microserviceName, "1.0.0");
- Assert.assertThat(result, Matchers.contains(instance));
+ MatcherAssert.assertThat(result, Matchers.contains(instance));
MicroserviceInstances microserviceInstances =
registryClient.findServiceInstances("self", appId, microserviceName, "1.0.0", "0");
List<MicroserviceInstance> results = microserviceInstances.getInstancesResponse().getInstances();
- Assert.assertThat(results, Matchers.contains(instance));
+ MatcherAssert.assertThat(results, Matchers.contains(instance));
}
@Test
public void registerSchema_microserviceNotExist() {
mockRegisterMicroservice(appId, microserviceName, "1.0.0");
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage(Matchers.is("Invalid serviceId, serviceId=notExist"));
-
- registryClient.registerSchema("notExist", "sid", "content");
+ IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
+ registryClient.registerSchema("notExist", "sid", "content");
+ });
+ Assertions.assertEquals("Invalid serviceId, serviceId=notExist", exception.getMessage());
}
@Test
@@ -197,7 +194,7 @@ public class LocalServiceRegistryClientImplTest {
@Test
public void testLoadSchemaIdsFromRegistryFile() {
Microservice microservice = registryClient.getMicroservice("002");
- Assert.assertThat(microservice.getSchemas().size(), Is.is(1));
+ MatcherAssert.assertThat(microservice.getSchemas().size(), Is.is(1));
Assert.assertTrue(microservice.getSchemas().contains("hello"));
}
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
index 1d69a18b6..7059245bb 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java
@@ -50,6 +50,7 @@ import org.apache.servicecomb.serviceregistry.api.response.GetServiceResponse;
import org.apache.servicecomb.serviceregistry.client.ClientException;
import org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl.ResponseWrapper;
import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
+import org.hamcrest.MatcherAssert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -134,7 +135,7 @@ public class TestServiceRegistryClientImpl {
microservice.getServiceName(),
microservice.getVersion(),
microservice.getEnvironment()));
- Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
+ MatcherAssert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
Assert.assertNull(oClient.registerMicroservice(microservice));
Assert.assertNull(oClient.getMicroservice("microserviceId"));
Assert.assertNull(oClient.getMicroserviceInstance("consumerId", "providerId"));
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
index 8c356ad47..47ae26abb 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestRemoteServiceRegistry.java
@@ -16,14 +16,12 @@
*/
package org.apache.servicecomb.serviceregistry.registry;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.commons.configuration.Configuration;
import org.apache.servicecomb.config.ConfigUtil;
-import org.apache.servicecomb.foundation.common.net.IpPort;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.serviceregistry.event.ShutdownEvent;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
@@ -32,9 +30,7 @@ import org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientI
import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import com.google.common.eventbus.EventBus;
@@ -56,16 +52,9 @@ public class TestRemoteServiceRegistry {
}
}
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void testLifeCycle(@Injectable ServiceRegistryConfig config,
@Injectable ServiceRegistry registry) throws InterruptedException {
- ArrayList<IpPort> ipPortList = new ArrayList<>();
- ipPortList.add(new IpPort("127.0.0.1", 9980));
- ipPortList.add(new IpPort("127.0.0.1", 9981));
-
CountDownLatch latch = new CountDownLatch(1);
ServiceRegistryTaskInitializer initializer = new MockUp<ServiceRegistryTaskInitializer>() {
@Mock
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/swagger/TestSwaggerLoader.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/swagger/TestSwaggerLoader.java
index 4e0bf5903..ac92f0f28 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/swagger/TestSwaggerLoader.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/swagger/TestSwaggerLoader.java
@@ -17,10 +17,6 @@
package org.apache.servicecomb.serviceregistry.swagger;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.core.Is.is;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -46,9 +42,8 @@ import org.apache.servicecomb.serviceregistry.TestRegistryBase;
import org.apache.servicecomb.swagger.SwaggerUtils;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.swagger.models.Swagger;
import mockit.Deencapsulation;
@@ -57,8 +52,6 @@ import mockit.Mock;
import mockit.MockUp;
public class TestSwaggerLoader extends TestRegistryBase {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void registerSwagger() {
@@ -212,46 +205,44 @@ public class TestSwaggerLoader extends TestRegistryBase {
@Test
public void should_throw_exception_when_register_invalid_swagger_in_location() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("failed to register swaggers, microserviceName=default, location=location.");
- expectedException.expectCause(instanceOf(ServiceCombException.class));
- expectedException.expectCause(allOf(instanceOf(ServiceCombException.class),
- hasProperty("message", is("Parse swagger from url failed, url=location/invalid.yaml"))));
-
- URL url = new MockUp<URL>() {
-
- private String path = "location/invalid.yaml";
-
- @Mock
- String getPath() {
- return path;
- }
-
- @Mock
- String toExternalForm() {
- return path;
- }
- }.getMockInstance();
- URI uri = new MockUp<URI>() {
- @Mock
- URL toURL() {
- return url;
- }
- }.getMockInstance();
- new MockUp<ResourceUtil>() {
- @Mock
- List<URI> findResources(String directory, Predicate<Path> filter) {
- return Collections.singletonList(uri);
- }
- };
- new MockUp<IOUtils>() {
- @Mock
- String toString(final URL url, final Charset encoding) {
- return "invalid yaml content";
- }
- };
-
- RegistrationManager.INSTANCE.getSwaggerLoader().registerSwaggersInLocation("location");
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ URL url = new MockUp<URL>() {
+
+ private String path = "location/invalid.yaml";
+
+ @Mock
+ String getPath() {
+ return path;
+ }
+
+ @Mock
+ String toExternalForm() {
+ return path;
+ }
+ }.getMockInstance();
+ URI uri = new MockUp<URI>() {
+ @Mock
+ URL toURL() {
+ return url;
+ }
+ }.getMockInstance();
+ new MockUp<ResourceUtil>() {
+ @Mock
+ List<URI> findResources(String directory, Predicate<Path> filter) {
+ return Collections.singletonList(uri);
+ }
+ };
+ new MockUp<IOUtils>() {
+ @Mock
+ String toString(final URL url, final Charset encoding) {
+ return "invalid yaml content";
+ }
+ };
+
+ RegistrationManager.INSTANCE.getSwaggerLoader().registerSwaggersInLocation("location");
+ });
+ Assertions.assertEquals("failed to register swaggers, microserviceName=default, location=location.", exception.getMessage());
+ Assertions.assertTrue(exception.getCause() instanceof ServiceCombException);
}
@Test
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
index afa4fd171..3ac37a252 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
@@ -25,9 +25,8 @@ import org.apache.commons.io.IOUtils;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.swagger.models.Operation;
import io.swagger.models.Path;
@@ -38,8 +37,6 @@ import mockit.Expectations;
import mockit.Mocked;
public class TestSwaggerUtils {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void swaggerToStringNormal() {
@@ -58,10 +55,9 @@ public class TestSwaggerUtils {
result = new RuntimeExceptionWithoutStackTrace();
}
};
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage("Convert swagger to string failed, ");
-
- SwaggerUtils.swaggerToString(swagger);
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> SwaggerUtils.swaggerToString(swagger));
+ Assertions.assertEquals("Convert swagger to string failed, ", exception.getMessage());
}
@Test
@@ -88,18 +84,16 @@ public class TestSwaggerUtils {
}
};
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage("Parse swagger from url failed, ");
-
- SwaggerUtils.parseSwagger(url);
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> SwaggerUtils.parseSwagger(url));
+ Assertions.assertTrue(exception.getMessage().contains("Parse swagger from url failed, "));
}
@Test
- public void parseSwaggerContentException() throws IOException {
- expectedException.expect(ServiceCombException.class);
- expectedException.expectMessage("Parse swagger from content failed, ");
-
- SwaggerUtils.parseSwagger("");
+ public void parseSwaggerContentException() {
+ ServiceCombException exception = Assertions.assertThrows(ServiceCombException.class,
+ () -> SwaggerUtils.parseSwagger(""));
+ Assertions.assertEquals("Parse swagger from content failed, ", exception.getMessage());
}
@Test
@@ -176,14 +170,14 @@ public class TestSwaggerUtils {
}
@Test(expected = ServiceCombException.class)
- public void testInvalidate() throws Exception {
+ public void testInvalidate() {
URL resource = TestSwaggerUtils.class.getResource("/swagger1.yaml");
Swagger swagger = SwaggerUtils.parseSwagger(resource);
SwaggerUtils.validateSwagger(swagger);
}
@Test
- public void testInvalidateValid() throws Exception {
+ public void testInvalidateValid() {
URL resource = TestSwaggerUtils.class.getResource("/swagger2.yaml");
Swagger swagger = SwaggerUtils.parseSwagger(resource);
SwaggerUtils.validateSwagger(swagger);
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java
index 8d2bea314..a40d7d69b 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/extend/property/creator/TestPartPropertyCreator.java
@@ -19,8 +19,8 @@ package org.apache.servicecomb.swagger.extend.property.creator;
import javax.servlet.http.Part;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.Test;
import io.swagger.models.properties.FileProperty;
@@ -32,11 +32,11 @@ public class TestPartPropertyCreator {
@SuppressWarnings("unchecked")
@Test
public void classes() {
- Assert.assertThat(creator.classes(), Matchers.arrayContaining(Part.class));
+ MatcherAssert.assertThat(creator.classes(), Matchers.arrayContaining(Part.class));
}
@Test
public void createProperty() {
- Assert.assertThat(creator.createProperty(), Matchers.instanceOf(FileProperty.class));
+ MatcherAssert.assertThat(creator.createProperty(), Matchers.instanceOf(FileProperty.class));
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestApiOperation.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestApiOperation.java
index 0810c74df..337cf6d23 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestApiOperation.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestApiOperation.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.swagger.generator.core;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.Map;
@@ -27,6 +26,7 @@ import java.util.Map;
import org.apache.servicecomb.swagger.generator.SwaggerConst;
import org.apache.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
@@ -98,7 +98,7 @@ public class TestApiOperation {
testMap(swagger.getPath("/testMap"));
testList(swagger.getPath("/testList"));
testSet(swagger.getPath("/testSet"));
- assertThat(swagger.getPath("/testHidden"), is(nullValue()));
+ MatcherAssert.assertThat(swagger.getPath("/testHidden"), is(nullValue()));
}
@Test
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestOperationGenerator.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestOperationGenerator.java
index d08e4ee8e..db38dad34 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestOperationGenerator.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestOperationGenerator.java
@@ -20,12 +20,12 @@ package org.apache.servicecomb.swagger.generator.core;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
import java.util.List;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
@@ -80,7 +80,7 @@ public class TestOperationGenerator {
public void apiOperationNoTag() {
SwaggerOperation operation = swaggerOperations.findOperation("apiOperationNoTag");
List<String> tags = operation.getOperation().getTags();
- assertThat(tags, contains("default0", "default1"));
+ MatcherAssert.assertThat(tags, contains("default0", "default1"));
assertEquals("value2", operation.getOperation().getSummary());
}
@@ -88,7 +88,7 @@ public class TestOperationGenerator {
public void noApiOperation() {
SwaggerOperation operation = swaggerOperations.findOperation("noApiOperation");
List<String> tags = operation.getOperation().getTags();
- assertThat(tags, contains("default0", "default1"));
+ MatcherAssert.assertThat(tags, contains("default0", "default1"));
assertNull(operation.getOperation().getSummary());
}
@@ -96,7 +96,7 @@ public class TestOperationGenerator {
public void responseThenApiOperation() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("responseThenApiOperation");
List<String> tags = swaggerOperation.getOperation().getTags();
- assertThat(tags, contains("tag1", "tag2"));
+ MatcherAssert.assertThat(tags, contains("tag1", "tag2"));
Response response = swaggerOperation.getOperation().getResponses().get("200");
assertEquals("200 is ok............", response.getDescription());
@@ -106,10 +106,10 @@ public class TestOperationGenerator {
}
@Test
- public void apiOperationThenResponse() throws NoSuchMethodException {
+ public void apiOperationThenResponse() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("apiOperationThenResponse");
List<String> tags = swaggerOperation.getOperation().getTags();
- assertThat(tags, contains("tag1", "tag2"));
+ MatcherAssert.assertThat(tags, contains("tag1", "tag2"));
Response response = swaggerOperation.getOperation().getResponses().get("200");
assertEquals("200 is ok............", response.getDescription());
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
index b582fe9d1..204cbd04d 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerGenerator.java
@@ -18,10 +18,10 @@
package org.apache.servicecomb.swagger.generator.core;
import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.swagger.generator.pojo.PojoSwaggerGenerator;
+import org.hamcrest.MatcherAssert;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -57,6 +57,6 @@ public class TestSwaggerGenerator {
swaggerGenerator.addDefaultTag(null);
swaggerGenerator.addDefaultTag("test2");
- assertThat(swaggerGenerator.getDefaultTags(), contains("test1", "test2"));
+ MatcherAssert.assertThat(swaggerGenerator.getDefaultTags(), contains("test1", "test2"));
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
index b877fec86..4f9255056 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.swagger.generator.core;
import static junit.framework.TestCase.fail;
import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
@@ -40,10 +39,10 @@ import org.apache.servicecomb.swagger.generator.core.schema.InvalidResponseHeade
import org.apache.servicecomb.swagger.generator.core.schema.RepeatOperation;
import org.apache.servicecomb.swagger.generator.core.schema.Schema;
import org.apache.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils;
+import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import org.mockito.Mockito;
import io.swagger.models.Swagger;
@@ -56,8 +55,6 @@ import io.swagger.models.properties.StringProperty;
import mockit.Expectations;
public class TestSwaggerUtils {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
private void testSchemaMethod(String resultName, String... methodNames) {
UnitTestSwaggerUtils.testSwagger("schemas/" + resultName + ".yaml",
@@ -271,9 +268,9 @@ public class TestSwaggerUtils {
}
};
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(
- "parameter name is not present, method=org.apache.servicecomb.swagger.generator.core.schema.Schema:testint\n"
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class,
+ () -> SwaggerGeneratorUtils.collectParameterName(parameter));
+ String expectedMsg = "parameter name is not present, method=org.apache.servicecomb.swagger.generator.core.schema.Schema:testint\n"
+ "solution:\n"
+ " change pom.xml, add compiler argument: -parameters, for example:\n"
+ " <plugin>\n"
@@ -282,8 +279,8 @@ public class TestSwaggerUtils {
+ " <configuration>\n"
+ " <compilerArgument>-parameters</compilerArgument>\n"
+ " </configuration>\n"
- + " </plugin>");
- SwaggerGeneratorUtils.collectParameterName(parameter);
+ + " </plugin>";
+ Assertions.assertEquals(expectedMsg, exception.getMessage());
}
@Test
@@ -349,7 +346,7 @@ public class TestSwaggerUtils {
testExcep(fields1[i].getGenericType(), fields2[j].getGenericType());
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString("duplicate param model:"));
+ MatcherAssert.assertThat(e.getMessage(), containsString("duplicate param model:"));
}
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java
index 413af3153..8e29e90a4 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java
@@ -17,15 +17,12 @@
package org.apache.servicecomb.swagger.generator.core.model;
import org.apache.servicecomb.swagger.SwaggerUtils;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import io.swagger.models.Swagger;
public class TestSwaggerOperations {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
@Test
public void emptyOperationId() {
@@ -34,9 +31,9 @@ public class TestSwaggerOperations {
.findFirst().get()
.getPost().setOperationId("");
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("OperationId can not be empty, path=/testboolean, httpMethod=POST.");
-
- new SwaggerOperations(swagger);
+ IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, () -> {
+ new SwaggerOperations(swagger);
+ });
+ Assertions.assertEquals("OperationId can not be empty, path=/testboolean, httpMethod=POST.", exception.getMessage());
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiOperationProcessorTest.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiOperationProcessorTest.java
index ae7bc1943..41fb06194 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiOperationProcessorTest.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiOperationProcessorTest.java
@@ -30,6 +30,7 @@ import javax.ws.rs.core.MediaType;
import io.swagger.models.properties.Property;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Test;
@@ -119,7 +120,7 @@ public class ApiOperationProcessorTest {
@Test
public void testConvertTags() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("function");
- assertThat(swaggerOperation.getOperation().getTags(), containsInAnyOrder("tag1", "tag2"));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getTags(), containsInAnyOrder("tag1", "tag2"));
}
@Test
@@ -131,13 +132,13 @@ public class ApiOperationProcessorTest {
@Test
public void testMediaType() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testSingleMediaType");
- assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN));
- assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
swaggerOperation = swaggerOperations.findOperation("testMultiMediaType");
- assertThat(swaggerOperation.getOperation().getConsumes(),
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getConsumes(),
Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
- assertThat(swaggerOperation.getOperation().getProduces(),
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getProduces(),
Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
swaggerOperation = swaggerOperations.findOperation("testBlankMediaType");
@@ -146,8 +147,8 @@ public class ApiOperationProcessorTest {
swaggerOperation.getOperation().addConsumes(MediaType.TEXT_HTML);
swaggerOperation.getOperation().addProduces(MediaType.TEXT_HTML);
- assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_HTML));
- assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.TEXT_HTML));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_HTML));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.TEXT_HTML));
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiProcessorTest.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiProcessorTest.java
index e937ee2f3..5e0bf8535 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiProcessorTest.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/ApiProcessorTest.java
@@ -26,6 +26,7 @@ import javax.ws.rs.core.MediaType;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
@@ -70,9 +71,9 @@ public class ApiProcessorTest {
SwaggerOperations swaggerOperations = SwaggerOperations.generate(SwaggerTestTarget.class);
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("op");
- assertThat(swaggerOperation.getOperation().getTags(), contains("tag1", "tag2"));
- assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swaggerOperation.getOperation().getTags(), contains("tag1", "tag2"));
+ MatcherAssert.assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
}
@Test
@@ -81,31 +82,31 @@ public class ApiProcessorTest {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("op");
assertNull(swaggerOperation.getOperation().getTags());
- assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
- assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swaggerOperation.getSwagger().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swaggerOperation.getSwagger().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON));
}
@Test
public void processOverWriteEmptyConsumesAndProduces() {
Swagger swagger = SwaggerGenerator.generate(OverrideEmptyConsumesAndProduces.class);
- assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
- assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
}
@Test
public void processNotOverWriteValidConsumesAndProduces() {
Swagger swagger = SwaggerGenerator.generate(OverWriteValidConsumesAndProduces.class);
- assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
- assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
}
@Test
public void processWithConsumesAndProduces() {
Swagger swagger = SwaggerGenerator.generate(pureApi.class);
- assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
- assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON));
}
}
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/SwaggerDefinitionProcessorTest.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/SwaggerDefinitionProcessorTest.java
index b387667e6..d5c6b06e1 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/SwaggerDefinitionProcessorTest.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/processor/annotation/SwaggerDefinitionProcessorTest.java
@@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.apache.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
@@ -119,22 +120,22 @@ public class SwaggerDefinitionProcessorTest {
assertEquals("testValue", tag.getExternalDocs().getDescription());
assertEquals("testUrl", tag.getExternalDocs().getUrl());
assertEquals("127.0.0.1", swagger.getHost());
- assertThat(swagger.getSchemes(), contains(io.swagger.models.Scheme.HTTP, io.swagger.models.Scheme.HTTPS));
+ MatcherAssert.assertThat(swagger.getSchemes(), contains(io.swagger.models.Scheme.HTTP, io.swagger.models.Scheme.HTTPS));
io.swagger.models.Info info = swagger.getInfo();
assertEquals("title", info.getTitle());
assertEquals("version", info.getVersion());
assertEquals("desc", info.getDescription());
assertEquals("contactName", info.getContact().getName());
assertEquals("licenseName", info.getLicense().getName());
- assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
- assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
}
@Test
public void testProcess_emptyMediaType() {
Swagger swagger = SwaggerGenerator.generate(SwaggerTestTarget_EmptyMediaType.class);
- assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_XML));
- assertThat(swagger.getProduces(), Matchers.contains(MediaType.TEXT_PLAIN));
+ MatcherAssert.assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_XML));
+ MatcherAssert.assertThat(swagger.getProduces(), Matchers.contains(MediaType.TEXT_PLAIN));
}
@Test
diff --git a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/processor/annotation/RequestPartAnnotationProcessorTest.java b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/processor/annotation/RequestPartAnnotationProcessorTest.java
index 95a1b40dd..c2cc5fe9f 100644
--- a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/processor/annotation/RequestPartAnnotationProcessorTest.java
+++ b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/processor/annotation/RequestPartAnnotationProcessorTest.java
@@ -22,6 +22,7 @@ import java.lang.reflect.Parameter;
import java.util.List;
import org.apache.servicecomb.swagger.generator.core.model.HttpParameterType;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -60,7 +61,7 @@ public class RequestPartAnnotationProcessorTest {
Parameter stringParam = parameters[0];
RequestPart stringParamAnnotation = stringParam.getAnnotation(RequestPart.class);
- Assert.assertThat(requestPartAnnotationProcessor.getParameterName(stringParamAnnotation),
+ MatcherAssert.assertThat(requestPartAnnotationProcessor.getParameterName(stringParamAnnotation),
Matchers.is("stringParam"));
}
@@ -70,13 +71,13 @@ public class RequestPartAnnotationProcessorTest {
Parameter intParam = parameters[1];
RequestPart intParamAnnotation = intParam.getAnnotation(RequestPart.class);
- Assert.assertThat(requestPartAnnotationProcessor.getParameterName(intParamAnnotation),
+ MatcherAssert.assertThat(requestPartAnnotationProcessor.getParameterName(intParamAnnotation),
Matchers.is("intParam"));
}
@Test
public void getHttpParameterType() {
- Assert.assertThat(requestPartAnnotationProcessor.getHttpParameterType(null),
+ MatcherAssert.assertThat(requestPartAnnotationProcessor.getHttpParameterType(null),
Matchers.is(HttpParameterType.FORM));
}
@@ -88,8 +89,8 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("string"));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("string"));
}
@Test
@@ -100,9 +101,9 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("array"));
- Assert.assertThat(formParameter.getItems(), Matchers.instanceOf(StringProperty.class));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("array"));
+ MatcherAssert.assertThat(formParameter.getItems(), Matchers.instanceOf(StringProperty.class));
}
@Test
@@ -113,9 +114,9 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("array"));
- Assert.assertThat(formParameter.getItems(), Matchers.instanceOf(StringProperty.class));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("array"));
+ MatcherAssert.assertThat(formParameter.getItems(), Matchers.instanceOf(StringProperty.class));
}
@Test
@@ -126,8 +127,8 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("file"));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("file"));
}
@Test
@@ -138,9 +139,9 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("array"));
- Assert.assertThat(formParameter.getItems(), Matchers.instanceOf(FileProperty.class));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("array"));
+ MatcherAssert.assertThat(formParameter.getItems(), Matchers.instanceOf(FileProperty.class));
}
@Test
@@ -151,9 +152,9 @@ public class RequestPartAnnotationProcessorTest {
requestPartAnnotationProcessor
.fillParameter(null, null, formParameter, param.getParameterizedType(), requestPartAnnotation);
- Assert.assertThat(formParameter.getIn(), Matchers.is("formData"));
- Assert.assertThat(formParameter.getType(), Matchers.is("array"));
- Assert.assertThat(formParameter.getItems(), Matchers.instanceOf(FileProperty.class));
+ MatcherAssert.assertThat(formParameter.getIn(), Matchers.is("formData"));
+ MatcherAssert.assertThat(formParameter.getType(), Matchers.is("array"));
+ MatcherAssert.assertThat(formParameter.getItems(), Matchers.instanceOf(FileProperty.class));
}
public static class DemoRest {
diff --git a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/property/creator/MultipartFilePropertyCreatorTest.java b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/property/creator/MultipartFilePropertyCreatorTest.java
index 619e7776b..4e581cde7 100644
--- a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/property/creator/MultipartFilePropertyCreatorTest.java
+++ b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/property/creator/MultipartFilePropertyCreatorTest.java
@@ -17,6 +17,7 @@
package org.apache.servicecomb.swagger.generator.springmvc.property.creator;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -26,17 +27,17 @@ import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.Property;
public class MultipartFilePropertyCreatorTest {
- private MultipartFilePropertyCreator multipartFilePropertyCreator = new MultipartFilePropertyCreator();
+ private final MultipartFilePropertyCreator multipartFilePropertyCreator = new MultipartFilePropertyCreator();
@Test
public void createProperty() {
Property property = multipartFilePropertyCreator.createProperty();
- Assert.assertThat(property, Matchers.instanceOf(FileProperty.class));
+ MatcherAssert.assertThat(property, Matchers.instanceOf(FileProperty.class));
}
@Test
public void classes() {
Class<?>[] classes = multipartFilePropertyCreator.classes();
- Assert.assertThat(classes, Matchers.arrayContaining(MultipartFile.class));
+ MatcherAssert.assertThat(classes, Matchers.arrayContaining(MultipartFile.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerEnvironment.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerEnvironment.java
index 6b86fae2e..f2bdfd0e9 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerEnvironment.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerEnvironment.java
@@ -20,10 +20,10 @@ package org.apache.servicecomb.swagger.engine;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.apache.servicecomb.swagger.invocation.models.ProducerImpl;
+import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,7 +31,7 @@ import org.junit.Test;
import io.swagger.models.Swagger;
public class TestSwaggerEnvironment {
- private static SwaggerEnvironment env = new SwaggerEnvironment();
+ private static final SwaggerEnvironment env = new SwaggerEnvironment();
private static SwaggerProducer producer;
@@ -42,12 +42,12 @@ public class TestSwaggerEnvironment {
@Test
public void ableToFindVisibleMethod() {
- assertThat(producer.findOperation("visibleMethod"), is(notNullValue()));
+ MatcherAssert.assertThat(producer.findOperation("visibleMethod"), is(notNullValue()));
}
@Test
public void unableToFindHiddenMethod() {
- assertThat(producer.findOperation("hiddenMethod"), is(nullValue()));
+ MatcherAssert.assertThat(producer.findOperation("hiddenMethod"), is(nullValue()));
}
interface ConsumerIntf {
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/PartListToPartArrayConverterTest.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/PartListToPartArrayConverterTest.java
index c65fde1de..8b766d391 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/PartListToPartArrayConverterTest.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/PartListToPartArrayConverterTest.java
@@ -21,6 +21,7 @@ import java.util.Arrays;
import javax.servlet.http.Part;
import org.apache.servicecomb.foundation.common.part.FilePart;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -41,7 +42,7 @@ public class PartListToPartArrayConverterTest {
@Test
public void convert() {
Object parts = converter.convert(Arrays.asList(new FilePart("name", "file")));
- Assert.assertThat(parts, Matchers.instanceOf(Part[].class));
+ MatcherAssert.assertThat(parts, Matchers.instanceOf(Part[].class));
}
@Test
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
index 19fcfa256..c5f52b6f3 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestBytesToPartConverter.java
@@ -18,6 +18,7 @@ package org.apache.servicecomb.swagger.invocation.converter.impl.part;
import javax.servlet.http.Part;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -38,6 +39,6 @@ public class TestBytesToPartConverter {
@Test
public void convert() {
Object part = converter.convert(new byte[] {});
- Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ MatcherAssert.assertThat(part, Matchers.instanceOf(Part.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java
index 0cf1516f8..73fad719f 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestFileToPartConverter.java
@@ -21,6 +21,7 @@ import java.io.File;
import javax.servlet.http.Part;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -42,6 +43,6 @@ public class TestFileToPartConverter {
public void convert() {
File file = new File("abc");
Object part = converter.convert(file);
- Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ MatcherAssert.assertThat(part, Matchers.instanceOf(Part.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java
index 74fe2b05c..852c323eb 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestInputStreamToPartConverter.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
import javax.servlet.http.Part;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -42,6 +43,6 @@ public class TestInputStreamToPartConverter {
@Test
public void convert() {
Object part = converter.convert(new ByteArrayInputStream(new byte[] {}));
- Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ MatcherAssert.assertThat(part, Matchers.instanceOf(Part.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java
index 54c72c09d..9ad13eee9 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/impl/part/TestResourceToPartConverter.java
@@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
import javax.servlet.http.Part;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -43,6 +44,6 @@ public class TestResourceToPartConverter {
@Test
public void convert() {
Object part = converter.convert(new InputStreamResource(new ByteArrayInputStream(new byte[] {})));
- Assert.assertThat(part, Matchers.instanceOf(Part.class));
+ MatcherAssert.assertThat(part, Matchers.instanceOf(Part.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsConsumerResponseMapper.java b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsConsumerResponseMapper.java
index fac885bf1..b70c47cee 100644
--- a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsConsumerResponseMapper.java
+++ b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsConsumerResponseMapper.java
@@ -24,6 +24,7 @@ import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
import org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation;
import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -75,6 +76,6 @@ public class TestJaxrsConsumerResponseMapper {
Response jaxrsResponse = (Response) operation.getResponseMapper().mapResponse(response);
Assert.assertEquals(result, jaxrsResponse.getEntity());
Assert.assertEquals(1, jaxrsResponse.getHeaders().size());
- Assert.assertThat(jaxrsResponse.getHeaders().get("h"), Matchers.contains("v1", "v2"));
+ MatcherAssert.assertThat(jaxrsResponse.getHeaders().get("h"), Matchers.contains("v1", "v2"));
}
}
diff --git a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapper.java b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapper.java
index 74b369940..7f64a4940 100644
--- a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapper.java
+++ b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapper.java
@@ -21,6 +21,7 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
import org.apache.servicecomb.swagger.invocation.Response;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -69,6 +70,6 @@ public class TestJaxrsProducerResponseMapper {
Assert.assertEquals(Status.OK, response.getStatus());
Assert.assertEquals("result", response.getResult());
Assert.assertEquals(1, response.getHeaders().size());
- Assert.assertThat(response.getHeaders("h"), Matchers.contains("v"));
+ MatcherAssert.assertThat(response.getHeaders("h"), Matchers.contains("v"));
}
}
diff --git a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapperFactory.java b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapperFactory.java
index 5b768d047..43c481ba4 100644
--- a/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-jaxrs/src/test/java/org/apache/servicecomb/swagger/invocation/jaxrs/response/TestJaxrsProducerResponseMapperFactory.java
@@ -18,6 +18,7 @@ package org.apache.servicecomb.swagger.invocation.jaxrs.response;
import javax.ws.rs.core.Response;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -37,7 +38,7 @@ public class TestJaxrsProducerResponseMapperFactory {
@Test
public void createResponseMapper() {
- Assert.assertThat(factory.createResponseMapper(null, null),
+ MatcherAssert.assertThat(factory.createResponseMapper(null, null),
Matchers.instanceOf(JaxrsProducerResponseMapper.class));
}
}
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java
index 0a8d443f5..fe12c8bdc 100644
--- a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java
+++ b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/converter/TestPartToMultipartFile.java
@@ -24,12 +24,10 @@ import java.io.IOException;
import javax.servlet.http.Part;
import org.apache.servicecomb.foundation.common.Holder;
-import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Assertions;
import mockit.Expectations;
import mockit.Mock;
@@ -42,9 +40,6 @@ public class TestPartToMultipartFile {
PartToMultipartFile multipartFile;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void setup() {
multipartFile = new PartToMultipartFile(part);
@@ -163,10 +158,9 @@ public class TestPartToMultipartFile {
}
};
- expectedException.expect(IOException.class);
- expectedException.expectMessage(Matchers.is("open stream failed"));
-
- multipartFile.getBytes();
+ IOException exception = Assertions.assertThrows(IOException.class,
+ () -> multipartFile.getBytes());
+ Assertions.assertEquals("open stream failed", exception.getMessage());
}
@Test
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcConsumerResponseMapper.java b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcConsumerResponseMapper.java
index 9bbb7b3dc..3cbb9c237 100644
--- a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcConsumerResponseMapper.java
+++ b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcConsumerResponseMapper.java
@@ -23,6 +23,7 @@ import org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation;
import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import org.apache.servicecomb.swagger.invocation.Response;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -73,7 +74,7 @@ public class TestSpringmvcConsumerResponseMapper {
.mapResponse(response);
Assert.assertEquals(result, responseEntity.getBody());
Assert.assertEquals(1, responseEntity.getHeaders().size());
- Assert.assertThat(responseEntity.getHeaders().get("h"), Matchers.contains("v"));
+ MatcherAssert.assertThat(responseEntity.getHeaders().get("h"), Matchers.contains("v"));
}
@Test
@@ -98,6 +99,6 @@ public class TestSpringmvcConsumerResponseMapper {
.mapResponse(response);
Assert.assertEquals(result, responseEntity.getBody());
Assert.assertEquals(1, responseEntity.getHeaders().size());
- Assert.assertThat(responseEntity.getHeaders().get("h"), Matchers.contains("v1", "v2"));
+ MatcherAssert.assertThat(responseEntity.getHeaders().get("h"), Matchers.contains("v1", "v2"));
}
}
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapper.java b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapper.java
index 594cae95e..e6ae3c1ae 100644
--- a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapper.java
+++ b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapper.java
@@ -25,6 +25,7 @@ import javax.ws.rs.core.Response.StatusType;
import org.apache.servicecomb.foundation.common.http.HttpStatus;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -66,7 +67,7 @@ public class TestSpringmvcProducerResponseMapper {
ResponseEntity<String[]> responseEntity =
new ResponseEntity<>(arrResult, org.springframework.http.HttpStatus.OK);
Response response = mapper.mapResponse(null, responseEntity);
- Assert.assertThat((List<String>) response.getResult(), Matchers.contains("a", "b"));
+ MatcherAssert.assertThat((List<String>) response.getResult(), Matchers.contains("a", "b"));
Assert.assertEquals(Status.OK, response.getStatus());
}
@@ -89,6 +90,6 @@ public class TestSpringmvcProducerResponseMapper {
Response response = mapper.mapResponse(null, responseEntity);
List<String> hv = response.getHeaders("h");
- Assert.assertThat(hv, Matchers.contains("v"));
+ MatcherAssert.assertThat(hv, Matchers.contains("v"));
}
}
diff --git a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapperFactory.java b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapperFactory.java
index d65b3e017..198103cdd 100644
--- a/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-springmvc/src/test/java/org/apache/servicecomb/swagger/invocation/springmvc/response/TestSpringmvcProducerResponseMapperFactory.java
@@ -24,6 +24,7 @@ import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys;
import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapperFactory;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -67,10 +68,10 @@ public class TestSpringmvcProducerResponseMapperFactory {
ProducerResponseMapper mapper = factory
.createResponseMapper(factorys, responseEntityMethod.getGenericReturnType());
- Assert.assertThat(mapper, Matchers.instanceOf(SpringmvcProducerResponseMapper.class));
+ MatcherAssert.assertThat(mapper, Matchers.instanceOf(SpringmvcProducerResponseMapper.class));
ResponseEntity<String[]> responseEntity = new ResponseEntity<>(new String[] {"a", "b"}, HttpStatus.OK);
Response response = mapper.mapResponse(null, responseEntity);
- Assert.assertThat(response.getResult(), Matchers.arrayContaining("a", "b"));
+ MatcherAssert.assertThat(response.getResult(), Matchers.arrayContaining("a", "b"));
}
}
diff --git a/swagger/swagger-invocation/invocation-validator/src/test/java/org/apache/servicecomb/swagger/invocation/validator/TestDefaultParameterNameProvider.java b/swagger/swagger-invocation/invocation-validator/src/test/java/org/apache/servicecomb/swagger/invocation/validator/TestDefaultParameterNameProvider.java
index fcb228fe2..3ca5c2bb6 100644
--- a/swagger/swagger-invocation/invocation-validator/src/test/java/org/apache/servicecomb/swagger/invocation/validator/TestDefaultParameterNameProvider.java
+++ b/swagger/swagger-invocation/invocation-validator/src/test/java/org/apache/servicecomb/swagger/invocation/validator/TestDefaultParameterNameProvider.java
@@ -18,6 +18,8 @@ package org.apache.servicecomb.swagger.invocation.validator;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -91,23 +93,23 @@ public class TestDefaultParameterNameProvider {
@Test
public void testMethod() throws NoSuchMethodException {
Method method = validatorForTest.getMethod("add", int.class, int.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("a", "b"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("a", "b"));
method = validatorForTest.getMethod("sayHi", String.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("hi"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("hi"));
method = validatorForTest.getMethod("sayHello", ValidatorForTest.Student.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("student"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("student"));
method = validatorForTest.getMethod("setTest", String.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("grade"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("grade"));
method = validatorForTest.getMethod("getNumber");
Assert.assertTrue(parameterNameProvider.getParameterNames(method).isEmpty());
method = validatorForTest.getMethod("setNumber", int.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("number"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(method), Matchers.contains("number"));
}
@Test
public void testConstructor() throws NoSuchMethodException {
Constructor<ValidatorForTest> constructor = validatorForTest.getConstructor(String.class, int.class);
- Assert.assertThat(parameterNameProvider.getParameterNames(constructor), Matchers.contains("grade", "number"));
+ MatcherAssert.assertThat(parameterNameProvider.getParameterNames(constructor), Matchers.contains("grade", "number"));
constructor = validatorForTest.getConstructor();
Assert.assertTrue(parameterNameProvider.getParameterNames(constructor).isEmpty());
diff --git a/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinSpanAspectTest.java b/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinSpanAspectTest.java
index 15a4da68d..a909a7c4f 100644
--- a/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinSpanAspectTest.java
+++ b/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinSpanAspectTest.java
@@ -22,9 +22,9 @@ import static org.apache.servicecomb.tracing.zipkin.ZipkinTracingAdviser.CALL_PA
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.assertThat;
import java.util.List;
+import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.stream.Collectors;
@@ -33,6 +33,7 @@ import org.apache.servicecomb.tracing.zipkin.ZipkinSpanAspectTest.TracingConfig;
import org.apache.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication;
import org.apache.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication.CustomSpanTask;
import org.apache.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication.SomeSlowTask;
+import org.hamcrest.MatcherAssert;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -93,25 +94,25 @@ public class ZipkinSpanAspectTest {
await().atMost(2, SECONDS).until(() -> !spans.isEmpty());
zipkin2.Span span = spans.poll();
- assertThat(span.name(), is("crawl"));
- assertThat(tracedValues(span), contains(SomeSlowTask.class.getMethod("crawl").toString()));
+ MatcherAssert.assertThat(span.name(), is("crawl"));
+ MatcherAssert.assertThat(tracedValues(span), contains(SomeSlowTask.class.getMethod("crawl").toString()));
}
@Test
- public void reportCustomSpanInfomation() throws Exception {
+ public void reportCustomSpanInformation() {
customSpanTask.invoke();
await().atMost(2, SECONDS).until(() -> !spans.isEmpty());
zipkin2.Span span = spans.poll();
- assertThat(span.name(), is("transaction1"));
- assertThat(tracedValues(span), contains("startA"));
+ MatcherAssert.assertThat(span.name(), is("transaction1"));
+ MatcherAssert.assertThat(tracedValues(span), contains("startA"));
}
private List<String> tracedValues(zipkin2.Span spans) {
return spans.tags().entrySet().stream()
.filter(span -> CALL_PATH.equals(span.getKey()) || "error".equals(span.getKey()))
.filter(span -> span.getValue() != null)
- .map(annotation -> new String(annotation.getValue()))
+ .map(Map.Entry::getValue)
.distinct()
.collect(Collectors.toList());
}
diff --git a/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingAdviserTest.java b/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingAdviserTest.java
index e991014cb..d61b85bb3 100644
--- a/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingAdviserTest.java
+++ b/tracing/tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingAdviserTest.java
@@ -24,7 +24,6 @@ import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.lang.reflect.Array;
@@ -40,6 +39,7 @@ import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.apache.servicecomb.tracing.zipkin.ZipkinTracingAdviser.ThrowableSupplier;
+import org.hamcrest.MatcherAssert;
import org.junit.After;
import org.junit.Test;
@@ -82,12 +82,12 @@ public class ZipkinTracingAdviserTest {
public void startsNewRootSpan() throws Throwable {
String result = tracingAdviser.invoke(spanName, path, supplier);
- assertThat(result, is(expected));
+ MatcherAssert.assertThat(result, is(expected));
await().atMost(2, SECONDS).until(() -> !traces.isEmpty());
zipkin2.Span span = traces.values().iterator().next().poll();
- assertThat(span.name(), is(spanName));
- assertThat(tracedValues(span), contains(this.getClass().getCanonicalName()));
+ MatcherAssert.assertThat(span.name(), is(spanName));
+ MatcherAssert.assertThat(tracedValues(span), contains(this.getClass().getCanonicalName()));
}
@Test
@@ -104,8 +104,8 @@ public class ZipkinTracingAdviserTest {
await().atMost(2, SECONDS).until(() -> !traces.isEmpty());
zipkin2.Span span = traces.values().iterator().next().poll();
- assertThat(span.name(), is(spanName));
- assertThat(tracedValues(span), containsInAnyOrder(this.getClass().getCanonicalName(), "RuntimeException: oops"));
+ MatcherAssert.assertThat(span.name(), is(spanName));
+ MatcherAssert.assertThat(tracedValues(span), containsInAnyOrder(this.getClass().getCanonicalName(), "RuntimeException: oops"));
}
@SuppressWarnings({"unused", "try"})
@@ -121,7 +121,7 @@ public class ZipkinTracingAdviserTest {
waitTillAllAreReady(cyclicBarrier);
try (SpanInScope spanInScope = tracing.tracer().withSpanInScope(currentSpan)) {
- assertThat(tracingAdviser.invoke(spanName, path, supplier), is(expected));
+ MatcherAssert.assertThat(tracingAdviser.invoke(spanName, path, supplier), is(expected));
} catch (Throwable throwable) {
fail(throwable.getMessage());
} finally {
@@ -132,16 +132,16 @@ public class ZipkinTracingAdviserTest {
CompletableFuture.allOf(futures).join();
- assertThat(traces.size(), is(nThreads));
+ MatcherAssert.assertThat(traces.size(), is(nThreads));
for (Queue<zipkin2.Span> queue : traces.values()) {
zipkin2.Span child = queue.poll();
- assertThat(child.name(), is(spanName));
+ MatcherAssert.assertThat(child.name(), is(spanName));
zipkin2.Span parent = queue.poll();
- assertThat(child.parentId(), is(parent.id()));
- assertThat(child.traceId(), is(parent.traceId()));
- assertThat(tracedValues(child), contains(this.getClass().getCanonicalName()));
+ MatcherAssert.assertThat(child.parentId(), is(parent.id()));
+ MatcherAssert.assertThat(child.traceId(), is(parent.traceId()));
+ MatcherAssert.assertThat(tracedValues(child), contains(this.getClass().getCanonicalName()));
}
}
@@ -157,7 +157,7 @@ public class ZipkinTracingAdviserTest {
return spans.tags().entrySet().stream()
.filter(span -> CALL_PATH.equals(span.getKey()) || "error".equals(span.getKey()))
.filter(span -> span.getValue() != null)
- .map(annotation -> new String(annotation.getValue()))
+ .map(Map.Entry::getValue)
.distinct()
.collect(Collectors.toList());
}
diff --git a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/message/TestHeaders.java b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/message/TestHeaders.java
index 3a0a0981a..a47f3c114 100644
--- a/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/message/TestHeaders.java
+++ b/transports/transport-highway/src/test/java/org/apache/servicecomb/transport/highway/message/TestHeaders.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@@ -29,8 +30,8 @@ public class TestHeaders {
@Test
public void test1() {
Headers headers = new Headers();
- Assert.assertEquals(null, headers.getFirst("h1"));
- Assert.assertEquals(null, headers.getHeader("h1"));
+ Assert.assertNull(headers.getFirst("h1"));
+ Assert.assertNull(headers.getHeader("h1"));
Map<String, List<Object>> headerMap = new HashMap<>();
List<Object> h1Value = Arrays.asList("h1v1", "h1v2");
@@ -41,8 +42,8 @@ public class TestHeaders {
Assert.assertEquals(headerMap, headers.getHeaderMap());
Assert.assertEquals("h1v1", headers.getFirst("h1"));
- Assert.assertEquals(null, headers.getFirst("h2"));
- Assert.assertEquals(null, headers.getFirst("h3"));
+ Assert.assertNull(headers.getFirst("h2"));
+ Assert.assertNull(headers.getFirst("h3"));
Assert.assertEquals(h1Value, headers.getHeader("h1"));
}
@@ -61,6 +62,6 @@ public class TestHeaders {
headers.addHeader("h", Arrays.asList("v1", "v2"));
headers.addHeader("h", Arrays.asList("v3"));
- Assert.assertThat(headers.getHeader("h"), Matchers.contains("v1", "v2", "v3"));
+ MatcherAssert.assertThat(headers.getHeader("h"), Matchers.contains("v1", "v2", "v3"));
}
}
diff --git a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
index 34a19fe31..3fd1fcfb0 100644
--- a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
@@ -49,6 +49,7 @@ import org.apache.servicecomb.registry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -171,7 +172,7 @@ public class TestRestClientInvocation {
restClientInvocation.invoke(invocation, asyncResp);
Assert.assertSame(resp, response);
- Assert.assertThat(headers.names(),
+ MatcherAssert.assertThat(headers.names(),
Matchers.containsInAnyOrder(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE,
org.apache.servicecomb.core.Const.CSE_CONTEXT));
Assert.assertEquals(TARGET_MICROSERVICE_NAME, headers.get(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE));
@@ -191,7 +192,7 @@ public class TestRestClientInvocation {
restClientInvocation.invoke(invocation, asyncResp);
Assert.assertSame(resp, response);
- Assert.assertThat(headers.names(), Matchers.empty());
+ MatcherAssert.assertThat(headers.names(), Matchers.empty());
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartClientFiltersRequest());
}
@@ -208,7 +209,7 @@ public class TestRestClientInvocation {
restClientInvocation.invoke(invocation, asyncResp);
Assert.assertSame(resp, response);
- Assert.assertThat(headers.names(),
+ MatcherAssert.assertThat(headers.names(),
Matchers.containsInAnyOrder(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE,
org.apache.servicecomb.core.Const.CSE_CONTEXT));
Assert.assertEquals(TARGET_MICROSERVICE_NAME, headers.get(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE));
@@ -223,7 +224,7 @@ public class TestRestClientInvocation {
when(request.send()).thenReturn(Future.succeededFuture(mock(HttpClientResponse.class)));
restClientInvocation.invoke(invocation, asyncResp);
- Assert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.instanceOf(Error.class));
+ MatcherAssert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.instanceOf(Error.class));
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartClientFiltersRequest());
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getFinishClientFiltersResponse());
}
@@ -238,7 +239,7 @@ public class TestRestClientInvocation {
restClientInvocation.invoke(invocation, asyncResp);
restClientInvocation.invoke(invocation, asyncResp);
- Assert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.sameInstance(t));
+ MatcherAssert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.sameInstance(t));
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartClientFiltersRequest());
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getFinishClientFiltersResponse());
}
@@ -342,7 +343,7 @@ public class TestRestClientInvocation {
when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor());
restClientInvocation.processResponseBody(null);
- Assert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.instanceOf(Error.class));
+ MatcherAssert.assertThat(((InvocationException) response.getResult()).getCause(), Matchers.instanceOf(Error.class));
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartClientFiltersResponse());
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getFinishClientFiltersResponse());
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getFinishReceiveResponse());
diff --git a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
index f97b858f6..83cb2cfa2 100644
--- a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
+++ b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestCseXmlWebApplicationContext.java
@@ -22,6 +22,7 @@ import javax.servlet.ServletRegistration.Dynamic;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
@@ -47,7 +48,7 @@ public class TestCseXmlWebApplicationContext {
@Test
public void testGetConfigLocationsEmpty() {
String[] result = context.getConfigLocations();
- Assert.assertThat(result,
+ MatcherAssert.assertThat(result,
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
}
@@ -55,7 +56,7 @@ public class TestCseXmlWebApplicationContext {
public void testGetConfigLocationsEmptyAndDefaultEmpty() {
context.setDefaultBeanResource(null);
String[] result = context.getConfigLocations();
- Assert.assertThat(result,
+ MatcherAssert.assertThat(result,
Matchers.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE));
}
@@ -69,7 +70,7 @@ public class TestCseXmlWebApplicationContext {
};
String[] result = context.getConfigLocations();
- Assert.assertThat(result, Matchers
+ MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}
@@ -82,7 +83,7 @@ public class TestCseXmlWebApplicationContext {
}
};
String[] result = context.getConfigLocations();
- Assert.assertThat(result, Matchers
+ MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}
@@ -95,7 +96,7 @@ public class TestCseXmlWebApplicationContext {
}
};
String[] result = context.getConfigLocations();
- Assert.assertThat(result, Matchers
+ MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b"));
}
@@ -108,7 +109,7 @@ public class TestCseXmlWebApplicationContext {
}
};
String[] result = context.getConfigLocations();
- Assert.assertThat(result, Matchers
+ MatcherAssert.assertThat(result, Matchers
.arrayContaining(BeanUtils.DEFAULT_BEAN_CORE_RESOURCE, BeanUtils.DEFAULT_BEAN_NORMAL_RESOURCE, "a", "b", "c"));
}
diff --git a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestServletUtils.java b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestServletUtils.java
index 04c87c31d..7eb1bc51b 100644
--- a/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestServletUtils.java
+++ b/transports/transport-rest/transport-rest-servlet/src/test/java/org/apache/servicecomb/transport/rest/servlet/TestServletUtils.java
@@ -40,6 +40,7 @@ import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.registry.definition.DefinitionConst;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -107,17 +108,17 @@ public class TestServletUtils {
Collection<String> urlPatterns = Arrays.asList(urlPattern);
String[] result = ServletUtils.filterUrlPatterns(urlPatterns);
- Assert.assertThat(result, Matchers.arrayContaining("/r1/*"));
+ MatcherAssert.assertThat(result, Matchers.arrayContaining("/r1/*"));
result = ServletUtils.filterUrlPatterns(urlPattern);
- Assert.assertThat(result, Matchers.arrayContaining("/r1/*"));
+ MatcherAssert.assertThat(result, Matchers.arrayContaining("/r1/*"));
}
@Test
public void testFilterUrlPatternsEmpty() {
Collection<String> urlPatterns = Arrays.asList(" ", "\t");
String[] result = ServletUtils.filterUrlPatterns(urlPatterns);
- Assert.assertThat(result, Matchers.emptyArray());
+ MatcherAssert.assertThat(result, Matchers.emptyArray());
}
@Test
@@ -144,7 +145,7 @@ public class TestServletUtils {
};
String[] result = ServletUtils.collectUrlPatterns(servletContext, RestServlet.class);
- Assert.assertThat(result, Matchers.emptyArray());
+ MatcherAssert.assertThat(result, Matchers.emptyArray());
}
@Test
@@ -170,7 +171,7 @@ public class TestServletUtils {
};
String[] result = ServletUtils.collectUrlPatterns(servletContext, RestServlet.class);
- Assert.assertThat(result, Matchers.arrayContaining("/r1/*", "/r1/1/*"));
+ MatcherAssert.assertThat(result, Matchers.arrayContaining("/r1/*", "/r1/1/*"));
}
@Test
@@ -202,7 +203,7 @@ public class TestServletUtils {
ServletUtils.saveUrlPrefix(servletContext);
- Assert.assertThat(ClassLoaderScopeContext.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX),
+ MatcherAssert.assertThat(ClassLoaderScopeContext.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX),
Matchers.is("/root/rest"));
ClassLoaderScopeContext.clearClassLoaderScopeProperty();
}
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
index 063abe16e..5f155209d 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestRestServerVerticle.java
@@ -30,6 +30,7 @@ import org.apache.servicecomb.core.transport.AbstractTransport;
import org.apache.servicecomb.foundation.common.Holder;
import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -38,7 +39,6 @@ import org.junit.Test;
import org.mockito.Mockito;
import io.vertx.core.Context;
-import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
@@ -211,14 +211,14 @@ public class TestRestServerVerticle {
@Mock
CorsHandler allowedHeaders(Set<String> headerNames) {
- Assert.assertThat(headerNames, Matchers.containsInAnyOrder("abc", "def"));
+ MatcherAssert.assertThat(headerNames, Matchers.containsInAnyOrder("abc", "def"));
counter.incrementAndGet();
return null;
}
@Mock
CorsHandler exposedHeaders(Set<String> headerNames) {
- Assert.assertThat(headerNames, Matchers.containsInAnyOrder("abc2", "def2"));
+ MatcherAssert.assertThat(headerNames, Matchers.containsInAnyOrder("abc2", "def2"));
counter.incrementAndGet();
return null;
}
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
index 641ad49a0..660c1b77b 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
@@ -18,6 +18,7 @@
package org.apache.servicecomb.transport.rest.vertx;
import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -70,16 +71,16 @@ public class TestTransportConfig {
@Test
public void testGetCompressedAndHeaderSize() {
ArchaiusUtils.setProperty("servicecomb.rest.server.compression", true);
- Assert.assertEquals(true, TransportConfig.getCompressed());
+ Assert.assertTrue(TransportConfig.getCompressed());
ArchaiusUtils.setProperty("servicecomb.rest.server.maxHeaderSize", 2048);
Assert.assertEquals(2048, TransportConfig.getMaxHeaderSize());
}
@Test
public void testGetDecompressed() {
- Assert.assertEquals(false, TransportConfig.getDecompressionSupported());
+ Assert.assertFalse(TransportConfig.getDecompressionSupported());
ArchaiusUtils.setProperty("servicecomb.rest.server.decompressionSupported", true);
- Assert.assertEquals(true, TransportConfig.getDecompressionSupported());
+ Assert.assertTrue(TransportConfig.getDecompressionSupported());
}
@Test
@@ -148,11 +149,11 @@ public class TestTransportConfig {
String configKey = "servicecomb.cors.allowedHeader";
Assert.assertTrue(TransportConfig.getCorsAllowedHeaders().isEmpty());
ArchaiusUtils.setProperty(configKey, "abc");
- Assert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc"));
ArchaiusUtils.setProperty(configKey, "abc, def");
- Assert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
ArchaiusUtils.setProperty(configKey, "abc ,, def");
- Assert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
ArchaiusUtils.setProperty(configKey, "");
Assert.assertTrue(TransportConfig.getCorsAllowedHeaders().isEmpty());
}
@@ -162,11 +163,11 @@ public class TestTransportConfig {
String configKey = "servicecomb.cors.allowedMethod";
Assert.assertTrue(TransportConfig.getCorsAllowedMethods().isEmpty());
ArchaiusUtils.setProperty(configKey, "GET");
- Assert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET"));
ArchaiusUtils.setProperty(configKey, "GET, POST");
- Assert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET", "POST"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET", "POST"));
ArchaiusUtils.setProperty(configKey, "GET,,POST");
- Assert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET", "POST"));
+ MatcherAssert.assertThat(TransportConfig.getCorsAllowedMethods(), Matchers.containsInAnyOrder("GET", "POST"));
ArchaiusUtils.setProperty(configKey, "");
Assert.assertTrue(TransportConfig.getCorsAllowedMethods().isEmpty());
}
@@ -176,11 +177,11 @@ public class TestTransportConfig {
String configKey = "servicecomb.cors.exposedHeader";
Assert.assertTrue(TransportConfig.getCorsExposedHeaders().isEmpty());
ArchaiusUtils.setProperty(configKey, "abc");
- Assert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc"));
+ MatcherAssert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc"));
ArchaiusUtils.setProperty(configKey, "abc, def");
- Assert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
+ MatcherAssert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
ArchaiusUtils.setProperty(configKey, "abc ,, def");
- Assert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
+ MatcherAssert.assertThat(TransportConfig.getCorsExposedHeaders(), Matchers.containsInAnyOrder("abc", "def"));
ArchaiusUtils.setProperty(configKey, "");
Assert.assertTrue(TransportConfig.getCorsExposedHeaders().isEmpty());
}
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
index 7a1f6d728..12890da24 100644
--- a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestDispatcher.java
@@ -38,6 +38,7 @@ import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
@@ -201,10 +202,10 @@ public class TestVertxRestDispatcher {
Deencapsulation.invoke(dispatcher, "failureHandler", context);
- Assert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
- Assert.assertThat(response.responseStatusCode, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode()));
- Assert.assertThat(response.responseStatusMessage, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getReasonPhrase()));
- Assert.assertThat(response.responseChunk,
+ MatcherAssert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
+ MatcherAssert.assertThat(response.responseStatusCode, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode()));
+ MatcherAssert.assertThat(response.responseStatusMessage, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getReasonPhrase()));
+ MatcherAssert.assertThat(response.responseChunk,
Matchers.is("{\"message\":\"" + Status.REQUEST_ENTITY_TOO_LARGE.getReasonPhrase() + "\"}"));
Assert.assertTrue(response.responseEnded);
}
@@ -227,9 +228,9 @@ public class TestVertxRestDispatcher {
Deencapsulation.invoke(dispatcher, "failureHandler", context);
- Assert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
- Assert.assertThat(response.responseStatusCode, Matchers.is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
- Assert.assertThat(response.responseChunk,
+ MatcherAssert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
+ MatcherAssert.assertThat(response.responseStatusCode, Matchers.is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ MatcherAssert.assertThat(response.responseChunk,
Matchers.is("{\"message\":\"" + exceptionMessage + "\"}"));
Assert.assertTrue(response.responseEnded);
}
@@ -252,8 +253,8 @@ public class TestVertxRestDispatcher {
Deencapsulation.invoke(dispatcher, "failureHandler", context);
- Assert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
- Assert.assertThat(response.responseStatusCode, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode()));
+ MatcherAssert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
+ MatcherAssert.assertThat(response.responseStatusCode, Matchers.is(Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode()));
Assert.assertTrue(response.responseEnded);
}
@@ -275,10 +276,10 @@ public class TestVertxRestDispatcher {
Deencapsulation.invoke(dispatcher, "failureHandler", context);
- Assert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
- Assert.assertThat(response.responseStatusCode, Matchers.is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
- Assert.assertThat(response.responseStatusMessage, Matchers.is(Status.INTERNAL_SERVER_ERROR.getReasonPhrase()));
- Assert.assertThat(response.responseChunk,
+ MatcherAssert.assertThat(response.responseHeader, Matchers.hasEntry(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD));
+ MatcherAssert.assertThat(response.responseStatusCode, Matchers.is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ MatcherAssert.assertThat(response.responseStatusMessage, Matchers.is(Status.INTERNAL_SERVER_ERROR.getReasonPhrase()));
+ MatcherAssert.assertThat(response.responseChunk,
Matchers.is("{\"message\":\"" + Status.INTERNAL_SERVER_ERROR.getReasonPhrase() + "\"}"));
Assert.assertTrue(response.responseEnded);
}