diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml index ac7af8e88772..761fc87f5494 100755 --- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml +++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml @@ -73,6 +73,9 @@ + + + diff --git a/parent/pom.xml b/parent/pom.xml index 1c259a2117ba..e1e80e91da24 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -139,7 +139,8 @@ 2.15.0 9.4.11.v20180605 9.4.11.v20180605 - 4.12 + 4.12 + 5.5.0 2.4 @@ -286,7 +287,22 @@ junit junit - ${junit.version} + ${junit4.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit5.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + + + org.junit.jupiter + junit-jupiter-params + ${junit5.version} diff --git a/pom.client.xml b/pom.client.xml index d4ed7878ba44..31e7702a2586 100644 --- a/pom.client.xml +++ b/pom.client.xml @@ -447,6 +447,18 @@ true + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.2 + @@ -473,9 +485,9 @@ maven-checkstyle-plugin ${maven-checkstyle-plugin.version} - checkstyle/checkstyle.xml - checkstyle/checkstyle-suppressions.xml - checkstyle/java.header + eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml + eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml + eng/code-quality-reports/src/main/resources/checkstyle/java.header samedir= UTF-8 true diff --git a/sdk/core/azure-core-amqp/pom.xml b/sdk/core/azure-core-amqp/pom.xml index acdcb042d4c2..1bdae588079a 100644 --- a/sdk/core/azure-core-amqp/pom.xml +++ b/sdk/core/azure-core-amqp/pom.xml @@ -67,8 +67,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine test diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/AmqpShutdownSignalTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/AmqpShutdownSignalTest.java index 400e467549bb..7bf2dcbe2b4a 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/AmqpShutdownSignalTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/AmqpShutdownSignalTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class AmqpShutdownSignalTest { @@ -19,11 +19,11 @@ public void constructor() { AmqpShutdownSignal shutdownSignal = new AmqpShutdownSignal(isTransient, isInitiatedByClient, message); - Assert.assertTrue(shutdownSignal.isTransient()); - Assert.assertTrue(shutdownSignal.isInitiatedByClient()); + assertTrue(shutdownSignal.isTransient()); + assertTrue(shutdownSignal.isInitiatedByClient()); String contents = shutdownSignal.toString(); - Assert.assertNotNull(contents); - Assert.assertTrue(contents.contains(message)); + assertNotNull(contents); + assertTrue(contents.contains(message)); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/ExponentialRetryTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/ExponentialRetryTest.java index 1bf45032e090..1f6f3fe23a0c 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/ExponentialRetryTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/ExponentialRetryTest.java @@ -6,8 +6,8 @@ import com.azure.core.amqp.exception.AmqpException; import com.azure.core.amqp.exception.ErrorCondition; import com.azure.core.amqp.exception.ErrorContext; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.time.Duration; @@ -30,15 +30,15 @@ public void retryDurationIncreases() { // Act retry.incrementRetryCount(); final Duration firstRetryInterval = retry.getNextRetryInterval(exception, remainingTime); - Assert.assertNotNull(firstRetryInterval); + assertNotNull(firstRetryInterval); retry.incrementRetryCount(); final Duration leftoverTime = remainingTime.minus(firstRetryInterval); final Duration secondRetryInterval = retry.getNextRetryInterval(exception, leftoverTime); // Assert - Assert.assertNotNull(secondRetryInterval); - Assert.assertTrue(secondRetryInterval.toNanos() > firstRetryInterval.toNanos()); + assertNotNull(secondRetryInterval); + assertTrue(secondRetryInterval.toNanos() > firstRetryInterval.toNanos()); } /** @@ -61,12 +61,12 @@ public void retryCloneBehavesSame() { final Duration cloneRetryInterval = clone.getNextRetryInterval(exception, remainingTime); // Assert - Assert.assertNotNull(retryInterval); - Assert.assertNotNull(cloneRetryInterval); + assertNotNull(retryInterval); + assertNotNull(cloneRetryInterval); // The retry interval for the clone will be larger because we've incremented the retry count, so it should // calculate a longer waiting period. - Assert.assertTrue(cloneRetryInterval.toNanos() > retryInterval.toNanos()); + assertTrue(cloneRetryInterval.toNanos() > retryInterval.toNanos()); } @Test @@ -84,12 +84,12 @@ public void retryClone() { final Duration cloneRetryInterval = clone.getNextRetryInterval(exception, remainingTime); // Assert - Assert.assertNotSame(retry, clone); - Assert.assertEquals(retry, clone); - Assert.assertEquals(retry.hashCode(), clone.hashCode()); + assertNotSame(retry, clone); + assertEquals(retry, clone); + assertEquals(retry.hashCode(), clone.hashCode()); - Assert.assertNotNull(retryInterval); - Assert.assertNotNull(cloneRetryInterval); - Assert.assertEquals(retryInterval, cloneRetryInterval); + assertNotNull(retryInterval); + assertNotNull(cloneRetryInterval); + assertEquals(retryInterval, cloneRetryInterval); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/MessageConstantTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/MessageConstantTest.java index e08bb10ee561..deaee43a75de 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/MessageConstantTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/MessageConstantTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class MessageConstantTest { @@ -16,7 +16,7 @@ public void createFromString() { String header = "absolute-expiry-time"; MessageConstant actual = MessageConstant.fromString(header); - Assert.assertEquals(MessageConstant.ABSOLUTE_EXPIRY_TIME, actual); + assertEquals(MessageConstant.ABSOLUTE_EXPIRY_TIME, actual); } /** @@ -27,6 +27,6 @@ public void getHeaderValue() { String expected = "x-opt-enqueued-time"; String actual = MessageConstant.ENQUEUED_TIME_UTC_ANNOTATION_NAME.getValue(); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/RetryTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/RetryTest.java index fa30f6d5cce2..65eff127396b 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/RetryTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/RetryTest.java @@ -6,8 +6,8 @@ import com.azure.core.amqp.exception.AmqpException; import com.azure.core.amqp.exception.ErrorCondition; import com.azure.core.amqp.exception.ErrorContext; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.time.Duration; @@ -27,15 +27,15 @@ public void defaultRetryPolicy() { // Act retry.incrementRetryCount(); final Duration firstRetryInterval = retry.getNextRetryInterval(exception, remainingTime); - Assert.assertNotNull(firstRetryInterval); + assertNotNull(firstRetryInterval); retry.incrementRetryCount(); final Duration leftoverTime = remainingTime.minus(firstRetryInterval); final Duration secondRetryInterval = retry.getNextRetryInterval(exception, leftoverTime); // Assert - Assert.assertNotNull(secondRetryInterval); - Assert.assertTrue(secondRetryInterval.toNanos() > firstRetryInterval.toNanos()); + assertNotNull(secondRetryInterval); + assertTrue(secondRetryInterval.toNanos() > firstRetryInterval.toNanos()); } /** @@ -44,39 +44,39 @@ public void defaultRetryPolicy() { @Test public void canIncrementRetryCount() { Retry retry = Retry.getDefaultRetry(); - Assert.assertEquals(0, retry.getRetryCount()); - Assert.assertEquals(0, retry.incrementRetryCount()); + assertEquals(0, retry.getRetryCount()); + assertEquals(0, retry.incrementRetryCount()); - Assert.assertEquals(1, retry.getRetryCount()); - Assert.assertEquals(1, retry.incrementRetryCount()); + assertEquals(1, retry.getRetryCount()); + assertEquals(1, retry.incrementRetryCount()); - Assert.assertEquals(2, retry.getRetryCount()); - Assert.assertEquals(2, retry.incrementRetryCount()); + assertEquals(2, retry.getRetryCount()); + assertEquals(2, retry.incrementRetryCount()); retry.resetRetryInterval(); - Assert.assertEquals(0, retry.getRetryCount()); - Assert.assertEquals(0, retry.incrementRetryCount()); + assertEquals(0, retry.getRetryCount()); + assertEquals(0, retry.incrementRetryCount()); - Assert.assertEquals(1, retry.getRetryCount()); + assertEquals(1, retry.getRetryCount()); } @Test public void isRetriableException() { final Exception exception = new AmqpException(true, "error message", errorContext); - Assert.assertTrue(Retry.isRetriableException(exception)); + assertTrue(Retry.isRetriableException(exception)); } @Test public void notRetriableException() { final Exception invalidException = new RuntimeException("invalid exception"); - Assert.assertFalse(Retry.isRetriableException(invalidException)); + assertFalse(Retry.isRetriableException(invalidException)); } @Test public void notRetriableExceptionNotTransient() { final Exception invalidException = new AmqpException(false, "Some test exception", errorContext); - Assert.assertFalse(Retry.isRetriableException(invalidException)); + assertFalse(Retry.isRetriableException(invalidException)); } /** @@ -94,8 +94,8 @@ public void noRetryPolicy() { int retryCount = noRetry.incrementRetryCount(); // Assert - Assert.assertEquals(0, retryCount); - Assert.assertNull(nextRetryInterval); + assertEquals(0, retryCount); + assertNull(nextRetryInterval); } /** @@ -118,7 +118,7 @@ public void excessMaxRetry() { final Duration nextRetryInterval = retry.getNextRetryInterval(exception, sixtySec); // Assert - Assert.assertEquals(Retry.DEFAULT_MAX_RETRY_COUNT, retry.getRetryCount()); - Assert.assertNull(nextRetryInterval); + assertEquals(Retry.DEFAULT_MAX_RETRY_COUNT, retry.getRetryCount()); + assertNull(nextRetryInterval); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/TransportTypeTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/TransportTypeTest.java index 01f798dfa22d..e7d2881f9f9a 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/TransportTypeTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/TransportTypeTest.java @@ -3,8 +3,9 @@ package com.azure.core.amqp; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; public class TransportTypeTest { @@ -16,16 +17,18 @@ public void createFromString() { String socketString = "Amqpwebsockets"; TransportType actual = TransportType.fromString(socketString); - Assert.assertEquals(TransportType.AMQP_WEB_SOCKETS, actual); + assertEquals(TransportType.AMQP_WEB_SOCKETS, actual); } /** * Verifies that an exception is thrown when an unknown transport type string is passed. */ - @Test(expected = IllegalArgumentException.class) + @Test public void illegalTransportTypeString() { - String socketString = "AmqpNonExistent"; + final String socketString = "AmqpNonExistent"; - TransportType actual = TransportType.fromString(socketString); + assertThrows(IllegalArgumentException.class, () -> { + TransportType actual = TransportType.fromString(socketString); + }); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpExceptionTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpExceptionTest.java index c61fad1028c3..59c2d30364db 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpExceptionTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpExceptionTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class AmqpExceptionTest { private final SessionErrorContext context = new SessionErrorContext("namespace-test", "entity-path-test"); @@ -19,17 +19,17 @@ public void constructor() { AmqpException exception = new AmqpException(true, message, context); // Assert - Assert.assertTrue(exception.isTransient()); - Assert.assertNotNull(exception.getMessage()); - Assert.assertTrue(exception.getMessage().contains(message)); + assertTrue(exception.isTransient()); + assertNotNull(exception.getMessage()); + assertTrue(exception.getMessage().contains(message)); - Assert.assertTrue(exception.getContext() instanceof SessionErrorContext); + assertTrue(exception.getContext() instanceof SessionErrorContext); SessionErrorContext actualContext = (SessionErrorContext) exception.getContext(); - Assert.assertEquals(context.getNamespace(), actualContext.getNamespace()); - Assert.assertEquals(context.getEntityPath(), actualContext.getEntityPath()); + assertEquals(context.getNamespace(), actualContext.getNamespace()); + assertEquals(context.getEntityPath(), actualContext.getEntityPath()); - Assert.assertNull(exception.getErrorCondition()); + assertNull(exception.getErrorCondition()); } /** @@ -45,14 +45,14 @@ public void constructorErrorCondition() { AmqpException exception = new AmqpException(false, condition, message, innerException, context); // Assert - Assert.assertEquals(condition, exception.getErrorCondition()); + assertEquals(condition, exception.getErrorCondition()); - Assert.assertTrue(exception.getContext() instanceof SessionErrorContext); + assertTrue(exception.getContext() instanceof SessionErrorContext); SessionErrorContext actualContext = (SessionErrorContext) exception.getContext(); - Assert.assertEquals(context.getNamespace(), actualContext.getNamespace()); - Assert.assertEquals(context.getEntityPath(), actualContext.getEntityPath()); + assertEquals(context.getNamespace(), actualContext.getNamespace()); + assertEquals(context.getEntityPath(), actualContext.getEntityPath()); - Assert.assertSame(innerException, exception.getCause()); + assertSame(innerException, exception.getCause()); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpResponseCodeTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpResponseCodeTest.java index 5675f493027f..857dc8ecae47 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpResponseCodeTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/AmqpResponseCodeTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class AmqpResponseCodeTest { /** @@ -17,7 +17,7 @@ public void createFromInteger() { AmqpResponseCode actual = AmqpResponseCode.fromValue(forbidden); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } /** @@ -28,6 +28,6 @@ public void returnsCorrectValue() { int expected = 404; AmqpResponseCode forbidden = AmqpResponseCode.NOT_FOUND; - Assert.assertEquals(expected, forbidden.getValue()); + assertEquals(expected, forbidden.getValue()); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ErrorContextTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ErrorContextTest.java index 8fad41ea9296..d095931536ac 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ErrorContextTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ErrorContextTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ErrorContextTest { /** @@ -19,24 +19,28 @@ public void constructor() { ErrorContext context = new ErrorContext(namespace); // Assert - Assert.assertEquals(namespace, context.getNamespace()); + assertEquals(namespace, context.getNamespace()); } /** * Verifies an exception is thrown if namespace is an empty string. */ - @Test(expected = IllegalArgumentException.class) + @Test public void constructorEmptyString() { // Act - ErrorContext context = new ErrorContext(""); + assertThrows(IllegalArgumentException.class, () -> { + ErrorContext context = new ErrorContext(""); + }); } /** * Verifies an exception is thrown if namespace is null. */ - @Test(expected = IllegalArgumentException.class) + @Test public void constructorNull() { // Act - ErrorContext context = new ErrorContext(null); + assertThrows(IllegalArgumentException.class, () -> { + ErrorContext context = new ErrorContext(null); + }); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ExceptionUtilTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ExceptionUtilTest.java index 77568cf5f563..a72d28aa8a04 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ExceptionUtilTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/ExceptionUtilTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ExceptionUtilTest { private final ErrorContext context = new ErrorContext("test-namespace"); @@ -22,14 +22,14 @@ public void createsCorrectException() { Exception exception = ExceptionUtil.toException(condition.getErrorCondition(), message, context); // Assert - Assert.assertTrue(exception instanceof AmqpException); + assertTrue(exception instanceof AmqpException); AmqpException amqpException = (AmqpException) exception; - Assert.assertEquals(condition, amqpException.getErrorCondition()); - Assert.assertFalse(amqpException.isTransient()); - Assert.assertSame(context, amqpException.getContext()); - Assert.assertTrue(amqpException.getMessage().startsWith(message)); + assertEquals(condition, amqpException.getErrorCondition()); + assertFalse(amqpException.isTransient()); + assertSame(context, amqpException.getContext()); + assertTrue(amqpException.getMessage().startsWith(message)); } /** @@ -47,14 +47,14 @@ public void createsNotFoundException() { Exception exception = ExceptionUtil.amqpResponseCodeToException(notFound.getValue(), message, context); // Assert - Assert.assertTrue(exception instanceof AmqpException); + assertTrue(exception instanceof AmqpException); AmqpException amqpException = (AmqpException) exception; - Assert.assertEquals(condition, amqpException.getErrorCondition()); - Assert.assertFalse(amqpException.isTransient()); - Assert.assertSame(context, amqpException.getContext()); - Assert.assertTrue(amqpException.getMessage().contains(message)); + assertEquals(condition, amqpException.getErrorCondition()); + assertFalse(amqpException.isTransient()); + assertSame(context, amqpException.getContext()); + assertTrue(amqpException.getMessage().contains(message)); } @@ -72,14 +72,14 @@ public void createsNotFoundExceptionNotMatches() { Exception exception = ExceptionUtil.amqpResponseCodeToException(notFound.getValue(), message, context); // Assert - Assert.assertTrue(exception instanceof AmqpException); + assertTrue(exception instanceof AmqpException); AmqpException amqpException = (AmqpException) exception; - Assert.assertEquals(condition, amqpException.getErrorCondition()); - Assert.assertTrue(amqpException.isTransient()); - Assert.assertSame(context, amqpException.getContext()); - Assert.assertTrue(amqpException.getMessage().contains(message)); + assertEquals(condition, amqpException.getErrorCondition()); + assertTrue(amqpException.isTransient()); + assertSame(context, amqpException.getContext()); + assertTrue(amqpException.getMessage().contains(message)); } /** @@ -95,14 +95,14 @@ public void createsFromStatusCode() { Exception exception = ExceptionUtil.amqpResponseCodeToException(responseCode.getValue(), message, context); // Assert - Assert.assertTrue(exception instanceof AmqpException); + assertTrue(exception instanceof AmqpException); AmqpException amqpException = (AmqpException) exception; - Assert.assertEquals(actualCondition, amqpException.getErrorCondition()); - Assert.assertFalse(amqpException.isTransient()); - Assert.assertSame(context, amqpException.getContext()); + assertEquals(actualCondition, amqpException.getErrorCondition()); + assertFalse(amqpException.isTransient()); + assertSame(context, amqpException.getContext()); - Assert.assertTrue(amqpException.getMessage().contains(message)); + assertTrue(amqpException.getMessage().contains(message)); } /** @@ -117,13 +117,13 @@ public void createsFromNonExistentStatusCode() { Exception exception = ExceptionUtil.amqpResponseCodeToException(unknownCode, message, context); // Assert - Assert.assertTrue(exception instanceof AmqpException); + assertTrue(exception instanceof AmqpException); AmqpException amqpException = (AmqpException) exception; - Assert.assertNull(amqpException.getErrorCondition()); - Assert.assertTrue(amqpException.isTransient()); - Assert.assertSame(context, amqpException.getContext()); + assertNull(amqpException.getErrorCondition()); + assertTrue(amqpException.isTransient()); + assertSame(context, amqpException.getContext()); - Assert.assertTrue(amqpException.getMessage().contains(message)); + assertTrue(amqpException.getMessage().contains(message)); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/LinkErrorContextTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/LinkErrorContextTest.java index 13f39bf159bd..457b1128dc43 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/LinkErrorContextTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/LinkErrorContextTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class LinkErrorContextTest { /** @@ -22,9 +22,9 @@ public void constructor() { LinkErrorContext context = new LinkErrorContext(namespace, entity, trackingId, credits); // Assert - Assert.assertEquals(namespace, context.getNamespace()); - Assert.assertEquals(entity, context.getEntityPath()); - Assert.assertEquals(trackingId, context.getTrackingId()); - Assert.assertEquals(credits, context.getLinkCredit()); + assertEquals(namespace, context.getNamespace()); + assertEquals(entity, context.getEntityPath()); + assertEquals(trackingId, context.getTrackingId()); + assertEquals(credits, context.getLinkCredit()); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/OperationCancelledExceptionTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/OperationCancelledExceptionTest.java index fb77190d9ea6..41a807330451 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/OperationCancelledExceptionTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/OperationCancelledExceptionTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class OperationCancelledExceptionTest { @Test @@ -12,7 +12,7 @@ public void correctMessage() { final String message = "A test message."; final OperationCancelledException exception = new OperationCancelledException(message, null); - Assert.assertEquals(message, exception.getMessage()); + assertEquals(message, exception.getMessage()); } @Test @@ -25,7 +25,7 @@ public void correctMessageAndThrowable() { final OperationCancelledException exception = new OperationCancelledException(message, innerException, null); // Arrange - Assert.assertEquals(message, exception.getMessage()); - Assert.assertEquals(innerException, exception.getCause()); + assertEquals(message, exception.getMessage()); + assertEquals(innerException, exception.getCause()); } } diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/SessionErrorContextTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/SessionErrorContextTest.java index 5d3355a7ee9c..b97a2c1fafcb 100644 --- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/SessionErrorContextTest.java +++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/exception/SessionErrorContextTest.java @@ -3,8 +3,8 @@ package com.azure.core.amqp.exception; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class SessionErrorContextTest { /** @@ -20,7 +20,7 @@ public void constructor() { SessionErrorContext context = new SessionErrorContext(namespace, entity); // Assert - Assert.assertEquals(namespace, context.getNamespace()); - Assert.assertEquals(entity, context.getEntityPath()); + assertEquals(namespace, context.getNamespace()); + assertEquals(entity, context.getEntityPath()); } } diff --git a/sdk/core/azure-core-management/pom.xml b/sdk/core/azure-core-management/pom.xml index 19accb8aaa85..b79bb7bb0b55 100644 --- a/sdk/core/azure-core-management/pom.xml +++ b/sdk/core/azure-core-management/pom.xml @@ -61,8 +61,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine test diff --git a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureProxyToRestProxyTests.java b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureProxyToRestProxyTests.java index 8e6e63c015b6..088ba4e59f29 100644 --- a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureProxyToRestProxyTests.java +++ b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureProxyToRestProxyTests.java @@ -28,20 +28,13 @@ import com.azure.core.implementation.http.ContentType; import com.azure.core.management.implementation.AzureProxy; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.LinkedHashMap; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public abstract class AzureProxyToRestProxyTests { /** * Get the HTTP client that will be used for each test. This will be called once per test. @@ -739,10 +732,9 @@ public void service18GetStatus300WithExpectedResponse300() { .getStatus300WithExpectedResponse300(); } - @Test(expected = HttpResponseException.class) + @Test public void service18GetStatus400() { - createService(Service18.class) - .getStatus400(); + assertThrows(HttpResponseException.class, () -> createService(Service18.class).getStatus400()); } @Test @@ -751,10 +743,9 @@ public void service18GetStatus400WithExpectedResponse400() { .getStatus400WithExpectedResponse400(); } - @Test(expected = HttpResponseException.class) + @Test public void service18GetStatus500() { - createService(Service18.class) - .getStatus500(); + assertThrows(HttpResponseException.class, () -> createService(Service18.class).getStatus500()); } @Test @@ -772,7 +763,7 @@ private T createService(Class serviceClass) { } private static void assertContains(String value, String expectedSubstring) { - assertTrue("Expected \"" + value + "\" to contain \"" + expectedSubstring + "\".", value.contains(expectedSubstring)); + assertTrue(value.contains(expectedSubstring), "Expected \"" + value + "\" to contain \"" + expectedSubstring + "\"."); } private static void assertMatchWithHttpOrHttps(String url1, String url2) { @@ -784,7 +775,7 @@ private static void assertMatchWithHttpOrHttps(String url1, String url2) { if (s2.equalsIgnoreCase(url2)) { return; } - Assert.assertTrue("'" + url2 + "' does not match with '" + s1 + "' or '" + s2 + "'.", false); + fail("'" + url2 + "' does not match with '" + s1 + "' or '" + s2 + "'."); } } diff --git a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureTests.java b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureTests.java index 68313eadad1a..f5a6ac6d8e3e 100644 --- a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureTests.java +++ b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/AzureTests.java @@ -25,6 +25,6 @@ public interface HttpBinService { // .build(); // HttpBinService service = RestProxy.create(HttpBinService.class, client); // -// Assert.assertEquals("http://vault1.vault.azure.net/secrets/{secretName}", service.getSecret("http://vault1.vault.azure.net", "secret1")); +// assertEquals("http://vault1.vault.azure.net/secrets/{secretName}", service.getSecret("http://vault1.vault.azure.net", "secret1")); // } } diff --git a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/PagedListTests.java b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/PagedListTests.java index 6fd9eb84483e..5554d6e72a31 100644 --- a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/PagedListTests.java +++ b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/PagedListTests.java @@ -3,9 +3,10 @@ package com.azure.core.management; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import java.util.ArrayList; @@ -17,7 +18,7 @@ public class PagedListTests { private PagedList list; - @Before + @BeforeEach public void setupList() { list = new PagedList(new TestPage(0, 21)) { @Override @@ -30,19 +31,19 @@ public Page nextPage(String nextPageLink) { @Test public void sizeTest() { - Assert.assertEquals(20, list.size()); + assertEquals(20, list.size()); } @Test public void getTest() { - Assert.assertEquals(15, (int) list.get(15)); + assertEquals(15, (int) list.get(15)); } @Test public void iterateTest() { int j = 0; for (int i : list) { - Assert.assertEquals(i, j++); + assertEquals(i, j++); } } @@ -50,52 +51,52 @@ public void iterateTest() { public void removeTest() { Integer i = list.get(10); list.remove(10); - Assert.assertEquals(19, list.size()); - Assert.assertEquals(19, (int) list.get(18)); + assertEquals(19, list.size()); + assertEquals(19, (int) list.get(18)); } @Test public void addTest() { Integer i = list.get(10); list.add(100); - Assert.assertEquals(21, list.size()); - Assert.assertEquals(100, (int) list.get(11)); - Assert.assertEquals(19, (int) list.get(20)); + assertEquals(21, list.size()); + assertEquals(100, (int) list.get(11)); + assertEquals(19, (int) list.get(20)); } @Test public void containsTest() { - Assert.assertTrue(list.contains(0)); - Assert.assertTrue(list.contains(3)); - Assert.assertTrue(list.contains(19)); - Assert.assertFalse(list.contains(20)); + assertTrue(list.contains(0)); + assertTrue(list.contains(3)); + assertTrue(list.contains(19)); + assertFalse(list.contains(20)); } @Test public void containsAllTest() { List subList = new ArrayList<>(); subList.addAll(Arrays.asList(0, 3, 19)); - Assert.assertTrue(list.containsAll(subList)); + assertTrue(list.containsAll(subList)); subList.add(20); - Assert.assertFalse(list.containsAll(subList)); + assertFalse(list.containsAll(subList)); } @Test public void subListTest() { List subList = list.subList(5, 15); - Assert.assertEquals(10, subList.size()); - Assert.assertTrue(list.containsAll(subList)); - Assert.assertEquals(7, (int) subList.get(2)); + assertEquals(10, subList.size()); + assertTrue(list.containsAll(subList)); + assertEquals(7, (int) subList.get(2)); } @Test public void testIndexOf() { - Assert.assertEquals(15, list.indexOf(15)); + assertEquals(15, list.indexOf(15)); } @Test public void testLastIndexOf() { - Assert.assertEquals(15, list.lastIndexOf(15)); + assertEquals(15, list.lastIndexOf(15)); } @@ -105,7 +106,7 @@ public void testIteratorWithListSizeInvocation() { list.size(); int j = 0; while (itr.hasNext()) { - Assert.assertEquals(j++, (long) itr.next()); + assertEquals(j++, (long) itr.next()); } } @@ -114,13 +115,13 @@ public void testIteratorPartsWithSizeInvocation() { ListIterator itr = list.listIterator(); int j = 0; while (j < 5) { - Assert.assertTrue(itr.hasNext()); - Assert.assertEquals(j++, (long) itr.next()); + assertTrue(itr.hasNext()); + assertEquals(j++, (long) itr.next()); } list.size(); while (j < 10) { - Assert.assertTrue(itr.hasNext()); - Assert.assertEquals(j++, (long) itr.next()); + assertTrue(itr.hasNext()); + assertEquals(j++, (long) itr.next()); } } @@ -129,19 +130,19 @@ public void testIteratorWithLoadNextPageInvocation() { ListIterator itr = list.listIterator(); int j = 0; while (j < 5) { - Assert.assertTrue(itr.hasNext()); - Assert.assertEquals(j++, (long) itr.next()); + assertTrue(itr.hasNext()); + assertEquals(j++, (long) itr.next()); } list.loadNextPage(); while (j < 10) { - Assert.assertTrue(itr.hasNext()); - Assert.assertEquals(j++, (long) itr.next()); + assertTrue(itr.hasNext()); + assertEquals(j++, (long) itr.next()); } list.loadNextPage(); while (itr.hasNext()) { - Assert.assertEquals(j++, (long) itr.next()); + assertEquals(j++, (long) itr.next()); } - Assert.assertEquals(20, j); + assertEquals(20, j); } @Test @@ -153,20 +154,20 @@ public void testIteratorOperations() { } catch (IllegalStateException ex) { expectedException = ex; } - Assert.assertNotNull(expectedException); + assertNotNull(expectedException); ListIterator itr2 = list.listIterator(); - Assert.assertTrue(itr2.hasNext()); - Assert.assertEquals(0, (long) itr2.next()); + assertTrue(itr2.hasNext()); + assertEquals(0, (long) itr2.next()); itr2.remove(); - Assert.assertTrue(itr2.hasNext()); - Assert.assertEquals(1, (long) itr2.next()); + assertTrue(itr2.hasNext()); + assertEquals(1, (long) itr2.next()); itr2.set(100); - Assert.assertTrue(itr2.hasPrevious()); - Assert.assertEquals(100, (long) itr2.previous()); - Assert.assertTrue(itr2.hasNext()); - Assert.assertEquals(100, (long) itr2.next()); + assertTrue(itr2.hasPrevious()); + assertEquals(100, (long) itr2.previous()); + assertTrue(itr2.hasNext()); + assertEquals(100, (long) itr2.next()); } @Test @@ -178,7 +179,7 @@ public void testAddViaIteratorWhileIterating() { itr1.add(99); } } - Assert.assertEquals(30, list.size()); + assertEquals(30, list.size()); } @Test @@ -188,7 +189,7 @@ public void testRemoveViaIteratorWhileIterating() { itr1.next(); itr1.remove(); } - Assert.assertEquals(0, list.size()); + assertEquals(0, list.size()); } @Test @@ -258,10 +259,10 @@ public List items() { ListIterator itr = pagedList.listIterator(); int c = 1; while (itr.hasNext()) { - Assert.assertEquals(c, (int) itr.next()); + assertEquals(c, (int) itr.next()); c++; } - Assert.assertEquals(7, c); + assertEquals(7, c); } @Test @@ -301,11 +302,11 @@ public Flux get() { final Integer[] cnt = new Integer[] { 0 }; obpl.toFlux().subscribe(integer -> { - Assert.assertEquals(cnt[0], integer); + assertEquals(cnt[0], integer); cnt[0]++; }); - Assert.assertEquals(20, (long) cnt[0]); - Assert.assertEquals(19, obpl.loadNextPageCallCount); + assertEquals(20, (long) cnt[0]); + assertEquals(19, obpl.loadNextPageCallCount); } diff --git a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/AzureProxyTests.java b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/AzureProxyTests.java index 7f1de50865f5..4b9a2d19a50f 100644 --- a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/AzureProxyTests.java +++ b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/AzureProxyTests.java @@ -24,10 +24,10 @@ import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,21 +35,18 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class AzureProxyTests { private long delayInMillisecondsBackup; - @Before + @BeforeEach public void beforeTest() { delayInMillisecondsBackup = AzureProxy.defaultDelayInMilliseconds(); AzureProxy.setDefaultPollingDelayInMilliseconds(0); } - @After + @AfterEach public void afterTest() { AzureProxy.setDefaultPollingDelayInMilliseconds(delayInMillisecondsBackup); } @@ -396,7 +393,7 @@ public void createAsyncWithAzureAsyncOperationAndPolls() { } @Test - @Ignore("Test does not run in a stable fashion across Windows, MacOS, and Linux") + @Disabled("Test does not run in a stable fashion across Windows, MacOS, and Linux") public void createAsyncWithAzureAsyncOperationAndPollsWithDelay() throws InterruptedException { final long delayInMilliseconds = 100; AzureProxy.setDefaultPollingDelayInMilliseconds(delayInMilliseconds); @@ -859,7 +856,7 @@ private static T createMockService(Class serviceClass, MockAzureHttpClien } private static void assertContains(String value, String expectedSubstring) { - assertTrue("Expected \"" + value + "\" to contain \"" + expectedSubstring + "\".", value.contains(expectedSubstring)); + assertTrue(value.contains(expectedSubstring), "Expected \"" + value + "\" to contain \"" + expectedSubstring + "\"."); } } diff --git a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/ValueTests.java b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/ValueTests.java index 14035b0021b3..3735d737fda2 100644 --- a/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/ValueTests.java +++ b/sdk/core/azure-core-management/src/test/java/com/azure/core/management/implementation/ValueTests.java @@ -3,10 +3,9 @@ package com.azure.core.management.implementation; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class ValueTests { @Test diff --git a/sdk/core/azure-core-test/pom.xml b/sdk/core/azure-core-test/pom.xml index 7dd327ef2b29..de3327042ce6 100644 --- a/sdk/core/azure-core-test/pom.xml +++ b/sdk/core/azure-core-test/pom.xml @@ -45,8 +45,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestBase.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestBase.java index 6bc1b4a0e6ae..ef1542ba4b6d 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestBase.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestBase.java @@ -4,11 +4,10 @@ import com.azure.core.util.configuration.ConfigurationManager; import com.azure.core.test.utils.TestResourceNamer; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +31,7 @@ public abstract class TestBase { * Before tests are executed, determines the test mode by reading the {@link TestBase#AZURE_TEST_MODE} environment * variable. If it is not set, {@link TestMode#PLAYBACK} */ - @BeforeClass + @BeforeAll public static void setupClass() { testMode = initializeTestMode(); } @@ -41,7 +40,7 @@ public static void setupClass() { * Sets-up the {@link TestBase#testResourceNamer} and {@link TestBase#interceptorManager} before each test case is run. * Then calls its implementing class to perform any other set-up commands. */ - @Before + @BeforeEach public void setupTest() { final String testName = testName(); if (logger.isInfoEnabled()) { @@ -54,7 +53,7 @@ public void setupTest() { if (logger.isErrorEnabled()) { logger.error("Could not create interceptor for {}", testName, e); } - Assert.fail(); + Assertions.fail(); } testResourceNamer = new TestResourceNamer(testName, testMode, interceptorManager.getRecordedData()); @@ -64,7 +63,7 @@ public void setupTest() { /** * Disposes of {@link InterceptorManager} and its inheriting class' resources. */ - @After + @AfterEach public void teardownTest() { afterTest(); interceptorManager.close(); @@ -82,7 +81,7 @@ public TestMode getTestMode() { /** * Gets the name of the current test being run. *

- * NOTE: This could not be implemented in the base class using {@link TestName} because it always returns {@code + * NOTE: This could not be implemented in the base class using TestName because it always returns {@code * null}. See https://stackoverflow.com/a/16113631/4220757. * * @return The name of the current test. diff --git a/sdk/core/azure-core/pom.xml b/sdk/core/azure-core/pom.xml index 33deba0573e1..899ed32bd787 100644 --- a/sdk/core/azure-core/pom.xml +++ b/sdk/core/azure-core/pom.xml @@ -104,8 +104,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/ConfigurationTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/ConfigurationTests.java index 3ac2eca6bd20..c20e616f85c8 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/ConfigurationTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/ConfigurationTests.java @@ -5,12 +5,9 @@ import com.azure.core.util.configuration.BaseConfigurations; import com.azure.core.util.configuration.ConfigurationManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the configuration API. diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/UserAgentTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/UserAgentTests.java index 404631e808c4..f50005b3a50c 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/UserAgentTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/UserAgentTests.java @@ -10,8 +10,8 @@ import com.azure.core.http.MockHttpClient; import com.azure.core.http.MockHttpResponse; import com.azure.core.http.policy.UserAgentPolicy; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.URL; @@ -23,7 +23,7 @@ public void defaultUserAgentTests() throws Exception { .httpClient(new MockHttpClient() { @Override public Mono send(HttpRequest request) { - Assert.assertEquals( + assertEquals( request.headers().value("User-Agent"), "AutoRest-Java"); return Mono.just(new MockHttpResponse(request, 200)); @@ -35,7 +35,7 @@ public Mono send(HttpRequest request) { HttpResponse response = pipeline.send(new HttpRequest( HttpMethod.GET, new URL("http://localhost"))).block(); - Assert.assertEquals(200, response.statusCode()); + assertEquals(200, response.statusCode()); } @Test @@ -45,7 +45,7 @@ public void customUserAgentTests() throws Exception { @Override public Mono send(HttpRequest request) { String header = request.headers().value("User-Agent"); - Assert.assertEquals("Awesome", header); + assertEquals("Awesome", header); return Mono.just(new MockHttpResponse(request, 200)); } }) @@ -54,6 +54,6 @@ public Mono send(HttpRequest request) { HttpResponse response = pipeline.send(new HttpRequest(HttpMethod.GET, new URL("http://localhost"))).block(); - Assert.assertEquals(200, response.statusCode()); + assertEquals(200, response.statusCode()); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/credentials/CredentialsTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/credentials/CredentialsTests.java index 2362bf9d5b99..9b545e503a8f 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/credentials/CredentialsTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/credentials/CredentialsTests.java @@ -9,13 +9,14 @@ import com.azure.core.http.MockHttpClient; import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; import com.azure.core.http.policy.HttpPipelinePolicy; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.URL; import java.time.OffsetDateTime; +import static org.junit.jupiter.api.Assertions.*; + public class CredentialsTests { @Test @@ -24,7 +25,7 @@ public void basicCredentialsTest() throws Exception { HttpPipelinePolicy auditorPolicy = (context, next) -> { String headerValue = context.httpRequest().headers().value("Authorization"); - Assert.assertEquals("Basic dXNlcjpwYXNz", headerValue); + assertEquals("Basic dXNlcjpwYXNz", headerValue); return next.process(); }; // @@ -52,7 +53,7 @@ public Mono getToken(String... scopes) { HttpPipelinePolicy auditorPolicy = (context, next) -> { String headerValue = context.httpRequest().headers().value("Authorization"); - Assert.assertEquals("Bearer this_is_a_token", headerValue); + assertEquals("Bearer this_is_a_token", headerValue); return next.process(); }; diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/credentials/TokenCacheTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/credentials/TokenCacheTests.java index 321a62c52002..dbd5e519a36f 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/credentials/TokenCacheTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/credentials/TokenCacheTests.java @@ -3,8 +3,8 @@ package com.azure.core.credentials; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -44,8 +44,8 @@ public void testOnlyOneThreadRefreshesToken() throws Exception { .subscribe(); latch.await(); - Assert.assertTrue(maxMillis.get() > 1000); - Assert.assertTrue(maxMillis.get() < 2000); // Big enough for any latency, small enough to make sure no get token is called twice + assertTrue(maxMillis.get() > 1000); + assertTrue(maxMillis.get() < 2000); // Big enough for any latency, small enough to make sure no get token is called twice } @Test @@ -76,7 +76,7 @@ public void testLongRunningWontOverflow() throws Exception { latch.await(); // At most 10 requests should do actual token acquisition, use 11 for safe - Assert.assertTrue(refreshes.get() <= 11); + assertTrue(refreshes.get() <= 11); } private Mono remoteGetTokenAsync(long delayInMillis) { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeaderTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeaderTests.java index 2e2a62ce3589..dac3465c46e4 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeaderTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeaderTests.java @@ -3,9 +3,9 @@ package com.azure.core.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class HttpHeaderTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeadersTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeadersTests.java index 4b9b7ec77c63..1882fd6bf2d5 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeadersTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpHeadersTests.java @@ -3,10 +3,9 @@ package com.azure.core.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class HttpHeadersTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpMethodTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpMethodTests.java index 1a4d2678633f..90a0fe364cac 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpMethodTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpMethodTests.java @@ -3,9 +3,9 @@ package com.azure.core.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class HttpMethodTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpPipelineTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpPipelineTests.java index 07f2e164317e..15e905cb3114 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpPipelineTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpPipelineTests.java @@ -8,17 +8,14 @@ import com.azure.core.http.policy.RequestIdPolicy; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.http.policy.UserAgentPolicy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.MalformedURLException; import java.net.URL; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class HttpPipelineTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpRequestTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpRequestTests.java index ea3dcd688592..6025f68b662a 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpRequestTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/HttpRequestTests.java @@ -4,16 +4,14 @@ package com.azure.core.http; import io.netty.buffer.Unpooled; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.*; public class HttpRequestTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/ReactorNettyClientTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/ReactorNettyClientTests.java index d5b182d58592..6ac9fa0a7df8 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/ReactorNettyClientTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/ReactorNettyClientTests.java @@ -9,11 +9,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.util.ReferenceCountUtil; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -29,11 +30,10 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; -import static org.junit.Assert.assertEquals; - public class ReactorNettyClientTests { private static final String SHORT_BODY = "hi there"; @@ -41,8 +41,8 @@ public class ReactorNettyClientTests { private static WireMockServer server; - @BeforeClass - public static void beforeClass() { + @BeforeAll + public static void beforeAll() { server = new WireMockServer(WireMockConfiguration.options().dynamicPort().disableRequestJournal()); server.stubFor( WireMock.get("/short").willReturn(WireMock.aResponse().withBody(SHORT_BODY))); @@ -55,7 +55,7 @@ public static void beforeClass() { // ResourceLeakDetector.setLevel(Level.PARANOID); } - @AfterClass + @AfterAll public static void afterClass() { if (server != null) { server.shutdown(); @@ -90,7 +90,7 @@ public void testDispose() throws InterruptedException { response.body().subscribe().dispose(); // Wait for scheduled connection disposal action to execute on netty event-loop Thread.sleep(5000); - Assert.assertTrue(response.internConnection().isDisposed()); + assertTrue(response.internConnection().isDisposed()); } @Test @@ -106,7 +106,7 @@ public void testCancel() { .expectNextCount(1) .thenCancel() .verify(); - Assert.assertTrue(response.internConnection().isDisposed()); + assertTrue(response.internConnection().isDisposed()); } @Test @@ -119,7 +119,7 @@ public void testFlowableWhenServerReturnsBodyAndNoErrorsWhenHttp500Returned() { } @Test - @Ignore("Not working accurately at present") + @Disabled("Not working accurately at present") public void testFlowableBackpressure() { HttpResponse response = getResponse("/long"); // @@ -166,55 +166,56 @@ public void testRequestBodyEndsInErrorShouldPropagateToResponse() { .verify(); } - @Test(timeout = 5000) - public void testServerShutsDownSocketShouldPushErrorToContentFlowable() - throws IOException, InterruptedException { - CountDownLatch latch = new CountDownLatch(1); - AtomicReference sock = new AtomicReference<>(); - ServerSocket ss = new ServerSocket(0); - try { - Mono.fromCallable(() -> { - latch.countDown(); - Socket socket = ss.accept(); - sock.set(socket); - // give the client time to get request across - Thread.sleep(500); - // respond but don't send the complete response - byte[] bytes = new byte[1024]; - int n = socket.getInputStream().read(bytes); - System.out.println(new String(bytes, 0, n, StandardCharsets.UTF_8)); - String response = "HTTP/1.1 200 OK\r\n" // - + "Content-Type: text/plain\r\n" // - + "Content-Length: 10\r\n" // - + "\r\n" // - + "zi"; - OutputStream out = socket.getOutputStream(); - out.write(response.getBytes()); - out.flush(); - // kill the socket with HTTP response body incomplete - socket.close(); - return 1; - }) - .subscribeOn(Schedulers.elastic()) - .subscribe(); - // - latch.await(); - HttpClient client = HttpClient.createDefault(); - HttpRequest request = new HttpRequest(HttpMethod.GET, + @Test + public void testServerShutsDownSocketShouldPushErrorToContentFlowable() { + assertTimeout(Duration.ofMillis(5000), () -> { + CountDownLatch latch = new CountDownLatch(1); + AtomicReference sock = new AtomicReference<>(); + ServerSocket ss = new ServerSocket(0); + try { + Mono.fromCallable(() -> { + latch.countDown(); + Socket socket = ss.accept(); + sock.set(socket); + // give the client time to get request across + Thread.sleep(500); + // respond but don't send the complete response + byte[] bytes = new byte[1024]; + int n = socket.getInputStream().read(bytes); + System.out.println(new String(bytes, 0, n, StandardCharsets.UTF_8)); + String response = "HTTP/1.1 200 OK\r\n" // + + "Content-Type: text/plain\r\n" // + + "Content-Length: 10\r\n" // + + "\r\n" // + + "zi"; + OutputStream out = socket.getOutputStream(); + out.write(response.getBytes()); + out.flush(); + // kill the socket with HTTP response body incomplete + socket.close(); + return 1; + }) + .subscribeOn(Schedulers.elastic()) + .subscribe(); + // + latch.await(); + HttpClient client = HttpClient.createDefault(); + HttpRequest request = new HttpRequest(HttpMethod.GET, new URL("http://localhost:" + ss.getLocalPort() + "/get")); - HttpResponse response = client.send(request).block(); - assertEquals(200, response.statusCode()); - System.out.println("reading body"); - // - StepVerifier.create(response.bodyAsByteArray()) + HttpResponse response = client.send(request).block(); + assertEquals(200, response.statusCode()); + System.out.println("reading body"); + // + StepVerifier.create(response.bodyAsByteArray()) // .awaitDone(20, TimeUnit.SECONDS) .verifyError(IOException.class); - } finally { - ss.close(); - } + } finally { + ss.close(); + } + }); } - @Ignore("This flakey test fails often on MacOS. https://github.com/Azure/azure-sdk-for-java/issues/4357.") + @Disabled("This flakey test fails often on MacOS. https://github.com/Azure/azure-sdk-for-java/issues/4357.") @Test public void testConcurrentRequests() throws NoSuchAlgorithmException { long t = System.currentTimeMillis(); @@ -244,8 +245,7 @@ public void testConcurrentRequests() throws NoSuchAlgorithmException { }) .map(bb -> new NumberedByteBuf(n, bb)) // .doOnComplete(() -> System.out.println("completed " + n)) - .doOnComplete(() -> Assert.assertArrayEquals("wrong digest!", expectedDigest, - md.digest())); + .doOnComplete(() -> assertArrayEquals(expectedDigest, md.digest(), "wrong digest!")); })) .sequential() // enable the doOnNext call to see request numbers and thread names diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/HostPolicyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/HostPolicyTests.java index 8c209c4817c1..44dca03bd0e9 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/HostPolicyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/HostPolicyTests.java @@ -9,14 +9,14 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; import com.azure.core.http.ProxyOptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.MalformedURLException; import java.net.URL; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class HostPolicyTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProtocolPolicyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProtocolPolicyTests.java index c581c598b71a..c148877572ee 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProtocolPolicyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProtocolPolicyTests.java @@ -9,14 +9,14 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; import com.azure.core.http.ProxyOptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.MalformedURLException; import java.net.URL; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class ProtocolPolicyTests { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProxyAuthenticationPolicyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProxyAuthenticationPolicyTests.java index 2832ab41e820..634740fec1d4 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProxyAuthenticationPolicyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/ProxyAuthenticationPolicyTests.java @@ -7,14 +7,13 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpRequest; import com.azure.core.http.MockHttpClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class ProxyAuthenticationPolicyTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RequestIdPolicyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RequestIdPolicyTests.java index e044f7d1ea5b..661ef717fcd0 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RequestIdPolicyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RequestIdPolicyTests.java @@ -10,8 +10,8 @@ import com.azure.core.http.HttpResponse; import com.azure.core.http.MockHttpClient; import io.netty.buffer.ByteBuf; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -69,13 +69,13 @@ public void newRequestIdForEachCall() throws Exception { public Mono send(HttpRequest request) { if (firstRequestId != null) { String newRequestId = request.headers().value(REQUEST_ID_HEADER); - Assert.assertNotNull(newRequestId); - Assert.assertNotEquals(newRequestId, firstRequestId); + assertNotNull(newRequestId); + assertNotEquals(newRequestId, firstRequestId); } firstRequestId = request.headers().value(REQUEST_ID_HEADER); if (firstRequestId == null) { - Assert.fail(); + fail(); } return Mono.just(mockResponse); } @@ -97,12 +97,12 @@ public void sameRequestIdForRetry() throws Exception { public Mono send(HttpRequest request) { if (firstRequestId != null) { String newRequestId = request.headers().value(REQUEST_ID_HEADER); - Assert.assertNotNull(newRequestId); - Assert.assertEquals(newRequestId, firstRequestId); + assertNotNull(newRequestId); + assertEquals(newRequestId, firstRequestId); } firstRequestId = request.headers().value(REQUEST_ID_HEADER); if (firstRequestId == null) { - Assert.fail(); + fail(); } return Mono.just(mockResponse); } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RetryPolicyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RetryPolicyTests.java index 7a20532fa07c..12bca6c9ac44 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RetryPolicyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RetryPolicyTests.java @@ -9,8 +9,8 @@ import com.azure.core.http.HttpResponse; import com.azure.core.http.MockHttpClient; import com.azure.core.http.MockHttpResponse; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.net.URL; @@ -37,7 +37,7 @@ public Mono send(HttpRequest request) { HttpResponse response = pipeline.send(new HttpRequest(HttpMethod.GET, new URL("http://localhost/"))).block(); - Assert.assertEquals(501, response.statusCode()); + assertEquals(501, response.statusCode()); } @Test @@ -49,7 +49,7 @@ public void exponentialRetryMax() throws Exception { @Override public Mono send(HttpRequest request) { - Assert.assertTrue(count++ < maxRetries); + assertTrue(count++ < maxRetries); return Mono.just(new MockHttpResponse(request, 500)); } }) @@ -60,6 +60,6 @@ public Mono send(HttpRequest request) { HttpResponse response = pipeline.send(new HttpRequest(HttpMethod.GET, new URL("http://localhost/"))).block(); - Assert.assertEquals(500, response.statusCode()); + assertEquals(500, response.statusCode()); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/PagedFluxTest.java b/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/PagedFluxTest.java index ebbc020f8529..35b218b6e6bd 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/PagedFluxTest.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/http/rest/PagedFluxTest.java @@ -13,10 +13,8 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; + +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -26,14 +24,6 @@ public class PagedFluxTest { private List> pagedResponses; - @Rule - public TestName testName = new TestName(); - - @Before - public void setup() { - System.out.println("-------------- Running " + testName.getMethodName() + " -----------------------------"); - } - @Test public void testEmptyResults() throws MalformedURLException { PagedFlux pagedFlux = getIntegerPagedFlux(0); diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/Base64UrlTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/Base64UrlTests.java index 5555520b977f..1549c6756406 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/Base64UrlTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/Base64UrlTests.java @@ -3,11 +3,9 @@ package com.azure.core.implementation; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class Base64UrlTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/EncodedParameterTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/EncodedParameterTests.java index 28d5677bf57c..6f1e50eca098 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/EncodedParameterTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/EncodedParameterTests.java @@ -3,9 +3,9 @@ package com.azure.core.implementation; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class EncodedParameterTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyStressTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyStressTests.java index c5aea3ac2a0f..86e81c8846be 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyStressTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyStressTests.java @@ -31,12 +31,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.util.ResourceLeakDetector; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; import reactor.core.Disposable; import reactor.core.Exceptions; @@ -68,7 +68,7 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assumptions.*; public class RestProxyStressTests { private static IOService service; @@ -78,11 +78,11 @@ public class RestProxyStressTests { // the server is already running on that port. private static int port = 8080; - @BeforeClass - public static void beforeClass() throws IOException { - Assume.assumeTrue( - "Set the environment variable JAVA_SDK_STRESS_TESTS to \"true\" to run stress tests", - Boolean.parseBoolean(System.getenv("JAVA_SDK_STRESS_TESTS"))); + @BeforeAll + public static void beforeAll() throws IOException { + assumeTrue( + Boolean.parseBoolean(System.getenv("JAVA_SDK_STRESS_TESTS")), + "Set the environment variable JAVA_SDK_STRESS_TESTS to \"true\" to run stress tests"); ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); LoggerFactory.getLogger(RestProxyStressTests.class).info("ResourceLeakDetector level: " + ResourceLeakDetector.getLevel()); @@ -119,7 +119,7 @@ public static void beforeClass() throws IOException { private static void launchTestServer() throws IOException { String portString = System.getenv("JAVA_SDK_TEST_PORT"); // TODO: figure out why test server hangs only when spawned as a subprocess - Assume.assumeTrue("JAVA_SDK_TEST_PORT must specify the port of a running local server", portString != null); + assumeTrue(portString != null, "JAVA_SDK_TEST_PORT must specify the port of a running local server"); if (portString != null) { port = Integer.parseInt(portString, 10); LoggerFactory.getLogger(RestProxyStressTests.class).warn("Attempting to connect to already-running test server on port {}", port); @@ -135,7 +135,7 @@ private static void launchTestServer() throws IOException { } } - @AfterClass + @AfterAll public static void afterClass() throws Exception { if (testServer != null) { testServer.destroy(); @@ -265,7 +265,7 @@ private static void create100MFiles(boolean recreate) throws IOException { } @Test - @Ignore("Should only be run manually") + @Disabled("Should only be run manually") public void prepare100MFiles() throws Exception { create100MFiles(true); } @@ -297,7 +297,7 @@ public void upload100MParallelTest() { return service.upload100MB(String.valueOf(id), sas, "BlockBlob", FluxUtil.byteBufStreamFromFile(fileStream), FILE_SIZE).map(response -> { String base64MD5 = response.headers().value("Content-MD5"); byte[] receivedMD5 = Base64.getDecoder().decode(base64MD5); - Assert.assertArrayEquals(md5, receivedMD5); + assertArrayEquals(md5, receivedMD5); return response; }); }) @@ -347,7 +347,7 @@ public void uploadMemoryMappedTest() { return service.upload100MB(String.valueOf(id), sas, "BlockBlob", stream, FILE_SIZE).map(response -> { String base64MD5 = response.headers().value("Content-MD5"); byte[] receivedMD5 = Base64.getDecoder().decode(base64MD5); - Assert.assertArrayEquals(md5, receivedMD5); + assertArrayEquals(md5, receivedMD5); return response; }); }) diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyTests.java index 2afd1cdd5768..13f1e19db101 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyTests.java @@ -41,9 +41,10 @@ import com.azure.core.implementation.util.FluxUtil; import io.netty.buffer.ByteBuf; import io.netty.util.ReferenceCountUtil; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -58,14 +59,6 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public abstract class RestProxyTests { /** @@ -541,7 +534,7 @@ public void syncPutRequestWithUnexpectedResponseAndExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -556,7 +549,7 @@ public void asyncPutRequestWithUnexpectedResponseAndExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -570,7 +563,7 @@ public void syncPutRequestWithUnexpectedResponseAndDeterminedExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -585,7 +578,7 @@ public void asyncPutRequestWithUnexpectedResponseAndDeterminedExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -599,7 +592,7 @@ public void syncPutRequestWithUnexpectedResponseAndFallthroughExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -614,7 +607,7 @@ public void asyncPutRequestWithUnexpectedResponseAndFallthroughExceptionType() { fail("Expected HttpResponseException would be thrown."); } catch (MyRestException e) { assertNotNull(e.value()); - Assert.assertEquals("I'm the body!", e.value().data()); + assertEquals("I'm the body!", e.value().data()); } catch (Throwable e) { fail("Expected MyRestException would be thrown. Instead got " + e.getClass().getSimpleName()); } @@ -976,10 +969,9 @@ public void service18GetStatus300WithExpectedResponse300() { .getStatus300WithExpectedResponse300(); } - @Test(expected = HttpResponseException.class) + @Test public void service18GetStatus400() { - createService(Service18.class) - .getStatus400(); + assertThrows(HttpResponseException.class, () -> createService(Service18.class).getStatus400()); } @Test @@ -988,10 +980,9 @@ public void service18GetStatus400WithExpectedResponse400() { .getStatus400WithExpectedResponse400(); } - @Test(expected = HttpResponseException.class) + @Test public void service18GetStatus500() { - createService(Service18.class) - .getStatus500(); + assertThrows(HttpResponseException.class, () -> createService(Service18.class).getStatus500()); } @Test @@ -1338,7 +1329,6 @@ public void service20GetBytes100OnlyHeaders() { assertEquals("keep-alive", headers.connection().toLowerCase()); assertNotNull(headers.date()); // assertEquals("1.1 vegur", headers.via); - assertNotEquals(0, headers.xProcessedTime()); } @Test @@ -1358,7 +1348,6 @@ public void service20GetBytes100BodyAndHeaders() { assertEquals(true, headers.accessControlAllowCredentials()); assertNotNull(headers.date()); // assertEquals("1.1 vegur", headers.via); - assertNotEquals(0, headers.xProcessedTime()); } @Test @@ -1394,7 +1383,6 @@ public void service20PutOnlyHeaders() { assertEquals("keep-alive", headers.connection().toLowerCase()); assertNotNull(headers.date()); // assertEquals("1.1 vegur", headers.via); - assertNotEquals(0, headers.xProcessedTime()); } @Test @@ -1416,7 +1404,7 @@ public void service20PutBodyAndHeaders() { assertEquals("keep-alive", headers.connection().toLowerCase()); assertNotNull(headers.date()); // assertEquals("1.1 vegur", headers.via); - assertNotEquals(0, headers.xProcessedTime()); + // assertNotEquals(0, headers.xProcessedTime()); } @Test @@ -1608,26 +1596,31 @@ interface Service25 { Mono> getBodyResponseAsync(); } - @Test(expected = HttpResponseException.class) - @Ignore("Decoding is not a policy anymore") + @Disabled("Decoding is not a policy anymore") public void testMissingDecodingPolicyCausesException() { - Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); - service.get(); + assertThrows(HttpResponseException.class, () -> { + Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); + service.get(); + }); } - @Test(expected = HttpResponseException.class) - @Ignore("Decoding is not a policy anymore") + @Test + @Disabled("Decoding is not a policy anymore") public void testSingleMissingDecodingPolicyCausesException() { - Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); - service.getAsync().block(); - service.getBodyResponseAsync().block(); + assertThrows(HttpResponseException.class, () -> { + Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); + service.getAsync().block(); + service.getBodyResponseAsync().block(); + }); } - @Test(expected = HttpResponseException.class) - @Ignore("Decoding is not a policy anymore") + @Test + @Disabled("Decoding is not a policy anymore") public void testSingleBodyResponseMissingDecodingPolicyCausesException() { - Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); - service.getBodyResponseAsync().block(); + assertThrows(HttpResponseException.class, () -> { + Service25 service = RestProxy.create(Service25.class, HttpPipeline.builder().build()); + service.getBodyResponseAsync().block(); + }); } @Host("http://httpbin.org/") @@ -1667,10 +1660,6 @@ protected T createService(Class serviceClass, HttpClient httpClient) { return RestProxy.create(serviceClass, httpPipeline, SERIALIZER); } - private static void assertContains(String value, String expectedSubstring) { - assertTrue("Expected \"" + value + "\" to contain \"" + expectedSubstring + "\".", value.contains(expectedSubstring)); - } - private static void assertMatchWithHttpOrHttps(String url1, String url2) { final String s1 = "http://" + url1; if (s1.equalsIgnoreCase(url2)) { @@ -1680,7 +1669,7 @@ private static void assertMatchWithHttpOrHttps(String url1, String url2) { if (s2.equalsIgnoreCase(url2)) { return; } - Assert.assertTrue("'" + url2 + "' does not match with '" + s1 + "' or '" + s2 + "'.", false); + fail("'" + url2 + "' does not match with '" + s1 + "' or '" + s2 + "'."); } private static final SerializerAdapter SERIALIZER = new JacksonAdapter(); diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithHttpProxyNettyTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithHttpProxyNettyTests.java index 4cd0e9cb04a4..193a1eb60694 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithHttpProxyNettyTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithHttpProxyNettyTests.java @@ -6,11 +6,11 @@ import com.azure.core.http.HttpClient; import com.azure.core.http.ProxyOptions; import com.azure.core.http.ProxyOptions.Type; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import java.net.InetSocketAddress; -@Ignore("Should only be run manually when a local proxy server (e.g. Fiddler) is running") +@Disabled("Should only be run manually when a local proxy server (e.g. Fiddler) is running") public class RestProxyWithHttpProxyNettyTests extends RestProxyTests { @Override diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithMockTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithMockTests.java index ccbdace92608..aba5b756b90f 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithMockTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyWithMockTests.java @@ -28,7 +28,7 @@ import com.azure.core.implementation.http.ContentType; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonProperty; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -42,11 +42,7 @@ import java.util.Map; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class RestProxyWithMockTests extends RestProxyTests { @Override @@ -418,7 +414,7 @@ public void serviceHeaderCollectionPackagePrivateFields() { } private static void assertContains(String value, String expectedSubstring) { - assertTrue("Expected \"" + value + "\" to contain \"" + expectedSubstring + "\".", value.contains(expectedSubstring)); + assertTrue(value.contains(expectedSubstring), "Expected \"" + value + "\" to contain \"" + expectedSubstring + "\"."); } private abstract static class SimpleMockHttpClient implements HttpClient { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyXMLTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyXMLTests.java index 7ea7c05e50ed..ae8609eb80be 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyXMLTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/RestProxyXMLTests.java @@ -23,7 +23,7 @@ import com.azure.core.implementation.serializer.SerializerEncoding; import com.azure.core.implementation.serializer.jackson.JacksonAdapter; import com.azure.core.implementation.util.FluxUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import java.io.IOException; @@ -37,11 +37,7 @@ import java.util.List; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - +import static org.junit.jupiter.api.Assertions.*; public class RestProxyXMLTests { static class MockXMLHTTPClient implements HttpClient { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SubstitutionTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SubstitutionTests.java index 8fb692f85cea..042a3ab40afe 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SubstitutionTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SubstitutionTests.java @@ -3,9 +3,9 @@ package com.azure.core.implementation; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class SubstitutionTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerInterfaceParserTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerInterfaceParserTests.java index a37791f863f5..0559509a33b0 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerInterfaceParserTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerInterfaceParserTests.java @@ -8,13 +8,11 @@ import com.azure.core.implementation.annotation.Host; import com.azure.core.implementation.annotation.ServiceInterface; import com.azure.core.implementation.exception.MissingRequiredAnnotationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Method; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.*; public class SwaggerInterfaceParserTests { @@ -31,14 +29,14 @@ interface TestInterface2 { interface TestInterface3 { } - @Test(expected = MissingRequiredAnnotationException.class) + @Test public void hostWithNoHostAnnotation() { - new SwaggerInterfaceParser(TestInterface1.class, null); + assertThrows(MissingRequiredAnnotationException.class, () -> new SwaggerInterfaceParser(TestInterface1.class, null)); } - @Test(expected = MissingRequiredAnnotationException.class) + @Test public void hostWithNoServiceNameAnnotation() { - new SwaggerInterfaceParser(TestInterface2.class, null); + assertThrows(MissingRequiredAnnotationException.class, () -> new SwaggerInterfaceParser(TestInterface2.class, null)); } @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerMethodParserTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerMethodParserTests.java index 808b8bc3841d..b09f0718016e 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerMethodParserTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/SwaggerMethodParserTests.java @@ -12,13 +12,12 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpMethod; import com.azure.core.implementation.exception.MissingRequiredAnnotationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.lang.reflect.Method; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class SwaggerMethodParserTests { @@ -26,12 +25,14 @@ interface TestInterface1 { void testMethod1(); } - @Test(expected = MissingRequiredAnnotationException.class) + @Test public void withNoAnnotations() { - final Method testMethod1 = TestInterface1.class.getDeclaredMethods()[0]; - assertEquals("testMethod1", testMethod1.getName()); + assertThrows(MissingRequiredAnnotationException.class, () -> { + final Method testMethod1 = TestInterface1.class.getDeclaredMethods()[0]; + assertEquals("testMethod1", testMethod1.getName()); - new SwaggerMethodParser(testMethod1, "https://raw.host.com"); + new SwaggerMethodParser(testMethod1, "https://raw.host.com"); + }); } interface TestInterface2 { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/UrlEscaperTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/UrlEscaperTests.java index 11966ee14535..38a00d616f3b 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/UrlEscaperTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/UrlEscaperTests.java @@ -3,8 +3,8 @@ package com.azure.core.implementation; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class UrlEscaperTests { private static String simple = "abcABC-123"; @@ -16,55 +16,55 @@ public class UrlEscaperTests { public void canEscapePathSimple() { PercentEscaper escaper = UrlEscapers.PATH_ESCAPER; String actual = escaper.escape(simple); - Assert.assertEquals(simple, actual); + assertEquals(simple, actual); } @Test public void canEscapeQuerySimple() { PercentEscaper escaper = UrlEscapers.QUERY_ESCAPER; String actual = escaper.escape(simple); - Assert.assertEquals(simple, actual); + assertEquals(simple, actual); } @Test public void canEscapePathWithGenDelim() { PercentEscaper escaper = UrlEscapers.PATH_ESCAPER; String actual = escaper.escape(genDelim); - Assert.assertEquals("abc%5b456%2378", actual); + assertEquals("abc%5b456%2378", actual); } @Test public void canEscapeQueryWithGenDelim() { PercentEscaper escaper = UrlEscapers.QUERY_ESCAPER; String actual = escaper.escape(genDelim); - Assert.assertEquals("abc%5b456%2378", actual); + assertEquals("abc%5b456%2378", actual); } @Test public void canEscapePathWithSafeForPath() { PercentEscaper escaper = UrlEscapers.PATH_ESCAPER; String actual = escaper.escape(safeForPath); - Assert.assertEquals(safeForPath, actual); + assertEquals(safeForPath, actual); } @Test public void canEscapeQueryWithSafeForPath() { PercentEscaper escaper = UrlEscapers.QUERY_ESCAPER; String actual = escaper.escape(safeForPath); - Assert.assertEquals("abc%3a456%4078", actual); + assertEquals("abc%3a456%4078", actual); } @Test public void canEscapePathWithSafeForQuery() { PercentEscaper escaper = UrlEscapers.PATH_ESCAPER; String actual = escaper.escape(safeForQuery); - Assert.assertEquals("abc%2f456%3f78", actual); + assertEquals("abc%2f456%3f78", actual); } @Test public void canEscapeQueryWithSafeForQuery() { PercentEscaper escaper = UrlEscapers.QUERY_ESCAPER; String actual = escaper.escape(safeForQuery); - Assert.assertEquals(safeForQuery, actual); + assertEquals(safeForQuery, actual); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/ValidatorTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/ValidatorTests.java index db0fbe231f4b..58912304e546 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/ValidatorTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/ValidatorTests.java @@ -6,8 +6,8 @@ import com.azure.core.implementation.annotation.SkipParentValidation; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.node.TextNode; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.util.ArrayList; @@ -15,8 +15,6 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.fail; - public class ValidatorTests { @Test public void validateInt() { @@ -36,7 +34,7 @@ public void validateInteger() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("value is required")); + assertTrue(ex.getMessage().contains("value is required")); } } @@ -50,7 +48,7 @@ public void validateString() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("value is required")); + assertTrue(ex.getMessage().contains("value is required")); } } @@ -64,7 +62,7 @@ public void validateLocalDate() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("value is required")); + assertTrue(ex.getMessage().contains("value is required")); } } @@ -76,7 +74,7 @@ public void validateList() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("list is required")); + assertTrue(ex.getMessage().contains("list is required")); } body.list(new ArrayList<>()); Validator.validate(body); // pass @@ -91,7 +89,7 @@ public void validateList() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("list.value is required")); + assertTrue(ex.getMessage().contains("list.value is required")); } } @@ -103,7 +101,7 @@ public void validateMap() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("map is required")); + assertTrue(ex.getMessage().contains("map is required")); } body.map(new HashMap<>()); Validator.validate(body); // pass @@ -118,7 +116,7 @@ public void validateMap() { Validator.validate(body); // fail fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(ex.getMessage().contains("map.value is required")); + assertTrue(ex.getMessage().contains("map.value is required")); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlBuilderTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlBuilderTests.java index 13b950c80c2a..11b8ffbbf645 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlBuilderTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlBuilderTests.java @@ -3,15 +3,12 @@ package com.azure.core.implementation.http; -import org.hamcrest.CoreMatchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class UrlBuilderTests { @Test @@ -178,7 +175,7 @@ public void hostWhenHostContainsQuery() { final UrlBuilder builder = new UrlBuilder() .host("www.example.com?a=b"); assertEquals("www.example.com", builder.host()); - assertThat(builder.toString(), CoreMatchers.containsString("a=b")); + assertTrue(builder.toString().contains("a=b")); assertEquals("www.example.com?a=b", builder.toString()); } @@ -309,7 +306,7 @@ public void portStringquery() { final UrlBuilder builder = new UrlBuilder() .port("50?a=b&c=d"); assertEquals(50, builder.port().intValue()); - assertThat(builder.toString(), CoreMatchers.containsString("?a=b&c=d")); + assertTrue(builder.toString().contains("?a=b&c=d")); assertEquals(":50?a=b&c=d", builder.toString()); } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlTokenizerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlTokenizerTests.java index 3d5261a7d918..69984bb02222 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlTokenizerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/http/UrlTokenizerTests.java @@ -3,14 +3,12 @@ package com.azure.core.implementation.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class UrlTokenizerTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/AdditionalPropertiesSerializerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/AdditionalPropertiesSerializerTests.java index 501a438af334..9d635b1df558 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/AdditionalPropertiesSerializerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/AdditionalPropertiesSerializerTests.java @@ -6,8 +6,8 @@ import com.azure.core.implementation.serializer.SerializerEncoding; import com.azure.core.implementation.util.Foo; import com.azure.core.implementation.util.FooChild; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; @@ -31,17 +31,17 @@ public void canSerializeAdditionalProperties() throws Exception { foo.additionalProperties().put("properties.bar", "barbar"); String serialized = new JacksonAdapter().serialize(foo, SerializerEncoding.JSON); - Assert.assertEquals("{\"$type\":\"foo\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}", serialized); + assertEquals("{\"$type\":\"foo\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}", serialized); } @Test public void canDeserializeAdditionalProperties() throws Exception { String wireValue = "{\"$type\":\"foo\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}"; Foo deserialized = new JacksonAdapter().deserialize(wireValue, Foo.class, SerializerEncoding.JSON); - Assert.assertNotNull(deserialized.additionalProperties()); - Assert.assertEquals("baz", deserialized.additionalProperties().get("bar")); - Assert.assertEquals("c.d", deserialized.additionalProperties().get("a.b")); - Assert.assertEquals("barbar", deserialized.additionalProperties().get("properties.bar")); + assertNotNull(deserialized.additionalProperties()); + assertEquals("baz", deserialized.additionalProperties().get("bar")); + assertEquals("c.d", deserialized.additionalProperties().get("a.b")); + assertEquals("barbar", deserialized.additionalProperties().get("properties.bar")); } @Test @@ -62,17 +62,17 @@ public void canSerializeAdditionalPropertiesThroughInheritance() throws Exceptio foo.additionalProperties().put("properties.bar", "barbar"); String serialized = new JacksonAdapter().serialize(foo, SerializerEncoding.JSON); - Assert.assertEquals("{\"$type\":\"foochild\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}", serialized); + assertEquals("{\"$type\":\"foochild\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}", serialized); } @Test public void canDeserializeAdditionalPropertiesThroughInheritance() throws Exception { String wireValue = "{\"$type\":\"foochild\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}}},\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}"; Foo deserialized = new JacksonAdapter().deserialize(wireValue, Foo.class, SerializerEncoding.JSON); - Assert.assertNotNull(deserialized.additionalProperties()); - Assert.assertEquals("baz", deserialized.additionalProperties().get("bar")); - Assert.assertEquals("c.d", deserialized.additionalProperties().get("a.b")); - Assert.assertEquals("barbar", deserialized.additionalProperties().get("properties.bar")); - Assert.assertTrue(deserialized instanceof FooChild); + assertNotNull(deserialized.additionalProperties()); + assertEquals("baz", deserialized.additionalProperties().get("bar")); + assertEquals("c.d", deserialized.additionalProperties().get("a.b")); + assertEquals("barbar", deserialized.additionalProperties().get("properties.bar")); + assertTrue(deserialized instanceof FooChild); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DateTimeSerializerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DateTimeSerializerTests.java index 491f996b7f5c..6e27b3f35c88 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DateTimeSerializerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DateTimeSerializerTests.java @@ -3,15 +3,14 @@ package com.azure.core.implementation.serializer.jackson; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class DateTimeSerializerTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DurationSerializerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DurationSerializerTests.java index 445f91f66f9a..f678214a7d57 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DurationSerializerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/DurationSerializerTests.java @@ -3,12 +3,11 @@ package com.azure.core.implementation.serializer.jackson; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Duration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class DurationSerializerTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/FlatteningSerializerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/FlatteningSerializerTests.java index 2d9d4c196b03..b7258ce61036 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/FlatteningSerializerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/FlatteningSerializerTests.java @@ -7,8 +7,8 @@ import com.azure.core.implementation.serializer.SerializerEncoding; import com.azure.core.implementation.util.Foo; import com.fasterxml.jackson.annotation.JsonProperty; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; @@ -33,24 +33,24 @@ public void canFlatten() throws Exception { // serialization String serialized = adapter.serialize(foo, SerializerEncoding.JSON); - Assert.assertEquals("{\"$type\":\"foo\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}},\"more.props\":\"hello\"}}", serialized); + assertEquals("{\"$type\":\"foo\",\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"hello\":\"world\",\"a.b\":\"c.d\",\"bar.b\":\"uuzz\",\"bar.a\":\"ttyy\"}}},\"more.props\":\"hello\"}}", serialized); // deserialization Foo deserialized = adapter.deserialize(serialized, Foo.class, SerializerEncoding.JSON); - Assert.assertEquals("hello.world", deserialized.bar()); - Assert.assertArrayEquals(new String[]{"hello", "hello.world"}, deserialized.baz().toArray()); - Assert.assertNotNull(deserialized.qux()); - Assert.assertEquals("world", deserialized.qux().get("hello")); - Assert.assertEquals("c.d", deserialized.qux().get("a.b")); - Assert.assertEquals("ttyy", deserialized.qux().get("bar.a")); - Assert.assertEquals("uuzz", deserialized.qux().get("bar.b")); - Assert.assertEquals("hello", deserialized.moreProps()); + assertEquals("hello.world", deserialized.bar()); + assertArrayEquals(new String[]{"hello", "hello.world"}, deserialized.baz().toArray()); + assertNotNull(deserialized.qux()); + assertEquals("world", deserialized.qux().get("hello")); + assertEquals("c.d", deserialized.qux().get("a.b")); + assertEquals("ttyy", deserialized.qux().get("bar.a")); + assertEquals("uuzz", deserialized.qux().get("bar.b")); + assertEquals("hello", deserialized.moreProps()); } @Test public void canSerializeMapKeysWithDotAndSlash() throws Exception { String serialized = new JacksonAdapter().serialize(prepareSchoolModel(), SerializerEncoding.JSON); - Assert.assertEquals("{\"teacher\":{\"students\":{\"af.B/D\":{},\"af.B/C\":{}}},\"tags\":{\"foo.aa\":\"bar\",\"x.y\":\"zz\"},\"properties\":{\"name\":\"school1\"}}", serialized); + assertEquals("{\"teacher\":{\"students\":{\"af.B/D\":{},\"af.B/C\":{}}},\"tags\":{\"foo.aa\":\"bar\",\"x.y\":\"zz\"},\"properties\":{\"name\":\"school1\"}}", serialized); } @JsonFlatten diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/JacksonAdapterTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/JacksonAdapterTests.java index 9059e134cde3..95c712f890d8 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/JacksonAdapterTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/serializer/jackson/JacksonAdapterTests.java @@ -5,13 +5,13 @@ import com.azure.core.implementation.serializer.SerializerEncoding; import com.fasterxml.jackson.annotation.JsonInclude; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class JacksonAdapterTests { @Test diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/FluxUtilTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/FluxUtilTests.java index 50a427fc25b5..5d5f41a3b647 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/FluxUtilTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/FluxUtilTests.java @@ -3,9 +3,7 @@ package com.azure.core.implementation.util; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpMethod; @@ -36,9 +34,9 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.Exceptions; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -164,7 +162,7 @@ public void testAsynchronyLongInput() throws IOException, NoSuchAlgorithmExcepti } @Test - @Ignore("Need to sync with smaldini to find equivalent for rx.test.awaitDone") + @Disabled("Need to sync with smaldini to find equivalent for rx.test.awaitDone") public void testBackpressureLongInput() throws IOException, NoSuchAlgorithmException { // File file = new File("target/test4"); // byte[] array = "1234567690".getBytes(StandardCharsets.UTF_8); @@ -283,7 +281,7 @@ public void testCallWithContextGetSingle() { String response = getSingle("Hello, ") .subscriberContext(reactor.util.context.Context.of("FirstName", "Foo", "LastName", "Bar")) .block(); - Assert.assertEquals("Hello, Foo Bar", response); + assertEquals("Hello, Foo Bar", response); } @Test @@ -294,7 +292,7 @@ public void testCallWithContextGetCollection() { .subscriberContext(reactor.util.context.Context.of("FirstName", "Foo", "LastName", "Bar")) .doOnNext(line -> actualLines.add(line)) .subscribe(); - Assert.assertEquals(expectedLines, actualLines); + assertEquals(expectedLines, actualLines); } @Test @@ -332,14 +330,14 @@ private List> getPagedResponses(int noOfPages) private Mono> getFirstPage(List> pagedResponses, Context context) { // Simulates the service side code which should get the context provided by customer code - Assert.assertEquals("Val1", context.getData("Key1").get()); + assertEquals("Val1", context.getData("Key1").get()); return pagedResponses.isEmpty() ? Mono.empty() : Mono.just(pagedResponses.get(0)); } private Mono> getNextPage(String continuationToken, List> pagedResponses, Context context) { // Simulates the service side code which should get the context provided by customer code - Assert.assertEquals("Val2", context.getData("Key2").get()); + assertEquals("Val2", context.getData("Key2").get()); if (continuationToken == null || continuationToken.isEmpty()) { return Mono.empty(); } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/ImplUtilsTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/ImplUtilsTests.java index c6f1fc7ed8fe..716a7ad7bfd8 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/ImplUtilsTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/ImplUtilsTests.java @@ -3,13 +3,13 @@ package com.azure.core.implementation.util; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ImplUtilsTests { @Test public void findFirstOfTypeEmptyArgs() { - Assert.assertNull(ImplUtils.findFirstOfType(null, Integer.class)); + assertNull(ImplUtils.findFirstOfType(null, Integer.class)); } @Test @@ -17,7 +17,7 @@ public void findFirstOfTypeWithOneOfType() { int expected = 1; Object[] args = { "string", expected }; int actual = ImplUtils.findFirstOfType(args, Integer.class); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test @@ -25,12 +25,12 @@ public void findFirstOfTypeWithMultipleOfType() { int expected = 1; Object[] args = { "string", expected, 10 }; int actual = ImplUtils.findFirstOfType(args, Integer.class); - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } @Test public void findFirstOfTypeWithNoneOfType() { Object[] args = { "string", "anotherString" }; - Assert.assertNull(ImplUtils.findFirstOfType(args, Integer.class)); + assertNull(ImplUtils.findFirstOfType(args, Integer.class)); } } diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/TypeUtilTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/TypeUtilTests.java index 4044bc027680..b8e689989e88 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/TypeUtilTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/implementation/util/TypeUtilTests.java @@ -3,8 +3,8 @@ package com.azure.core.implementation.util; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.lang.reflect.Type; import java.util.List; @@ -15,11 +15,11 @@ public class TypeUtilTests { public void testGetClasses() { Puppy puppy = new Puppy(); List> classes = TypeUtil.getAllClasses(puppy.getClass()); - Assert.assertEquals(4, classes.size()); - Assert.assertTrue(classes.contains(Puppy.class)); - Assert.assertTrue(classes.contains(Dog.class)); - Assert.assertTrue(classes.contains(Pet.class)); - Assert.assertTrue(classes.contains(Object.class)); + assertEquals(4, classes.size()); + assertTrue(classes.contains(Puppy.class)); + assertTrue(classes.contains(Dog.class)); + assertTrue(classes.contains(Pet.class)); + assertTrue(classes.contains(Object.class)); } @Test @@ -28,21 +28,21 @@ public void testGetTypeArguments() { Type[] dogArgs = TypeUtil.getTypeArguments(Puppy.class.getGenericSuperclass()); Type[] petArgs = TypeUtil.getTypeArguments(Dog.class.getGenericSuperclass()); - Assert.assertEquals(0, puppyArgs.length); - Assert.assertEquals(1, dogArgs.length); - Assert.assertEquals(2, petArgs.length); + assertEquals(0, puppyArgs.length); + assertEquals(1, dogArgs.length); + assertEquals(2, petArgs.length); } @Test public void testGetTypeArgument() { Type dogArgs = TypeUtil.getTypeArgument(Puppy.class.getGenericSuperclass()); - Assert.assertEquals(Kid.class, dogArgs); + assertEquals(Kid.class, dogArgs); } @Test public void testGetRawClass() { Type petType = Puppy.class.getSuperclass().getGenericSuperclass(); - Assert.assertEquals(Pet.class, TypeUtil.getRawClass(petType)); + assertEquals(Pet.class, TypeUtil.getRawClass(petType)); } @Test @@ -51,9 +51,9 @@ public void testGetSuperType() { Type petType = TypeUtil.getSuperType(dogType); Type[] arguments = TypeUtil.getTypeArguments(petType); - Assert.assertEquals(2, arguments.length); - Assert.assertEquals(Kid.class, arguments[0]); - Assert.assertEquals(String.class, arguments[1]); + assertEquals(2, arguments.length); + assertEquals(Kid.class, arguments[0]); + assertEquals(String.class, arguments[1]); } @Test @@ -61,9 +61,9 @@ public void testGetTopSuperType() { Type petType = TypeUtil.getSuperType(Puppy.class, Pet.class); Type[] arguments = TypeUtil.getTypeArguments(petType); - Assert.assertEquals(2, arguments.length); - Assert.assertEquals(Kid.class, arguments[0]); - Assert.assertEquals(String.class, arguments[1]); + assertEquals(2, arguments.length); + assertEquals(Kid.class, arguments[0]); + assertEquals(String.class, arguments[1]); } @Test @@ -71,12 +71,12 @@ public void testIsTypeOrSubTypeOf() { Type dogType = TypeUtil.getSuperType(Puppy.class); Type petType = TypeUtil.getSuperType(dogType); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, dogType)); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, Puppy.class)); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, petType)); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(dogType, petType)); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(dogType, dogType)); - Assert.assertTrue(TypeUtil.isTypeOrSubTypeOf(petType, petType)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, dogType)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, Puppy.class)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(Puppy.class, petType)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(dogType, petType)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(dogType, dogType)); + assertTrue(TypeUtil.isTypeOrSubTypeOf(petType, petType)); } @Test @@ -85,8 +85,8 @@ public void testCreateParameterizedType() { Type petType = TypeUtil.getSuperType(dogType); Type createdType = TypeUtil.createParameterizedType(Pet.class, Kid.class, String.class); - Assert.assertEquals(TypeUtil.getRawClass(petType), TypeUtil.getRawClass(createdType)); - Assert.assertArrayEquals(TypeUtil.getTypeArguments(petType), TypeUtil.getTypeArguments(createdType)); + assertEquals(TypeUtil.getRawClass(petType), TypeUtil.getRawClass(createdType)); + assertArrayEquals(TypeUtil.getTypeArguments(petType), TypeUtil.getTypeArguments(createdType)); } private abstract static class Pet { diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/util/polling/PollerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/util/polling/PollerTests.java index c03e1b19ef51..7701d6edd9b6 100644 --- a/sdk/core/azure-core/src/test/java/com/azure/core/util/polling/PollerTests.java +++ b/sdk/core/azure-core/src/test/java/com/azure/core/util/polling/PollerTests.java @@ -6,13 +6,11 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.util.polling.PollResponse.OperationStatus; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import static org.junit.Assert.assertTrue; - import java.time.Duration; import java.time.LocalDateTime; import java.util.ArrayList; @@ -123,9 +121,9 @@ public void subscribeToSpecificOtherOperationStatusTest() throws Exception { }); Thread.sleep(totalTimeoutInMillis + 3 * pollInterval.toMillis()); - Assert.assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } /* Test where SDK Client is subscribed all responses. @@ -153,8 +151,8 @@ public void blockForCustomOperationStatusTest() throws Exception { Poller createCertPoller = new Poller<>(pollInterval, pollOperation); PollResponse pollResponse = createCertPoller.blockUntil(PollResponse.OperationStatus.fromString("OTHER_2")); - Assert.assertEquals(pollResponse.getStatus(), PollResponse.OperationStatus.fromString("OTHER_2")); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertEquals(pollResponse.getStatus(), PollResponse.OperationStatus.fromString("OTHER_2")); + assertTrue(createCertPoller.isAutoPollingEnabled()); } private Mono matchesState(PollResponse currentPollResponse, List observeAllOperationStates) { @@ -208,8 +206,8 @@ public void run() { debug("Poll and wait for it to complete "); Thread.sleep(totalTimeoutInMillis); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } /* @@ -243,10 +241,10 @@ public void disableAutoPollAndEnableAfterCompletionSuccessfullyDone() throws Exc createCertPoller.setAutoPollingEnabled(true); Thread.sleep(5 * pollInterval.toMillis()); debug(createCertPoller.getStatus().toString()); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); Thread.sleep(5 * pollInterval.toMillis()); - Assert.assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); } @@ -274,8 +272,8 @@ public void autoStartPollingAndSuccessfullyComplete() throws Exception { Thread.sleep(pollInterval.toMillis()); } - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } /* Test where SDK Client is subscribed all responses. @@ -298,9 +296,9 @@ public void subscribeToAllPollEventSuccessfullyCompleteInNSecondsTest() throws E Poller createCertPoller = new Poller<>(pollInterval, pollOperation); Thread.sleep(totalTimeoutInMillis); debug("Calling poller.block "); - Assert.assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } /* Test where SDK Client is subscribed to only final/last response. @@ -325,8 +323,8 @@ public void subscribeToOnlyFinalEventSuccessfullyCompleteInNSecondsTest() throws Poller createCertPoller = new Poller<>(pollInterval, pollOperation); assertTrue(createCertPoller.block().getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } /* Test where SDK Client is subscribed all responses. @@ -360,8 +358,8 @@ public void run() { }; t.start(); Thread.sleep(totalTimeoutInMillis); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.IN_PROGRESS); - Assert.assertFalse(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.IN_PROGRESS); + assertFalse(createCertPoller.isAutoPollingEnabled()); } @@ -390,8 +388,8 @@ public void stopAutoPollAndManualPoll() throws Exception { Thread.sleep(pollInterval.toMillis()); } - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); - Assert.assertFalse(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.getStatus() == OperationStatus.SUCCESSFULLY_COMPLETED); + assertFalse(createCertPoller.isAutoPollingEnabled()); } @@ -429,9 +427,9 @@ public void run() { }; t.start(); - Assert.assertTrue(createCertPoller.block().getStatus() == OperationStatus.USER_CANCELLED); - Assert.assertTrue(createCertPoller.getStatus() == OperationStatus.USER_CANCELLED); - Assert.assertTrue(createCertPoller.isAutoPollingEnabled()); + assertTrue(createCertPoller.block().getStatus() == OperationStatus.USER_CANCELLED); + assertTrue(createCertPoller.getStatus() == OperationStatus.USER_CANCELLED); + assertTrue(createCertPoller.isAutoPollingEnabled()); } private void debug(String... messages) {