diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index 30cd272f5fbb..a215ba5f8cc6 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -339,7 +339,6 @@ springboot3_io.projectreactor:reactor-test;3.7.9 springboot3_jakarta.servlet:jakarta.servlet-api;6.0.0 springboot3_jakarta.validation:jakarta.validation-api;3.0.2 springboot3_javax.annotation:javax.annotation-api;1.3.2 -springboot3_junit:junit;4.13.2 springboot3_net.bytebuddy:byte-buddy-agent;1.17.7 springboot3_net.bytebuddy:byte-buddy;1.17.7 springboot3_org.apache.commons:commons-lang3;3.17.0 @@ -355,7 +354,6 @@ springboot3_org.assertj:assertj-core;3.27.4 springboot3_org.hibernate.validator:hibernate-validator;8.0.3.Final springboot3_org.javatuples:javatuples;1.2 springboot3_org.junit.jupiter:junit-jupiter;5.12.2 -springboot3_org.junit.vintage:junit-vintage-engine;5.12.2 springboot3_org.messaginghub:pooled-jms;3.1.7 springboot3_org.mockito:mockito-core;5.17.0 springboot3_org.postgresql:postgresql;42.7.7 diff --git a/sdk/spring/azure-spring-data-cosmos/pom.xml b/sdk/spring/azure-spring-data-cosmos/pom.xml index b5840b325b6a..67b68bf41a42 100644 --- a/sdk/spring/azure-spring-data-cosmos/pom.xml +++ b/sdk/spring/azure-spring-data-cosmos/pom.xml @@ -154,12 +154,6 @@ 1.17.7 test - - junit - junit - 4.13.2 - test - org.springframework.boot spring-boot-starter-test @@ -202,18 +196,6 @@ slf4j-api 2.0.17 - - org.junit.vintage - junit-vintage-engine - 5.12.2 - test - - - org.hamcrest - hamcrest-core - - - diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/AbstractIntegrationTestCollectionManager.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/AbstractIntegrationTestCollectionManager.java index b856a0f85888..d5edd2a06f1a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/AbstractIntegrationTestCollectionManager.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/AbstractIntegrationTestCollectionManager.java @@ -6,9 +6,6 @@ import com.azure.spring.data.cosmos.core.CosmosTemplate; import com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +16,7 @@ import java.util.concurrent.ConcurrentMap; @SuppressWarnings({"rawtypes", "unchecked"}) -public abstract class AbstractIntegrationTestCollectionManager implements TestRule { +public abstract class AbstractIntegrationTestCollectionManager { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractIntegrationTestCollectionManager.class); private static final Duration LEASE_DURATION = Duration.ofSeconds(5 * 60); @@ -115,19 +112,6 @@ private void releaseLocks() { } } - @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - public void evaluate() throws Throwable { - try { - base.evaluate(); - } finally { - releaseLocks(); - } - } - }; - } - private static class ContainerRefs { CosmosEntityInformation cosmosEntityInformation; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/ContainerLockIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/ContainerLockIT.java index 38e28ada4d18..0874f91e7cf6 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/ContainerLockIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/ContainerLockIT.java @@ -6,21 +6,21 @@ import com.azure.spring.data.cosmos.domain.Address; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.time.Duration; import java.time.OffsetDateTime; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) @SuppressWarnings({"rawtypes", "unchecked"}) public class ContainerLockIT { @@ -36,7 +36,7 @@ public class ContainerLockIT { private ContainerLock lock; private ContainerLock otherLock; - @Before + @BeforeEach public void setup() { staticTemplate = template; CosmosEntityInformation entityInfo = new CosmosEntityInformation(Address.class); @@ -46,7 +46,7 @@ public void setup() { otherLock = new ContainerLock(reactiveTemplate, entityInfo.getContainerName(), SHORT_LEASE_DURATION); } - @After + @AfterEach public void cleanup() { releaseLockIgnoreException(lock); releaseLockIgnoreException(otherLock); @@ -81,7 +81,7 @@ public void acquireShouldThrowExceptionIfWaitForIsLessThanLeaseDuration() { try { otherLock.acquire(SHORT_LEASE_DURATION.minusSeconds(1)); - Assert.fail(); + Assertions.fail(); } catch (ContainerLock.LockAcquisitionFailedException ex) { } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/CosmosFactoryTestIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/CosmosFactoryTestIT.java index 12cb621cf85a..108d70296bd5 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/CosmosFactoryTestIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/CosmosFactoryTestIT.java @@ -5,17 +5,17 @@ import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClientBuilder; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Value; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.lang.reflect.Field; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CosmosFactoryTestIT { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/ExpressionResolverUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/ExpressionResolverUnitTest.java index 40bf96bfa513..4f4cec394d2d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/ExpressionResolverUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/ExpressionResolverUnitTest.java @@ -2,15 +2,15 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.common; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ExpressionResolverUnitTest { private static final String LITERAL_EXPRESSION = "literal expression"; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/MemoizerUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/MemoizerUnitTest.java index 88c79e428d33..178113c302b0 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/MemoizerUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/MemoizerUnitTest.java @@ -2,8 +2,8 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.common; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -11,7 +11,7 @@ import java.util.function.Function; import java.util.stream.IntStream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MemoizerUnitTest { @@ -20,7 +20,7 @@ public class MemoizerUnitTest { private static final Function MEMOIZED_FUNCTION = Memoizer.memoize(MemoizerUnitTest::incrCount); - @Before + @BeforeEach public void setUp() { COUNT_MAP.put(KEY, new AtomicInteger(0)); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PageTestUtils.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PageTestUtils.java index 36ce7dc5bff2..e51797db2ba0 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PageTestUtils.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PageTestUtils.java @@ -11,7 +11,7 @@ import org.springframework.data.domain.Pageable; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PageTestUtils { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PropertyLoaderUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PropertyLoaderUnitTest.java index ccbe5eddb73f..11e1a089307f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PropertyLoaderUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/common/PropertyLoaderUnitTest.java @@ -2,8 +2,8 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.common; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PropertyLoaderUnitTest { @@ -11,8 +11,8 @@ public class PropertyLoaderUnitTest { public void testGetProjectVersion() { final String version = PropertyLoader.getProjectVersion(); - Assert.assertNotNull(version); - Assert.assertNotEquals(version, ""); - Assert.assertNotEquals(version, "@project.version@"); + Assertions.assertNotNull(version); + Assertions.assertNotEquals(version, ""); + Assertions.assertNotEquals(version, "@project.version@"); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/config/AbstractCosmosConfigurationIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/config/AbstractCosmosConfigurationIT.java index c3371d44f68f..24f29aeffbf7 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/config/AbstractCosmosConfigurationIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/config/AbstractCosmosConfigurationIT.java @@ -11,10 +11,7 @@ import com.azure.spring.data.cosmos.common.ExpressionResolver; import com.azure.spring.data.cosmos.common.TestConstants; import com.fasterxml.jackson.databind.ObjectMapper; -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -26,13 +23,13 @@ import java.lang.reflect.Field; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AbstractCosmosConfigurationIT { - @SuppressWarnings("deprecation") - @Rule - public ExpectedException exception = ExpectedException.none(); + @Test public void containsExpressionResolver() { @@ -47,15 +44,17 @@ public void containsCosmosFactory() { final AbstractApplicationContext context = new AnnotationConfigApplicationContext( TestCosmosConfiguration.class); - Assertions.assertThat(context.getBean(CosmosFactory.class)).isNotNull(); + assertThat(context.getBean(CosmosFactory.class)).isNotNull(); } - @Test(expected = NoSuchBeanDefinitionException.class) + @Test public void defaultObjectMapperBeanNotExists() { - final AbstractApplicationContext context = new AnnotationConfigApplicationContext( - TestCosmosConfiguration.class); + assertThrows(NoSuchBeanDefinitionException.class, () -> { + final AbstractApplicationContext context = new AnnotationConfigApplicationContext( + TestCosmosConfiguration.class); - context.getBean(ObjectMapper.class); + context.getBean(ObjectMapper.class); + }); } @Test @@ -63,8 +62,8 @@ public void objectMapperIsConfigurable() { final AbstractApplicationContext context = new AnnotationConfigApplicationContext( ObjectMapperConfiguration.class); - Assertions.assertThat(context.getBean(ObjectMapper.class)).isNotNull(); - Assertions.assertThat(context.getBean(Constants.OBJECT_MAPPER_BEAN_NAME)).isNotNull(); + assertThat(context.getBean(ObjectMapper.class)).isNotNull(); + assertThat(context.getBean(Constants.OBJECT_MAPPER_BEAN_NAME)).isNotNull(); } @Test @@ -73,16 +72,16 @@ public void testCosmosClientBuilderConfigurable() throws IllegalAccessException, RequestOptionsConfiguration.class); final CosmosFactory factory = context.getBean(CosmosFactory.class); - Assertions.assertThat(factory).isNotNull(); + assertThat(factory).isNotNull(); final CosmosAsyncClient cosmosAsyncClient = factory.getCosmosAsyncClient(); - Assertions.assertThat(cosmosAsyncClient).isNotNull(); + assertThat(cosmosAsyncClient).isNotNull(); Field desiredConsistencyLevel = cosmosAsyncClient.getClass().getDeclaredField("desiredConsistencyLevel"); desiredConsistencyLevel.setAccessible(true); ConsistencyLevel consistencyLevel = (ConsistencyLevel) desiredConsistencyLevel.get(cosmosAsyncClient); - Assertions.assertThat(consistencyLevel).isEqualTo(ConsistencyLevel.CONSISTENT_PREFIX); + assertThat(consistencyLevel).isEqualTo(ConsistencyLevel.CONSISTENT_PREFIX); } @Configuration diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosFactoryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosFactoryUnitTest.java index cca2296ee87d..940c3caeec01 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosFactoryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosFactoryUnitTest.java @@ -7,16 +7,16 @@ import com.azure.spring.data.cosmos.Constants; import com.azure.spring.data.cosmos.CosmosFactory; import com.azure.spring.data.cosmos.common.PropertyLoader; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CosmosFactoryUnitTest { @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java index f0939fae596a..9daa3a398ba4 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java @@ -46,11 +46,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; @@ -62,7 +61,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.parser.Part; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; import java.lang.reflect.InvocationTargetException; @@ -102,12 +100,9 @@ import static com.azure.spring.data.cosmos.common.TestConstants.TRANSIENT_PROPERTY; import static com.azure.spring.data.cosmos.common.TestConstants.UPDATED_FIRST_NAME; import static org.assertj.core.api.Assertions.assertThat; -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.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CosmosTemplateIT { private static final Person TEST_PERSON = new Person(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, @@ -160,7 +155,7 @@ public class CosmosTemplateIT { private static final CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions(); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static CosmosAsyncClient client; @@ -192,7 +187,7 @@ public class CosmosTemplateIT { public CosmosTemplateIT() throws JsonProcessingException { } - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { if (cosmosTemplate == null) { client = CosmosFactory.createCosmosAsyncClient(cosmosClientBuilder); @@ -243,7 +238,7 @@ public void testInsertDocShouldNotPersistTransientFields() { final Person personWithTransientField = TEST_PERSON_4; assertThat(personWithTransientField.getTransientProperty()).isNotNull(); final Person insertedPerson = cosmosTemplate.insert(Person.class.getSimpleName(), personWithTransientField, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4))); - Assert.assertEquals(TRANSIENT_PROPERTY, insertedPerson.getTransientProperty()); + assertEquals(TRANSIENT_PROPERTY, insertedPerson.getTransientProperty()); final Person retrievedPerson = cosmosTemplate.findById(Person.class.getSimpleName(), insertedPerson.getId(), Person.class); assertThat(retrievedPerson.getTransientProperty()).isNull(); } @@ -258,7 +253,7 @@ public void testInsertAllAndFindAllWithTransientField() { Iterable insertAllResponse = cosmosTemplate.insertAll(personInfo, entitiesToSave); //check that the transient field is retained in the response for (Person person : insertAllResponse) { - Assert.assertEquals(TRANSIENT_PROPERTY, person.getTransientProperty()); + assertEquals(TRANSIENT_PROPERTY, person.getTransientProperty()); } Iterable findByIdsResponse = cosmosTemplate.findByIds(Arrays.asList(TEST_PERSON_4.getId()), Person.class, containerName); @@ -269,10 +264,12 @@ public void testInsertAllAndFindAllWithTransientField() { } - @Test(expected = CosmosBadRequestException.class) + @Test public void testInsertShouldFailIfColumnNotAnnotatedWithAutoGenerate() { - final Person person = new Person(null, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - cosmosTemplate.insert(Person.class.getSimpleName(), person, new PartitionKey(person.getLastName())); + assertThrows(CosmosBadRequestException.class, () -> { + final Person person = new Person(null, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); + cosmosTemplate.insert(Person.class.getSimpleName(), person, new PartitionKey(person.getLastName())); + }); } @Test @@ -481,7 +478,7 @@ public void testUpsertNewDocumentIgnoresTransientFields() { final Person person = cosmosTemplate.upsertAndReturnEntity(Person.class.getSimpleName(), newPerson); - Assert.assertEquals(TRANSIENT_PROPERTY, person.getTransientProperty()); + assertEquals(TRANSIENT_PROPERTY, person.getTransientProperty()); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIllegalTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIllegalTest.java index e18960ae2da6..bae7b195bee9 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIllegalTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIllegalTest.java @@ -8,12 +8,12 @@ import com.azure.spring.data.cosmos.core.query.CriteriaType; import com.azure.spring.data.cosmos.domain.Person; import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; import org.springframework.data.repository.query.parser.Part; import org.springframework.util.Assert; @@ -21,7 +21,7 @@ import java.lang.reflect.Method; import java.util.Arrays; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CosmosTemplateIllegalTest { private static final String NULL_STR = null; private static final String DUMMY_COLL = "dummy"; @@ -35,7 +35,7 @@ public class CosmosTemplateIllegalTest { private CosmosTemplate cosmosTemplate; private Class cosmosTemplateClass; - @Before + @BeforeEach public void setUp() { cosmosTemplateClass = cosmosTemplate.getClass(); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplatePartitionIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplatePartitionIT.java index ad9cf498a005..62beed86c8d1 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplatePartitionIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplatePartitionIT.java @@ -3,6 +3,9 @@ package com.azure.spring.data.cosmos.core; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClientBuilder; import com.azure.cosmos.models.PartitionKey; @@ -22,10 +25,9 @@ import com.azure.spring.data.cosmos.domain.PartitionPerson; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; @@ -35,7 +37,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.parser.Part; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Collections; import java.util.List; @@ -57,11 +58,11 @@ import static com.azure.spring.data.cosmos.common.TestConstants.UPDATED_FIRST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.ZIP_CODE; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.data.domain.Sort.Direction.ASC; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CosmosTemplatePartitionIT { private static final PartitionPerson TEST_PERSON = new PartitionPerson(ID_1, FIRST_NAME, ZIP_CODE, @@ -73,7 +74,7 @@ public class CosmosTemplatePartitionIT { private static final PartitionPerson TEST_PERSON_3 = new PartitionPerson(ID_3, FIRST_NAME, NEW_ZIP_CODE, HOBBIES, ADDRESSES); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static CosmosFactory cosmosFactory; @@ -90,7 +91,7 @@ public class CosmosTemplatePartitionIT { @Autowired private ResponseDiagnosticsTestUtils responseDiagnosticsTestUtils; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { if (cosmosTemplate == null) { // Query plan caching is enabled by default diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateUnitTest.java index 54f515a8a62c..c9aaaa74e4a9 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateUnitTest.java @@ -7,18 +7,22 @@ import com.azure.cosmos.CosmosClientBuilder; import com.azure.spring.data.cosmos.CosmosFactory; import com.azure.spring.data.cosmos.common.TestConstants; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) public class CosmosTemplateUnitTest { - @Test(expected = IllegalArgumentException.class) + @Test public void rejectNullDbFactory() { - CosmosAsyncClient client = CosmosFactory.createCosmosAsyncClient(new CosmosClientBuilder() - .endpoint("") - .key("")); - new CosmosFactory(client, TestConstants.DB_NAME); + assertThrows(IllegalArgumentException.class, () -> { + CosmosAsyncClient client = CosmosFactory.createCosmosAsyncClient(new CosmosClientBuilder() + .endpoint("") + .key("")); + new CosmosFactory(client, TestConstants.DB_NAME); + }); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantContainerCosmosFactoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantContainerCosmosFactoryIT.java index a301a7d65e97..f087dd4888d0 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantContainerCosmosFactoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantContainerCosmosFactoryIT.java @@ -16,17 +16,16 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.MultiTenantTestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.data.annotation.Persistent; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -40,9 +39,9 @@ import static com.azure.spring.data.cosmos.common.TestConstants.LAST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.PASSPORT_IDS_BY_COUNTRY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = MultiTenantTestRepositoryConfig.class) public class MultiTenantContainerCosmosFactoryIT { @@ -54,7 +53,7 @@ public class MultiTenantContainerCosmosFactoryIT { private final Person TEST_PERSON_1 = new Person(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); private final Person TEST_PERSON_2 = new Person(ID_2, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -69,7 +68,7 @@ public class MultiTenantContainerCosmosFactoryIT { private CosmosAsyncClient client; private CosmosEntityInformation personInfo; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { /// Setup client = CosmosFactory.createCosmosAsyncClient(cosmosClientBuilder); @@ -79,7 +78,7 @@ public void setUp() throws ClassNotFoundException { try { mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class)); } catch (Exception e) { - Assert.fail(); + Assertions.fail(); } final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext, null); @@ -109,7 +108,7 @@ public void testGetContainerFunctionality() { Iterable iterableDB2 = cosmosTemplate.findAll(personInfo.getContainerName(), Person.class); List resultDB2 = new ArrayList<>(); iterableDB2.forEach(resultDB2::add); - Assert.assertEquals(expectedResultsContainer2, resultDB2); + assertEquals(expectedResultsContainer2, resultDB2); // Check that testContainer1 has the correct contents cosmosFactory.manuallySetContainerName = testContainer1; @@ -118,7 +117,7 @@ public void testGetContainerFunctionality() { Iterable iterableDB1 = cosmosTemplate.findAll(personInfo.getContainerName(), Person.class); List resultDB1 = new ArrayList<>(); iterableDB1.forEach(resultDB1::add); - Assert.assertEquals(expectedResultsContainer1, resultDB1); + assertEquals(expectedResultsContainer1, resultDB1); //Cleanup deleteDatabaseIfExists(testDB1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantDBCosmosFactoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantDBCosmosFactoryIT.java index dc16252d651a..0de37438ecea 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantDBCosmosFactoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/MultiTenantDBCosmosFactoryIT.java @@ -16,17 +16,16 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.MultiTenantTestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.data.annotation.Persistent; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -40,9 +39,9 @@ import static com.azure.spring.data.cosmos.common.TestConstants.LAST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.PASSPORT_IDS_BY_COUNTRY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = MultiTenantTestRepositoryConfig.class) public class MultiTenantDBCosmosFactoryIT { @@ -52,7 +51,7 @@ public class MultiTenantDBCosmosFactoryIT { private final Person TEST_PERSON_1 = new Person(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); private final Person TEST_PERSON_2 = new Person(ID_2, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -67,7 +66,7 @@ public class MultiTenantDBCosmosFactoryIT { private CosmosAsyncClient client; private CosmosEntityInformation personInfo; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { /// Setup client = CosmosFactory.createCosmosAsyncClient(cosmosClientBuilder); @@ -77,7 +76,7 @@ public void setUp() throws ClassNotFoundException { try { mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class)); } catch (Exception e) { - Assert.fail(); + Assertions.fail(); } final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext, null); @@ -106,7 +105,7 @@ public void testGetDatabaseFunctionality() { Iterable iterableDB2 = cosmosTemplate.findAll(personInfo.getContainerName(), Person.class); List resultDB2 = new ArrayList<>(); iterableDB2.forEach(resultDB2::add); - Assert.assertEquals(expectedResultsDB2, resultDB2); + assertEquals(expectedResultsDB2, resultDB2); // Check that DB1 has the correct contents cosmosFactory.manuallySetDatabaseName = testDB1; @@ -115,7 +114,7 @@ public void testGetDatabaseFunctionality() { Iterable iterableDB1 = cosmosTemplate.findAll(personInfo.getContainerName(), Person.class); List resultDB1 = new ArrayList<>(); iterableDB1.forEach(resultDB1::add); - Assert.assertEquals(expectedResultsDB1, resultDB1); + assertEquals(expectedResultsDB1, resultDB1); //Cleanup deleteDatabaseIfExists(testDB1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplateIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplateIT.java index 98e4f466400c..407187e1c35e 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplateIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplateIT.java @@ -45,14 +45,12 @@ import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.assertj.core.api.Assertions; import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.domain.EntityScanner; @@ -61,7 +59,6 @@ import org.springframework.data.auditing.IsNewAwareAuditingHandler; import org.springframework.data.repository.query.parser.Part; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -95,11 +92,11 @@ import static com.azure.spring.data.cosmos.common.TestConstants.PATCH_HOBBY1; import static com.azure.spring.data.cosmos.common.TestConstants.TRANSIENT_PROPERTY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveCosmosTemplateIT { private static final Person TEST_PERSON = new Person(TestConstants.ID_1, TestConstants.FIRST_NAME, @@ -153,7 +150,7 @@ public class ReactiveCosmosTemplateIT { private static final CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions(); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Value("${cosmos.secondaryKey}") @@ -191,7 +188,7 @@ public class ReactiveCosmosTemplateIT { @Autowired private StubDateTimeProvider stubDateTimeProvider; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { if (cosmosTemplate == null) { azureKeyCredential = new AzureKeyCredential(cosmosDbKey); @@ -223,7 +220,7 @@ private ReactiveCosmosTemplate createReactiveCosmosTemplate(CosmosConfig config, return new ReactiveCosmosTemplate(cosmosFactory, config, cosmosConverter, inah); } - @After + @AfterEach public void cleanup() { // Reset master key azureKeyCredential.update(cosmosDbKey); @@ -246,7 +243,7 @@ public void testInsertDocShouldNotPersistTransientFields() { final Person personWithTransientField = TEST_PERSON_5; assertThat(personWithTransientField.getTransientProperty()).isNotNull(); final Mono insertedPerson = cosmosTemplate.insert(Person.class.getSimpleName(), personWithTransientField, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_5))); - Assert.assertEquals(TRANSIENT_PROPERTY, insertedPerson.block().getTransientProperty()); + assertEquals(TRANSIENT_PROPERTY, insertedPerson.block().getTransientProperty()); final Mono retrievedPerson = cosmosTemplate.findById(Person.class.getSimpleName(), personWithTransientField.getId(), Person.class); assertThat(retrievedPerson.block().getTransientProperty()).isNull(); } @@ -283,7 +280,7 @@ public void testFindByIdPointRead() { BASIC_ITEM.getId(), BasicItem.class); StepVerifier.create(findById) - .consumeNextWith(actual -> Assert.assertEquals(actual, BASIC_ITEM)) + .consumeNextWith(actual -> assertEquals(actual, BASIC_ITEM)) .verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); @@ -296,11 +293,11 @@ public void testFindByID() { TEST_PERSON.getId(), Person.class); StepVerifier.create(findById) - .consumeNextWith(actual -> Assert.assertEquals(actual, TEST_PERSON)) + .consumeNextWith(actual -> assertEquals(actual, TEST_PERSON)) .verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -310,13 +307,13 @@ public void testFindByIDBySecondaryKey() { TEST_PERSON.getId(), Person.class); StepVerifier.create(findById).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); - Assert.assertEquals(actual.getLastName(), TEST_PERSON.getLastName()); + assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); + assertEquals(actual.getLastName(), TEST_PERSON.getLastName()); }).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -326,20 +323,20 @@ public void testFindAll() { StepVerifier.create(flux).expectNextCount(1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test public void testFindByIdWithContainerName() { StepVerifier.create(cosmosTemplate.findById(Person.class.getSimpleName(), TEST_PERSON.getId(), Person.class)) - .consumeNextWith(actual -> Assert.assertEquals(actual, TEST_PERSON)) + .consumeNextWith(actual -> assertEquals(actual, TEST_PERSON)) .verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -349,29 +346,29 @@ public void testSaveSetsAuditData() { stubDateTimeProvider.setNow(now); StepVerifier.create(cosmosTemplate.insert(TEST_AUDITABLE_ENTITY_1)) .consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_1); + assertEquals(actual.getId(), UUID_1); }).verifyComplete(); StepVerifier.create(cosmosTemplate.insert(TEST_AUDITABLE_ENTITY_2)) .consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_2); + assertEquals(actual.getId(), UUID_2); }).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); final Flux flux = cosmosTemplate.findAll(auditableEntityInfo.getContainerName(), AuditableEntity.class); StepVerifier.create(flux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_1); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now); + assertEquals(actual.getId(), UUID_1); + assertEquals(actual.getCreatedBy(), "test-auditor"); + assertEquals(actual.getLastModifiedBy(), "test-auditor"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now); }).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_2); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now); + assertEquals(actual.getId(), UUID_2); + assertEquals(actual.getCreatedBy(), "test-auditor"); + assertEquals(actual.getLastModifiedBy(), "test-auditor"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now); }).verifyComplete(); } @@ -383,22 +380,22 @@ public void testSaveAllSetsAuditData() { StepVerifier.create(cosmosTemplate.insertAll(auditableEntityInfo, Lists.newArrayList(TEST_AUDITABLE_ENTITY_1, TEST_AUDITABLE_ENTITY_2))).expectNextCount(2).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); final Flux flux = cosmosTemplate.findAll(auditableEntityInfo.getContainerName(), AuditableEntity.class); StepVerifier.create(flux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_1); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now); + assertEquals(actual.getId(), UUID_1); + assertEquals(actual.getCreatedBy(), "test-auditor-2"); + assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now); }).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_2); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now); + assertEquals(actual.getId(), UUID_2); + assertEquals(actual.getCreatedBy(), "test-auditor-2"); + assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now); }).verifyComplete(); } @@ -410,7 +407,7 @@ public void testSaveAllFailureAuditData() { StepVerifier.create(cosmosTemplate.insertAll(auditableEntityInfo, Lists.newArrayList(TEST_AUDITABLE_ENTITY_1, TEST_AUDITABLE_ENTITY_2, TEST_AUDITABLE_ENTITY_3))).expectNextCount(3).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); final List result = cosmosTemplate.findAll(auditableEntityInfo.getContainerName(), AuditableEntity.class).collectList().block(); @@ -421,28 +418,28 @@ public void testSaveAllFailureAuditData() { stubDateTimeProvider.setNow(now2); StepVerifier.create(cosmosTemplate.insertAll(auditableEntityInfo, result)) - .consumeNextWith(actual -> Assert.assertEquals(actual.getId(), UUID_1)) - .consumeNextWith(actual -> Assert.assertEquals(actual.getId(), UUID_3)).verifyComplete(); + .consumeNextWith(actual -> assertEquals(actual.getId(), UUID_1)) + .consumeNextWith(actual -> assertEquals(actual.getId(), UUID_3)).verifyComplete(); final Flux flux = cosmosTemplate.findAll(auditableEntityInfo.getContainerName(), AuditableEntity.class); StepVerifier.create(flux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_1); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor-3"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now2); + assertEquals(actual.getId(), UUID_1); + assertEquals(actual.getCreatedBy(), "test-auditor-2"); + assertEquals(actual.getLastModifiedBy(), "test-auditor-3"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now2); }).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_2); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now); + assertEquals(actual.getId(), UUID_2); + assertEquals(actual.getCreatedBy(), "test-auditor-2"); + assertEquals(actual.getLastModifiedBy(), "test-auditor-2"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now); }).consumeNextWith(actual -> { - Assert.assertEquals(actual.getId(), UUID_3); - Assert.assertEquals(actual.getCreatedBy(), "test-auditor-2"); - Assert.assertEquals(actual.getLastModifiedBy(), "test-auditor-3"); - Assert.assertEquals(actual.getCreatedDate(), now); - Assert.assertEquals(actual.getLastModifiedByDate(), now2); + assertEquals(actual.getId(), UUID_3); + assertEquals(actual.getCreatedBy(), "test-auditor-2"); + assertEquals(actual.getLastModifiedBy(), "test-auditor-3"); + assertEquals(actual.getCreatedDate(), now); + assertEquals(actual.getLastModifiedByDate(), now2); }).verifyComplete(); } @@ -453,7 +450,7 @@ public void testInsert() { .expectNext(TEST_PERSON_3).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -465,7 +462,7 @@ public void testInsertBySecondaryKey() { .expectNext(TEST_PERSON_3).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -476,7 +473,7 @@ public void testInsertWithContainerName() { .expectNext(TEST_PERSON_2).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -509,7 +506,7 @@ public void testUpsert() { p.setHobbies(hobbies); final Mono upsert = cosmosTemplate.upsert(p); StepVerifier.create(upsert).expectNextCount(1).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -525,7 +522,7 @@ public void testUpsertNewDocumentIgnoresTransientFields() { final Mono person = cosmosTemplate.upsert(Person.class.getSimpleName(), newPerson); - Assert.assertEquals(TRANSIENT_PROPERTY, person.block().getTransientProperty()); + assertEquals(TRANSIENT_PROPERTY, person.block().getTransientProperty()); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); @@ -605,7 +602,7 @@ public void testUpsertBySecondaryKey() { StepVerifier.create(upsert).expectNextCount(1).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -619,7 +616,7 @@ public void testUpsertWithContainerName() { StepVerifier.create(upsert).expectNextCount(1).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); } @@ -629,15 +626,15 @@ public void testDeleteById() { new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4))).block(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); Flux flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class); StepVerifier.create(flux).expectNextCount(2).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); final Mono voidMono = cosmosTemplate.deleteById(Person.class.getSimpleName(), @@ -646,15 +643,15 @@ public void testDeleteById() { StepVerifier.create(voidMono).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class); StepVerifier.create(flux).expectNextCount(1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @@ -664,30 +661,30 @@ public void testDeleteByEntity() { new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4))).block(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); Flux flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class); StepVerifier.create(flux).expectNextCount(2).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); final Mono voidMono = cosmosTemplate.deleteEntity(Person.class.getSimpleName(), insertedPerson); StepVerifier.create(voidMono).verifyComplete(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class); StepVerifier.create(flux).expectNextCount(1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @@ -696,7 +693,7 @@ public void testDeleteByQuery() { cosmosTemplate.insert(TEST_PERSON_4, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON_4))).block(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); final Criteria criteria = Criteria.getInstance(CriteriaType.IS_EQUAL, "id", @@ -707,8 +704,8 @@ public void testDeleteByQuery() { StepVerifier.create(deleteFlux).expectNextCount(1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); Mono itemMono = cosmosTemplate.findById(TEST_PERSON_4.getId(), Person.class); StepVerifier.create(itemMono).expectNextCount(0).verifyComplete(); @@ -747,8 +744,8 @@ public void testFind() { StepVerifier.create(personFluxIgnoreCase).expectNextCount(1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -767,8 +764,8 @@ public void testExists() { StepVerifier.create(existsIgnoreCase).expectNext(true).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -787,8 +784,8 @@ public void testNotExists() { StepVerifier.create(existsIgnoreCase).expectNext(false).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -797,8 +794,8 @@ public void testCount() { StepVerifier.create(count).expectNext((long) 1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplatePartitionIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplatePartitionIT.java index dcc7bd8a1e46..ffbfe5068841 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplatePartitionIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplatePartitionIT.java @@ -2,6 +2,9 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.core; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClientBuilder; import com.azure.cosmos.models.PartitionKey; @@ -18,19 +21,15 @@ import com.azure.spring.data.cosmos.domain.PartitionPerson; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.data.annotation.Persistent; import org.springframework.data.repository.query.parser.Part; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -42,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveCosmosTemplatePartitionIT { private static final PartitionPerson TEST_PERSON = new PartitionPerson(TestConstants.ID_1, @@ -53,7 +52,7 @@ public class ReactiveCosmosTemplatePartitionIT { TestConstants.NEW_FIRST_NAME, TestConstants.NEW_ZIP_CODE, TestConstants.HOBBIES, TestConstants.ADDRESSES); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); private static CosmosFactory cosmosFactory; @@ -70,7 +69,7 @@ public class ReactiveCosmosTemplatePartitionIT { @Autowired private ResponseDiagnosticsTestUtils responseDiagnosticsTestUtils; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { if (cosmosTemplate == null) { // Query plan caching is enabled by default @@ -101,13 +100,13 @@ public void testFindWithPartition() { PartitionPerson.class, PartitionPerson.class.getSimpleName()); StepVerifier.create(partitionPersonFlux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); - Assert.assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); + assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); + assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); }).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } // TODO: Find a way to test the query plan cache contents without using implementation package @@ -121,8 +120,8 @@ public void testFindWithPartitionWithQueryPlanCachingEnabled() { PartitionPerson.class, PartitionPerson.class.getSimpleName()); StepVerifier.create(partitionPersonFlux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); - Assert.assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); + assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); + assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); }).verifyComplete(); // CosmosAsyncClient cosmosAsyncClient = cosmosFactory.getCosmosAsyncClient(); @@ -142,8 +141,8 @@ public void testFindWithPartitionWithQueryPlanCachingEnabled() { PartitionPerson.class, PartitionPerson.class.getSimpleName()); StepVerifier.create(partitionPersonFlux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON_2.getFirstName()); - Assert.assertEquals(actual.getZipCode(), TEST_PERSON_2.getZipCode()); + assertEquals(actual.getFirstName(), TEST_PERSON_2.getFirstName()); + assertEquals(actual.getZipCode(), TEST_PERSON_2.getZipCode()); }).verifyComplete(); // Map postQueryCallCache = asyncDocumentClient.getQueryPlanCache(); @@ -160,13 +159,13 @@ public void testFindIgnoreCaseWithPartition() { PartitionPerson.class, PartitionPerson.class.getSimpleName()); StepVerifier.create(partitionPersonFlux).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); - Assert.assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); + assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); + assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); }).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @@ -176,8 +175,8 @@ public void testFindByIdWithPartition() { PartitionPerson.class, new PartitionKey(personInfo.getPartitionKeyFieldValue(TEST_PERSON))); StepVerifier.create(partitionPersonMono).consumeNextWith(actual -> { - Assert.assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); - Assert.assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); + assertEquals(actual.getFirstName(), TEST_PERSON.getFirstName()); + assertEquals(actual.getZipCode(), TEST_PERSON.getZipCode()); }).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); @@ -220,8 +219,8 @@ public void testUpdateWithPartition() { assertEquals(person, updated); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -236,8 +235,8 @@ public void testDeleteByIdPartition() { .verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -250,8 +249,8 @@ public void testDeleteAll() { .verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -263,8 +262,8 @@ public void testCountForPartitionedCollection() { .expectNext((long) 2).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -277,8 +276,8 @@ public void testCountForPartitionedCollectionByQuery() { .expectNext((long) 1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } @Test @@ -291,8 +290,8 @@ public void testCountIgnoreCaseForPartitionedCollectionByQuery() { .expectNext((long) 1).verifyComplete(); assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); - Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull(); + assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantContainerCosmosFactoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantContainerCosmosFactoryIT.java index 88b78a9e9ade..77eef43b221b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantContainerCosmosFactoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantContainerCosmosFactoryIT.java @@ -16,17 +16,16 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.MultiTenantTestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.data.annotation.Persistent; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -42,9 +41,9 @@ import static com.azure.spring.data.cosmos.common.TestConstants.LAST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.PASSPORT_IDS_BY_COUNTRY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = MultiTenantTestRepositoryConfig.class) public class ReactiveMultiTenantContainerCosmosFactoryIT { @@ -56,7 +55,7 @@ public class ReactiveMultiTenantContainerCosmosFactoryIT { private final Person TEST_PERSON_1 = new Person(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); private final Person TEST_PERSON_2 = new Person(ID_2, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -71,7 +70,7 @@ public class ReactiveMultiTenantContainerCosmosFactoryIT { private CosmosAsyncClient client; private CosmosEntityInformation personInfo; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { /// Setup client = CosmosFactory.createCosmosAsyncClient(cosmosClientBuilder); @@ -81,7 +80,7 @@ public void setUp() throws ClassNotFoundException { try { mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class)); } catch (Exception e) { - Assert.fail(); + Assertions.fail(); } final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext, null); @@ -112,7 +111,7 @@ public void testGetContainerFunctionality() { StepVerifier.create(fluxDB2).expectNextCount(1).verifyComplete(); List resultDB2 = new ArrayList<>(); fluxDB2.toIterable().forEach(resultDB2::add); - Assert.assertEquals(expectedResultsContainer2, resultDB2); + assertEquals(expectedResultsContainer2, resultDB2); // Check that testContainer1 has the correct contents cosmosFactory.manuallySetContainerName = testContainer1; @@ -122,7 +121,7 @@ public void testGetContainerFunctionality() { StepVerifier.create(fluxDB1).expectNextCount(1).verifyComplete(); List resultDB1 = new ArrayList<>(); fluxDB1.toIterable().forEach(resultDB1::add); - Assert.assertEquals(expectedResultsContainer1, resultDB1); + assertEquals(expectedResultsContainer1, resultDB1); //Cleanup deleteDatabaseIfExists(testDB1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantDBCosmosFactoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantDBCosmosFactoryIT.java index a865e65a1a07..56bc2acd0499 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantDBCosmosFactoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/ReactiveMultiTenantDBCosmosFactoryIT.java @@ -16,17 +16,16 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.MultiTenantTestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.data.annotation.Persistent; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -42,9 +41,9 @@ import static com.azure.spring.data.cosmos.common.TestConstants.LAST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.PASSPORT_IDS_BY_COUNTRY; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = MultiTenantTestRepositoryConfig.class) public class ReactiveMultiTenantDBCosmosFactoryIT { @@ -54,7 +53,7 @@ public class ReactiveMultiTenantDBCosmosFactoryIT { private final Person TEST_PERSON_1 = new Person(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); private final Person TEST_PERSON_2 = new Person(ID_2, FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -69,7 +68,7 @@ public class ReactiveMultiTenantDBCosmosFactoryIT { private CosmosAsyncClient client; private CosmosEntityInformation personInfo; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { /// Setup client = CosmosFactory.createCosmosAsyncClient(cosmosClientBuilder); @@ -79,7 +78,7 @@ public void setUp() throws ClassNotFoundException { try { mappingContext.setInitialEntitySet(new EntityScanner(this.applicationContext).scan(Persistent.class)); } catch (Exception e) { - Assert.fail(); + Assertions.fail(); } final MappingCosmosConverter cosmosConverter = new MappingCosmosConverter(mappingContext, null); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/convert/ZonedDateTimeDeserializerTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/convert/ZonedDateTimeDeserializerTest.java index 88b593f2fe95..57059cfc962f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/convert/ZonedDateTimeDeserializerTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/convert/ZonedDateTimeDeserializerTest.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.core.convert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.time.ZoneId; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/converter/MappingCosmosConverterUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/converter/MappingCosmosConverterUnitTest.java index 0a11e4a78741..f86817f8f79a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/converter/MappingCosmosConverterUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/converter/MappingCosmosConverterUnitTest.java @@ -15,11 +15,11 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.context.ApplicationContext; import java.text.ParseException; @@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MappingCosmosConverterUnitTest { private static final SimpleDateFormat DATE = new SimpleDateFormat(TestConstants.DATE_FORMAT); private static final SimpleDateFormat TIMEZONE_DATE = new SimpleDateFormat(TestConstants.DATE_TIMEZONE_FORMAT); @@ -39,7 +39,7 @@ public class MappingCosmosConverterUnitTest { @Mock ApplicationContext applicationContext; - @Before + @BeforeEach public void setUp() { final CosmosMappingContext mappingContext = new CosmosMappingContext(); final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGeneratorTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGeneratorTest.java index 55c21c65ce11..9c6d48004646 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGeneratorTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/AbstractQueryGeneratorTest.java @@ -10,9 +10,9 @@ import com.azure.spring.data.cosmos.core.query.CriteriaType; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.parser.Part; @@ -22,13 +22,14 @@ import java.util.stream.Collectors; import static org.springframework.data.domain.Sort.Direction.ASC; +import static org.junit.jupiter.api.Assertions.*; public class AbstractQueryGeneratorTest { @Mock private EmptyQueryGenerator queryGenerator; - @Before + @BeforeEach public void setUp() { this.queryGenerator = new EmptyQueryGenerator(); } @@ -45,7 +46,7 @@ public void binaryOperatorPriorityPreserved() { final CosmosQuery query = new CosmosQuery(and); SqlQuerySpec querySpec = queryGenerator.generateCosmos(query); List parameterNames = querySpec.getParameters().stream().map(SqlParameter::getName).collect(Collectors.toList()); - Assert.assertNotNull(querySpec.getQueryText()); + Assertions.assertNotNull(querySpec.getQueryText()); MatcherAssert.assertThat(querySpec.getQueryText(), Matchers.stringContainsInOrder( parameterNames.get(0), CriteriaType.AND.getSqlKeyword(), "(", parameterNames.get(1), CriteriaType.OR.getSqlKeyword(), parameterNames.get(2), ")")); @@ -60,7 +61,7 @@ public void generateBinaryQueryWithStartsWithDoesNotUseUpper() { SqlQuerySpec result = queryGenerator.generateCosmos(query); - Assert.assertEquals(result.getQueryText(), " WHERE STARTSWITH(r.firstName, @firstName0, true) "); + assertEquals(result.getQueryText(), " WHERE STARTSWITH(r.firstName, @firstName0, true) "); } @Test @@ -72,7 +73,7 @@ public void generateBinaryQueryWithSort() { SqlQuerySpec result = queryGenerator.generateCosmos(query); - Assert.assertEquals(result.getQueryText(), " WHERE ARRAY_CONTAINS(UPPER(r.lastName), UPPER(@lastName0)) ORDER BY r.id ASC"); + assertEquals(result.getQueryText(), " WHERE ARRAY_CONTAINS(UPPER(r.lastName), UPPER(@lastName0)) ORDER BY r.id ASC"); } @Test @@ -84,7 +85,7 @@ public void generateBinaryQueryWithArrayContainsUsesUpper() { SqlQuerySpec result = queryGenerator.generateCosmos(query); - Assert.assertEquals(result.getQueryText(), " WHERE ARRAY_CONTAINS(UPPER(r.lastName), UPPER(@lastName0)) "); + assertEquals(result.getQueryText(), " WHERE ARRAY_CONTAINS(UPPER(r.lastName), UPPER(@lastName0)) "); } @Test @@ -98,9 +99,9 @@ public void generateBinaryQueryWithStringEquals() { SqlQuerySpec result = queryGenerator.generateCosmos(query); if (ignoreCaseType == Part.IgnoreCaseType.NEVER) { - Assert.assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0) "); + assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0) "); } else { - Assert.assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0, true) "); + assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0, true) "); } } } @@ -114,7 +115,7 @@ public void generateBinaryQueryWithIsEqualIntUsesUpper() { SqlQuerySpec result = queryGenerator.generateCosmos(query); - Assert.assertEquals(result.getQueryText(), " WHERE UPPER(r.zipcode) = UPPER(@zipcode0) "); + assertEquals(result.getQueryText(), " WHERE UPPER(r.zipcode) = UPPER(@zipcode0) "); } @Test @@ -126,7 +127,7 @@ public void generateBinaryQueryWithIsEqualStringDoesNotUseUpper() { SqlQuerySpec result = queryGenerator.generateCosmos(query); - Assert.assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0, true) "); + assertEquals(result.getQueryText(), " WHERE STRINGEQUALS(r.firstName, @firstName0, true) "); } private static class EmptyQueryGenerator extends AbstractQueryGenerator implements QuerySpecGenerator { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/NativeQueryGeneratorTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/NativeQueryGeneratorTest.java index a21f4aeb60fc..e6c165623020 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/NativeQueryGeneratorTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/generator/NativeQueryGeneratorTest.java @@ -6,9 +6,8 @@ import com.azure.cosmos.models.SqlParameter; import com.azure.cosmos.models.SqlQuerySpec; import com.azure.spring.data.cosmos.core.query.CosmosQuery; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.springframework.data.domain.Sort; @@ -16,13 +15,14 @@ import java.util.List; import static org.springframework.data.domain.Sort.Direction.ASC; +import static org.junit.jupiter.api.Assertions.*; public class NativeQueryGeneratorTest { @Mock private EmptyQueryGenerator queryGenerator; - @Before + @BeforeEach public void setUp() { this.queryGenerator = new EmptyQueryGenerator(); } @@ -35,7 +35,7 @@ public void generateSortedQueryTest() { SqlQuerySpec querySpec = new SqlQuerySpec("select * from a where a.firstName = @firstName", sqlParameters); final SqlQuerySpec sortedQuerySpec = NativeQueryGenerator.getInstance().generateSortedQuery(querySpec, Sort.by(ASC, "id")); - Assert.assertEquals(sortedQuerySpec.getQueryText(), "select * from a where a.firstName = @firstName ORDER BY a.id ASC"); + assertEquals(sortedQuerySpec.getQueryText(), "select * from a where a.firstName = @firstName ORDER BY a.id ASC"); } private static class EmptyQueryGenerator extends NativeQueryGenerator implements QuerySpecGenerator { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/BasicCosmosPersistentEntityUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/BasicCosmosPersistentEntityUnitTest.java index 59d3e5c6a7f6..345457579818 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/BasicCosmosPersistentEntityUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/BasicCosmosPersistentEntityUnitTest.java @@ -4,7 +4,7 @@ package com.azure.spring.data.cosmos.core.mapping; import com.azure.spring.data.cosmos.domain.Person; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.util.ClassTypeInformation; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/CosmosMappingContextUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/CosmosMappingContextUnitTest.java index 2ed4fbbdc906..506f5034267f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/CosmosMappingContextUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/CosmosMappingContextUnitTest.java @@ -3,7 +3,7 @@ package com.azure.spring.data.cosmos.core.mapping; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.springframework.context.ApplicationContext; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorIT.java index ff4f63e10c08..200d92e55202 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorIT.java @@ -10,21 +10,21 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.AddressRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS1_PARTITION1; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestRepositoryConfig.class, ErrorEventListenerConfig.class}) public class ApplicationContextEventErrorIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -32,14 +32,16 @@ public class ApplicationContextEventErrorIT { @Autowired private CosmosTemplate template; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1)); } - @Test(expected = CosmosAccessException.class) + @Test public void shouldThrowExceptionIfEventListenerThrowsException() { - repository.findById(TEST_ADDRESS1_PARTITION1.getPostalCode(), new PartitionKey(TEST_ADDRESS1_PARTITION1.getCity())); + assertThrows(CosmosAccessException.class, () -> + repository.findById(TEST_ADDRESS1_PARTITION1.getPostalCode(), + new PartitionKey(TEST_ADDRESS1_PARTITION1.getCity()))); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorReactiveIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorReactiveIT.java index 6f833a984b6f..5db9dea65ea7 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorReactiveIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventErrorReactiveIT.java @@ -10,21 +10,20 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveAddressRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS1_PARTITION1; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestRepositoryConfig.class, ErrorEventListenerConfig.class}) public class ApplicationContextEventErrorReactiveIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -32,14 +31,12 @@ public class ApplicationContextEventErrorReactiveIT { @Autowired private CosmosTemplate template; - @Before - public void setUp() { - collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); - repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1)).collectList().block(); - } - - @Test(expected = CosmosAccessException.class) + @Test public void shouldThrowExceptionIfEventListenerThrowsException() { - repository.findById(TEST_ADDRESS1_PARTITION1.getPostalCode(), new PartitionKey(TEST_ADDRESS1_PARTITION1.getCity())).block(); + assertThrows(CosmosAccessException.class, () -> { + collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); + repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1)).collectList().block(); + repository.findById(TEST_ADDRESS1_PARTITION1.getPostalCode(), new PartitionKey(TEST_ADDRESS1_PARTITION1.getCity())).block(); + }); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventIT.java index 91654aee2bb6..f63cd324cd57 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventIT.java @@ -11,15 +11,12 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.AddressRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -30,11 +27,11 @@ import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS4_PARTITION3; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ApplicationContextEventIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -44,11 +41,9 @@ public class ApplicationContextEventIT { @Autowired private SimpleCosmosMappingEventListener simpleCosmosMappingEventListener; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Before + + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1, TEST_ADDRESS1_PARTITION2, diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventReactiveIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventReactiveIT.java index 9ce320cb6a46..4ce9f3e4a148 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventReactiveIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/ApplicationContextEventReactiveIT.java @@ -10,15 +10,12 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveAddressRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -29,11 +26,11 @@ import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS4_PARTITION3; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ApplicationContextEventReactiveIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -43,11 +40,9 @@ public class ApplicationContextEventReactiveIT { @Autowired private SimpleCosmosMappingEventListener simpleCosmosMappingEventListener; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Before + + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1, TEST_ADDRESS1_PARTITION2, diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/CosmosEventListenerUnitTests.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/CosmosEventListenerUnitTests.java index e604fdddd8a9..50339dc8194b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/CosmosEventListenerUnitTests.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/mapping/event/CosmosEventListenerUnitTests.java @@ -7,7 +7,7 @@ import com.azure.spring.data.cosmos.domain.Student; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.NullNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CosmosQueryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CosmosQueryUnitTest.java index 39e0e584129a..6a163bc57a7d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CosmosQueryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CosmosQueryUnitTest.java @@ -2,8 +2,7 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.core.query; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.parser.Part; @@ -12,6 +11,7 @@ import static com.azure.spring.data.cosmos.common.TestConstants.CRITERIA_KEY; import static com.azure.spring.data.cosmos.common.TestConstants.CRITERIA_OBJECT; +import static org.junit.jupiter.api.Assertions.*; public class CosmosQueryUnitTest { @@ -22,9 +22,9 @@ public void testDocumentQueryCreate() { final CosmosQuery query = new CosmosQuery(criteria); - Assert.assertEquals(criteria, query.getCriteria()); - Assert.assertEquals(Sort.unsorted(), query.getSort()); - Assert.assertEquals(Pageable.unpaged(), query.getPageable()); - Assert.assertEquals(Part.IgnoreCaseType.NEVER, criteria.getIgnoreCase()); + assertEquals(criteria, query.getCriteria()); + assertEquals(Sort.unsorted(), query.getSort()); + assertEquals(Pageable.unpaged(), query.getPageable()); + assertEquals(Part.IgnoreCaseType.NEVER, criteria.getIgnoreCase()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CriteriaUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CriteriaUnitTest.java index 3ac5bdd4e561..70eac9006d0b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CriteriaUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/core/query/CriteriaUnitTest.java @@ -4,8 +4,8 @@ import com.azure.spring.data.cosmos.core.generator.FindQuerySpecGenerator; import com.azure.spring.data.cosmos.exception.IllegalQueryException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.data.repository.query.parser.Part; import java.util.Arrays; @@ -14,6 +14,7 @@ import static com.azure.spring.data.cosmos.common.TestConstants.CRITERIA_KEY; import static com.azure.spring.data.cosmos.common.TestConstants.CRITERIA_OBJECT; +import static org.junit.jupiter.api.Assertions.*; public class CriteriaUnitTest { @@ -23,12 +24,12 @@ public void testUnaryCriteria() { final Criteria criteria = Criteria.getInstance(CriteriaType.IS_EQUAL, CRITERIA_KEY, values, Part.IgnoreCaseType.NEVER); - Assert.assertTrue(criteria.getSubCriteria().isEmpty()); - Assert.assertEquals(values, criteria.getSubjectValues()); - Assert.assertEquals(CriteriaType.IS_EQUAL, criteria.getType()); - Assert.assertEquals(CRITERIA_KEY, criteria.getSubject()); - Assert.assertTrue(CriteriaType.isBinary(criteria.getType())); - Assert.assertEquals(Part.IgnoreCaseType.NEVER, criteria.getIgnoreCase()); + Assertions.assertTrue(criteria.getSubCriteria().isEmpty()); + assertEquals(values, criteria.getSubjectValues()); + assertEquals(CriteriaType.IS_EQUAL, criteria.getType()); + assertEquals(CRITERIA_KEY, criteria.getSubject()); + Assertions.assertTrue(CriteriaType.isBinary(criteria.getType())); + assertEquals(Part.IgnoreCaseType.NEVER, criteria.getIgnoreCase()); } @Test @@ -40,37 +41,41 @@ public void testBinaryCriteria() { CRITERIA_OBJECT, values, Part.IgnoreCaseType.NEVER); final Criteria criteria = Criteria.getInstance(CriteriaType.AND, leftCriteria, rightCriteria); - Assert.assertNotNull(criteria.getSubCriteria()); - Assert.assertNull(criteria.getSubjectValues()); - Assert.assertNull(criteria.getSubject()); - Assert.assertEquals(criteria.getType(), CriteriaType.AND); - Assert.assertTrue(CriteriaType.isClosed(criteria.getType())); + Assertions.assertNotNull(criteria.getSubCriteria()); + Assertions.assertNull(criteria.getSubjectValues()); + Assertions.assertNull(criteria.getSubject()); + assertEquals(criteria.getType(), CriteriaType.AND); + Assertions.assertTrue(CriteriaType.isClosed(criteria.getType())); - Assert.assertEquals(2, criteria.getSubCriteria().size()); - Assert.assertEquals(leftCriteria, criteria.getSubCriteria().get(0)); - Assert.assertEquals(rightCriteria, criteria.getSubCriteria().get(1)); + assertEquals(2, criteria.getSubCriteria().size()); + assertEquals(leftCriteria, criteria.getSubCriteria().get(0)); + assertEquals(rightCriteria, criteria.getSubCriteria().get(1)); - Assert.assertEquals(Part.IgnoreCaseType.NEVER, criteria.getSubCriteria().get(0).getIgnoreCase()); - Assert.assertEquals(Part.IgnoreCaseType.NEVER, criteria.getSubCriteria().get(1).getIgnoreCase()); + assertEquals(Part.IgnoreCaseType.NEVER, criteria.getSubCriteria().get(0).getIgnoreCase()); + assertEquals(Part.IgnoreCaseType.NEVER, criteria.getSubCriteria().get(1).getIgnoreCase()); } - @Test(expected = IllegalQueryException.class) + @Test public void testInvalidInKeywordParameter() { - final List values = Collections.singletonList(CRITERIA_OBJECT); - final Criteria criteria = Criteria.getInstance(CriteriaType.IN, - CRITERIA_KEY, values, Part.IgnoreCaseType.NEVER); - final CosmosQuery query = new CosmosQuery(criteria); + assertThrows(IllegalQueryException.class, () -> { + final List values = Collections.singletonList(CRITERIA_OBJECT); + final Criteria criteria = Criteria.getInstance(CriteriaType.IN, + CRITERIA_KEY, values, Part.IgnoreCaseType.NEVER); + final CosmosQuery query = new CosmosQuery(criteria); - new FindQuerySpecGenerator().generateCosmos(query); + new FindQuerySpecGenerator().generateCosmos(query); + }); } - @Test(expected = IllegalQueryException.class) + @Test public void testInvalidInKeywordType() { - final List values = Collections.singletonList(new IllegalQueryException("")); - final Criteria criteria = Criteria.getInstance(CriteriaType.IN, - CRITERIA_KEY, values, Part.IgnoreCaseType.NEVER); - final CosmosQuery query = new CosmosQuery(criteria); + assertThrows(IllegalQueryException.class, () -> { + final List values = Collections.singletonList(new IllegalQueryException("")); + final Criteria criteria = Criteria.getInstance(CriteriaType.IN, + CRITERIA_KEY, values, Part.IgnoreCaseType.NEVER); + final CosmosQuery query = new CosmosQuery(criteria); - new FindQuerySpecGenerator().generateCosmos(query); + new FindQuerySpecGenerator().generateCosmos(query); + }); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/exception/CosmosExceptionUtilsTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/exception/CosmosExceptionUtilsTest.java index 334e3a2a7b54..f1c892d00ef5 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/exception/CosmosExceptionUtilsTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/exception/CosmosExceptionUtilsTest.java @@ -5,11 +5,11 @@ import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.CosmosException; import com.azure.spring.data.cosmos.core.ResponseDiagnosticsProcessor; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.http.HttpStatus; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; public class CosmosExceptionUtilsTest { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/CosmosAnnotationUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/CosmosAnnotationUnitTest.java index 73f2c734de4c..4a40d9a968a7 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/CosmosAnnotationUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/CosmosAnnotationUnitTest.java @@ -11,8 +11,8 @@ import com.azure.spring.data.cosmos.domain.Role; import com.azure.spring.data.cosmos.domain.TimeToLiveSample; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.util.Assert; @@ -20,7 +20,7 @@ public class CosmosAnnotationUnitTest { private CosmosEntityInformation personInfo; private CosmosEntityInformation roleInfo; - @Before + @BeforeEach public void setUp() { personInfo = new CosmosEntityInformation<>(NoDBAnnotationPerson.class); roleInfo = new CosmosEntityInformation<>(Role.class); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/EntityImplRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/EntityImplRepositoryIT.java index c97650b779cd..810c102903cf 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/EntityImplRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/EntityImplRepositoryIT.java @@ -12,23 +12,22 @@ import com.azure.spring.data.cosmos.repository.repository.EntityImplRepository; import com.azure.spring.data.cosmos.repository.repository.ParentEntityRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Iterator; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class EntityImplRepositoryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -52,7 +51,7 @@ public class EntityImplRepositoryIT { private final ParentEntity PARENTENTITY_1 = new ParentEntity(); private final ParentEntity PARENTENTITY_2 = new ParentEntity(); - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); ENTITYIMPL_1.setId("entityImpl1"); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/MultiCosmosTemplateIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/MultiCosmosTemplateIT.java index 87703fac276a..d32512bbe743 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/MultiCosmosTemplateIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/MultiCosmosTemplateIT.java @@ -10,22 +10,21 @@ import com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate; import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.assertj.core.api.Assertions; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Mono; import java.lang.reflect.Field; import static com.azure.spring.data.cosmos.common.TestConstants.AGE; import static com.azure.spring.data.cosmos.common.TestConstants.PASSPORT_IDS_BY_COUNTRY; +import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestRepositoryConfig.class, SecondaryTestRepositoryConfig.class}) public class MultiCosmosTemplateIT { private static final Person PRIMARY_TEST_PERSON = new Person(TestConstants.ID_1, TestConstants.FIRST_NAME, @@ -33,7 +32,7 @@ public class MultiCosmosTemplateIT { private static final Person SECONDARY_TEST_PERSON = new Person(TestConstants.ID_2, TestConstants.NEW_FIRST_NAME, TestConstants.NEW_LAST_NAME, TestConstants.HOBBIES, TestConstants.ADDRESSES, AGE, PASSPORT_IDS_BY_COUNTRY); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager primaryCollectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -53,7 +52,7 @@ public void testPrimaryTemplate() { primaryReactiveCosmosTemplate.insert(PRIMARY_TEST_PERSON, new PartitionKey(personInfo.getPartitionKeyFieldValue(PRIMARY_TEST_PERSON))).block(); final Mono findById = primaryReactiveCosmosTemplate.findById(PRIMARY_TEST_PERSON.getId(), Person.class); - Assertions.assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.FIRST_NAME); + assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.FIRST_NAME); } @Test @@ -62,7 +61,7 @@ public void testSecondaryTemplate() { secondaryReactiveCosmosTemplate.insert(SECONDARY_TEST_PERSON, new PartitionKey(personInfo.getPartitionKeyFieldValue(SECONDARY_TEST_PERSON))).block(); final Mono findById = secondaryReactiveCosmosTemplate.findById(SECONDARY_TEST_PERSON.getId(), Person.class); - Assertions.assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.NEW_FIRST_NAME); + assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.NEW_FIRST_NAME); secondaryReactiveCosmosTemplate.deleteAll(Person.class.getSimpleName(), Person.class).block(); secondaryReactiveCosmosTemplate.deleteContainer(personInfo.getContainerName()); } @@ -73,7 +72,7 @@ public void testSecondaryTemplateWithDiffDatabase() { secondaryDiffDatabaseReactiveCosmosTemplate.insert(SECONDARY_TEST_PERSON, new PartitionKey(personInfo.getPartitionKeyFieldValue(SECONDARY_TEST_PERSON))).block(); final Mono findById = secondaryDiffDatabaseReactiveCosmosTemplate.findById(SECONDARY_TEST_PERSON.getId(), Person.class); - Assertions.assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.NEW_FIRST_NAME); + assertThat(findById.block().getFirstName()).isEqualTo(TestConstants.NEW_FIRST_NAME); secondaryDiffDatabaseReactiveCosmosTemplate.deleteAll(Person.class.getSimpleName(), Person.class).block(); secondaryDiffDatabaseReactiveCosmosTemplate.deleteContainer(personInfo.getContainerName()); } @@ -86,6 +85,6 @@ public void testSingleCosmosClientForMultipleCosmosTemplate() throws IllegalAcce CosmosAsyncClient client1 = cosmosFactory1.getCosmosAsyncClient(); CosmosFactory cosmosFactory2 = (CosmosFactory) cosmosFactory.get(secondaryDiffDatabaseReactiveCosmosTemplate); CosmosAsyncClient client2 = cosmosFactory2.getCosmosAsyncClient(); - Assertions.assertThat(client1).isEqualTo(client2); + assertThat(client1).isEqualTo(client2); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/ReactiveUUIDIdDomainRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/ReactiveUUIDIdDomainRepositoryIT.java index c6dbb5ca5fbb..ce726a3a3c93 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/ReactiveUUIDIdDomainRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/ReactiveUUIDIdDomainRepositoryIT.java @@ -9,13 +9,12 @@ import com.azure.spring.data.cosmos.exception.CosmosNotFoundException; import com.azure.spring.data.cosmos.repository.repository.ReactiveUUIDIdDomainRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -24,7 +23,9 @@ import java.util.Objects; import java.util.UUID; -@RunWith(SpringJUnit4ClassRunner.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveUUIDIdDomainRepositoryIT { @@ -37,7 +38,7 @@ public class ReactiveUUIDIdDomainRepositoryIT { private static final UUIDIdDomain DOMAIN_1 = new UUIDIdDomain(ID_1, NAME_1); private static final UUIDIdDomain DOMAIN_2 = new UUIDIdDomain(ID_2, NAME_2); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -48,7 +49,7 @@ public class ReactiveUUIDIdDomainRepositoryIT { private CosmosEntityInformation entityInformation; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, UUIDIdDomain.class); entityInformation = collectionManager.getEntityInformation(UUIDIdDomain.class); @@ -77,9 +78,10 @@ public void testUUIDIdDomain() { StepVerifier.create(afterDelIdMono).expectNextCount(0).verifyComplete(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidDomain() { - new CosmosEntityInformation(InvalidDomain.class); + assertThrows(IllegalArgumentException.class, () -> + new CosmosEntityInformation(InvalidDomain.class)); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryIllegalTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryIllegalTest.java index 053ebd265c0c..b3819234d44a 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryIllegalTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryIllegalTest.java @@ -8,13 +8,15 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) public class SimpleCosmosRepositoryIllegalTest { private SimpleCosmosRepository repository; @@ -23,49 +25,49 @@ public class SimpleCosmosRepositoryIllegalTest { @Mock CosmosEntityInformation entityInformation; - @Before + @BeforeEach public void setUp() { CosmosContainerProperties containerProperties = new CosmosContainerProperties("", new PartitionKeyDefinition()); repository = new SimpleCosmosRepository<>(entityInformation, dbOperations); } - @Test(expected = IllegalArgumentException.class) + @Test public void deleteNullShouldFail() { - repository.delete(null); + assertThrows(IllegalArgumentException.class, () -> repository.delete(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void deleteIterableNullShouldFail() { - repository.deleteAll(null); + assertThrows(IllegalArgumentException.class, () -> repository.deleteAll(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void deleteNullIdShouldFail() { - repository.deleteById(null); + assertThrows(IllegalArgumentException.class, () -> repository.deleteById(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void existsNullIdShouldFail() { - repository.existsById(null); + assertThrows(IllegalArgumentException.class, () -> repository.existsById(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void findNullIterableIdsShouldFail() { - repository.findAllById(null); + assertThrows(IllegalArgumentException.class, () -> repository.findAllById(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void findByNullIdShouldFail() { - repository.findById(null); + assertThrows(IllegalArgumentException.class, () -> repository.findById(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void saveNullShouldFail() { - repository.save(null); + assertThrows(IllegalArgumentException.class, () -> repository.save(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void saveNullIterableShouldFail() { - repository.saveAll(null); + assertThrows(IllegalArgumentException.class, () -> repository.saveAll(null)); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryUnitTest.java index 74270cf1c380..7315ebc9955d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/SimpleCosmosRepositoryUnitTest.java @@ -10,23 +10,23 @@ import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SimpleCosmosRepositoryUnitTest { private static final Person TEST_PERSON = new Person(TestConstants.ID_1, TestConstants.FIRST_NAME, TestConstants.LAST_NAME, @@ -41,15 +41,13 @@ public class SimpleCosmosRepositoryUnitTest { @Mock CosmosEntityInformation entityInformation; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); + - @Before + @BeforeEach public void setUp() { when(entityInformation.getJavaType()).thenReturn(Person.class); when(entityInformation.getContainerName()).thenReturn(Person.class.getSimpleName()); - when(cosmosOperations.findAll(anyString(), any())).thenReturn(Arrays.asList(TEST_PERSON)); + lenient().when(cosmosOperations.findAll(anyString(), any())).thenReturn(Arrays.asList(TEST_PERSON)); repository = new SimpleCosmosRepository<>(entityInformation, cosmosOperations); } @@ -75,15 +73,15 @@ public void testFindOne() { @Test public void testFindOneExceptionForPartitioned() { - expectedException.expect(UnsupportedOperationException.class); - expectedException.expectMessage(PARTITION_VALUE_REQUIRED_MSG); - repository.save(TEST_PERSON); when(cosmosOperations.findById(anyString(), anyString(), any())) .thenThrow(new UnsupportedOperationException(PARTITION_VALUE_REQUIRED_MSG)); - final Person result = repository.findById(TEST_PERSON.getId()).get(); + UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> { + repository.findById(TEST_PERSON.getId()).get(); + }); + assertEquals(PARTITION_VALUE_REQUIRED_MSG, exception.getMessage()); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java index 73945c6eeee2..ee084a625675 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java @@ -4,7 +4,7 @@ package com.azure.spring.data.cosmos.repository.config; import com.azure.spring.data.cosmos.repository.CosmosRepository; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java index 57e518e03ef6..562bcb39a5c3 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java @@ -4,7 +4,7 @@ package com.azure.spring.data.cosmos.repository.config; import com.azure.spring.data.cosmos.repository.ReactiveCosmosRepository; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryIT.java index 7f6b0f0de5ec..e76518ac9384 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryIT.java @@ -2,6 +2,9 @@ // Licensed under the MIT License. package com.azure.spring.data.cosmos.repository.integration; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + import com.azure.cosmos.models.CosmosPatchItemRequestOptions; import com.azure.cosmos.models.CosmosPatchOperations; import com.azure.cosmos.models.PartitionKey; @@ -16,16 +19,13 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.AddressRepository; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; + + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.Comparator; @@ -40,12 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class AddressRepositoryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -60,9 +61,6 @@ public class AddressRepositoryIT { @Autowired private ResponseDiagnosticsTestUtils responseDiagnosticsTestUtils; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); CosmosPatchOperations patchSetOperation = CosmosPatchOperations .create() @@ -79,7 +77,7 @@ public class AddressRepositoryIT { private static final CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions(); - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1, TEST_ADDRESS1_PARTITION2, @@ -167,8 +165,8 @@ public void testFindByStreetOrCity() { result.sort(Comparator.comparing(Address::getPostalCode)); reference.sort(Comparator.comparing(Address::getPostalCode)); - Assert.assertEquals(reference.size(), result.size()); - Assert.assertEquals(reference, result); + assertEquals(reference.size(), result.size()); + assertEquals(reference, result); } @Test @@ -183,9 +181,8 @@ public void testCount() { @Test public void deleteWithoutPartitionedColumnShouldFail() { - expectedException.expect(Exception.class); - - repository.deleteById(TEST_ADDRESS1_PARTITION1.getPostalCode()); + assertThrows(Exception.class, () -> + repository.deleteById(TEST_ADDRESS1_PARTITION1.getPostalCode())); } @Test @@ -302,7 +299,7 @@ public void testPatchPreConditionFail() { options.setFilterPredicate("FROM address a WHERE a.city = 'dummy'"); Address patchedAddress = repository.save(TestConstants.POSTAL_CODE, new PartitionKey(CITY), Address.class, patchSetOperation, options); assertThat(patchedAddress.getStreet()).isEqualTo(TestConstants.NEW_STREET); - Assert.fail(); + Assertions.fail(); } catch (CosmosAccessException ex) { assertThat(ex.getCosmosException().getStatusCode()).isEqualTo(TestConstants.PRECONDITION_FAILED_STATUS_CODE); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryNoMetricsIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryNoMetricsIT.java index acc313a92d9c..a86dd3896023 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryNoMetricsIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AddressRepositoryNoMetricsIT.java @@ -11,13 +11,12 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryNoMetricsConfig; import com.azure.spring.data.cosmos.repository.repository.AddressRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.List; @@ -27,11 +26,11 @@ import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS4_PARTITION3; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryNoMetricsConfig.class) public class AddressRepositoryNoMetricsIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -47,7 +46,7 @@ public class AddressRepositoryNoMetricsIT { private ResponseDiagnosticsTestUtils responseDiagnosticsTestUtils; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(TEST_ADDRESS1_PARTITION1, TEST_ADDRESS1_PARTITION2, diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java index 671058c9a776..9919bd9cb865 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AnnotatedQueryIT.java @@ -12,17 +12,16 @@ import com.azure.spring.data.cosmos.repository.repository.AddressRepository; import com.azure.spring.data.cosmos.repository.repository.AuditableRepository; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.time.LocalDate; import java.util.ArrayList; @@ -38,11 +37,11 @@ import static com.azure.spring.data.cosmos.common.TestConstants.PAGE_SIZE_2; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class AnnotatedQueryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -54,7 +53,7 @@ public class AnnotatedQueryIT { @Autowired private AddressRepository addressRepository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class, AuditableEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AuditableIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AuditableIT.java index d09a15bb22e5..8a539413d389 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AuditableIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/AuditableIT.java @@ -18,14 +18,13 @@ import com.azure.spring.data.cosmos.repository.repository.AuditableIdGeneratedRepository; import com.azure.spring.data.cosmos.repository.repository.AuditableRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.repository.query.parser.Part; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.time.OffsetDateTime; import java.time.ZoneId; @@ -35,14 +34,14 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class AuditableIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -56,7 +55,7 @@ public class AuditableIT { @Autowired private StubAuditorProvider stubAuditorProvider; - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(cosmosTemplate, AuditableEntity.class, AuditableIdGeneratedEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BasicItemRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BasicItemRepositoryIT.java index 583f9f7b6a20..8cc0756773dc 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BasicItemRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BasicItemRepositoryIT.java @@ -12,14 +12,13 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.BasicItemRepository; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; @@ -27,12 +26,13 @@ import static com.azure.spring.data.cosmos.common.TestConstants.ID_1; import static com.azure.spring.data.cosmos.common.TestConstants.ID_2; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class BasicItemRepositoryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -51,7 +51,7 @@ public class BasicItemRepositoryIT { private static final BasicItem BASIC_ITEM_2 = new BasicItem(ID_2); - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.saveAll(Lists.newArrayList(BASIC_ITEM_1, BASIC_ITEM_2)); @@ -61,9 +61,9 @@ public void setUp() { public void testFindAllById() { final Iterable allById = TestUtils.toList(this.repository.findAllById(Arrays.asList(BASIC_ITEM_1.getId(), BASIC_ITEM_2.getId()))); - Assert.assertTrue(((ArrayList) allById).size() == 2); + Assertions.assertTrue(((ArrayList) allById).size() == 2); Iterator it = allById.iterator(); - Assert.assertEquals(BASIC_ITEM_1, it.next()); - Assert.assertEquals(BASIC_ITEM_2, it.next()); + assertEquals(BASIC_ITEM_1, it.next()); + assertEquals(BASIC_ITEM_2, it.next()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BigTypeRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BigTypeRepositoryIT.java index d5f7a23b642a..f6fb2e6c309c 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BigTypeRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/BigTypeRepositoryIT.java @@ -3,21 +3,18 @@ package com.azure.spring.data.cosmos.repository.integration; import com.azure.spring.data.cosmos.IntegrationTestCollectionManager; -import com.azure.spring.data.cosmos.common.ResponseDiagnosticsTestUtils; import com.azure.spring.data.cosmos.common.TestUtils; -import com.azure.spring.data.cosmos.config.CosmosConfig; import com.azure.spring.data.cosmos.core.CosmosTemplate; import com.azure.spring.data.cosmos.domain.BigType; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.BigTypeRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.math.BigDecimal; import java.math.BigInteger; @@ -25,11 +22,11 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class BigTypeRepositoryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -48,7 +45,7 @@ public class BigTypeRepositoryIT { private BigType TEST_BIGTYPES_2 = new BigType("2", "BigType2", bigDecimal2, bigInteger2); - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, BigType.class); repository.saveAll(Lists.newArrayList(TEST_BIGTYPES_1, TEST_BIGTYPES_2)); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CompositeIndexIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CompositeIndexIT.java index e61587d96271..e56206b4bd6f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CompositeIndexIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CompositeIndexIT.java @@ -15,26 +15,25 @@ import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository; import com.azure.spring.data.cosmos.repository.support.SimpleReactiveCosmosRepository; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CompositeIndexIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -45,12 +44,12 @@ public class CompositeIndexIT { CosmosEntityInformation information = new CosmosEntityInformation<>(CompositeIndexEntity.class); - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, CompositeIndexEntity.class); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(new CosmosEntityInformation<>(CompositeIndexEntity.class)); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ContactRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ContactRepositoryIT.java index c10af40ed10a..235fee153ec0 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ContactRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ContactRepositoryIT.java @@ -10,14 +10,13 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ContactRepository; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; @@ -27,8 +26,10 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ContactRepositoryIT { @@ -41,7 +42,7 @@ public class ContactRepositoryIT { private static final Contact TEST_CONTACT4 = new Contact("testId4", "faketitle4", INT_VALUE_3, true); private static final Contact TEST_CONTACT5 = new Contact("testId5", "faketitle3", INT_VALUE_3, true); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -50,7 +51,7 @@ public class ContactRepositoryIT { @Autowired private CosmosTemplate template; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Contact.class); repository.save(TEST_CONTACT1); @@ -65,7 +66,7 @@ public void testFindAll() { final List result = TestUtils.toList(repository.findAll()); assertThat(result.size()).isEqualTo(5); - Assert.assertEquals(Arrays.asList(TEST_CONTACT1, TEST_CONTACT2, TEST_CONTACT3, TEST_CONTACT4, + assertEquals(Arrays.asList(TEST_CONTACT1, TEST_CONTACT2, TEST_CONTACT3, TEST_CONTACT4, TEST_CONTACT5), result); final Contact contact = repository.findById(TEST_CONTACT1.getLogicId()).get(); @@ -108,7 +109,7 @@ public void testCountAndDeleteEntity() { final List result = TestUtils.toList(repository.findAll()); assertThat(result.size()).isEqualTo(5); - Assert.assertEquals(Arrays.asList(TEST_CONTACT1, TEST_CONTACT2, TEST_CONTACT3, TEST_CONTACT4, + assertEquals(Arrays.asList(TEST_CONTACT1, TEST_CONTACT2, TEST_CONTACT3, TEST_CONTACT4, TEST_CONTACT5), result); assertThat(result.get(0).getLogicId()).isEqualTo(TEST_CONTACT1.getLogicId()); assertThat(result.get(0).getTitle()).isEqualTo(TEST_CONTACT1.getTitle()); @@ -175,66 +176,68 @@ public void testCustomQuery() { public void testFindById() { final Optional optional = repository.findById(TEST_CONTACT1.getLogicId()); - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(TEST_CONTACT1, optional.get()); - Assert.assertFalse(repository.findById("").isPresent()); + Assertions.assertTrue(optional.isPresent()); + assertEquals(TEST_CONTACT1, optional.get()); + Assertions.assertFalse(repository.findById("").isPresent()); } @Test public void testFindByIdNotFound() { final Optional optional = repository.findById("unknown-id"); - Assert.assertFalse(optional.isPresent()); + Assertions.assertFalse(optional.isPresent()); } @Test public void testShouldFindSingleEntity() { final Contact contact = repository.findOneByTitle(TEST_CONTACT1.getTitle()); - Assert.assertEquals(TEST_CONTACT1, contact); + assertEquals(TEST_CONTACT1, contact); } @Test public void testShouldFindSingleOptionalEntity() { final Optional contact = repository.findOptionallyByTitle(TEST_CONTACT1.getTitle()); - Assert.assertTrue(contact.isPresent()); - Assert.assertEquals(TEST_CONTACT1, contact.get()); + Assertions.assertTrue(contact.isPresent()); + assertEquals(TEST_CONTACT1, contact.get()); - Assert.assertFalse(repository.findOptionallyByTitle("not here").isPresent()); + Assertions.assertFalse(repository.findOptionallyByTitle("not here").isPresent()); } - @Test(expected = CosmosAccessException.class) + @Test public void testShouldFailIfMultipleResultsReturned() { - repository.save(new Contact("testId2", TEST_CONTACT1.getTitle())); + assertThrows(CosmosAccessException.class, () -> { + repository.save(new Contact("testId2", TEST_CONTACT1.getTitle())); - repository.findOneByTitle(TEST_CONTACT1.getTitle()); + repository.findOneByTitle(TEST_CONTACT1.getTitle()); + }); } @Test public void testShouldAllowListAndIterableResponses() { final List contactList = TestUtils.toList(repository.findByTitle(TEST_CONTACT1.getTitle())); - Assert.assertEquals(TEST_CONTACT1, contactList.get(0)); - Assert.assertEquals(1, contactList.size()); + assertEquals(TEST_CONTACT1, contactList.get(0)); + assertEquals(1, contactList.size()); final Iterator contactIterator = repository.findByLogicId(TEST_CONTACT1.getLogicId()).iterator(); - Assert.assertTrue(contactIterator.hasNext()); - Assert.assertEquals(TEST_CONTACT1, contactIterator.next()); - Assert.assertFalse(contactIterator.hasNext()); + Assertions.assertTrue(contactIterator.hasNext()); + assertEquals(TEST_CONTACT1, contactIterator.next()); + Assertions.assertFalse(contactIterator.hasNext()); } // @Test // public void testAnnotatedQueries() { // List valueContacts = repository.getContactsByTitleAndValue(43, TEST_CONTACT5.getTitle()); -// Assert.assertEquals(1, valueContacts.size()); -// Assert.assertEquals(TEST_CONTACT5, valueContacts.get(0)); +// assertEquals(1, valueContacts.size()); +// assertEquals(TEST_CONTACT5, valueContacts.get(0)); // // List contactsWithOffset = repository.getContactsWithOffsetLimit(1, 2); -// Assert.assertEquals(2, contactsWithOffset.size()); -// Assert.assertEquals(TEST_CONTACT2, contactsWithOffset.get(0)); -// Assert.assertEquals(TEST_CONTACT3, contactsWithOffset.get(1)); +// assertEquals(2, contactsWithOffset.size()); +// assertEquals(TEST_CONTACT2, contactsWithOffset.get(0)); +// assertEquals(TEST_CONTACT3, contactsWithOffset.get(1)); // // List groupByContacts = repository.selectGroupBy(); -// Assert.assertEquals(3, groupByContacts.size()); +// assertEquals(3, groupByContacts.size()); // } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CosmosAnnotationIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CosmosAnnotationIT.java index a4311294d30b..360188db8650 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CosmosAnnotationIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CosmosAnnotationIT.java @@ -14,14 +14,12 @@ import com.azure.spring.data.cosmos.domain.TimeToLiveSample; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveRoleRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.Assert; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -30,8 +28,9 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CosmosAnnotationIT { @@ -42,7 +41,7 @@ public class CosmosAnnotationIT { private static final Role TEST_ROLE_3 = new Role(TestConstants.ID_3, true, TestConstants.LEVEL, TestConstants.ROLE_NAME); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -50,7 +49,7 @@ public class CosmosAnnotationIT { @Autowired private ReactiveRoleRepository repository; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { collectionManager.ensureContainersCreatedAndEmpty(cosmosTemplate, Role.class, TimeToLiveSample.class); repository.saveAll(Arrays.asList(TEST_ROLE_1, TEST_ROLE_2, TEST_ROLE_3)).collectList().block(); @@ -119,7 +118,7 @@ public void testTimeToLiveAnnotation() { public void testIndexingPolicyAnnotation() { final IndexingPolicy policy = collectionManager.getContainerProperties(Role.class).getIndexingPolicy(); - Assert.isTrue(policy.getIndexingMode() == TestConstants.INDEXING_POLICY_MODE, + assertTrue(policy.getIndexingMode() == TestConstants.INDEXING_POLICY_MODE, "unmatched collection policy indexing mode of class Role"); TestUtils.testIndexingPolicyPathsEquals(policy.getIncludedPaths() diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CountIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CountIT.java index 5f8211521f1e..bad9cc5bf56e 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CountIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CountIT.java @@ -9,22 +9,21 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ContactRepository; import com.azure.spring.data.cosmos.repository.repository.ReactiveCourseRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CountIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -34,7 +33,7 @@ public class CountIT { @Autowired private CosmosTemplate template; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { collectionManager.ensureContainersCreatedAndEmpty(template, Contact.class, Course.class); } @@ -47,11 +46,11 @@ public void testCountByField() { Contact contact4 = new Contact("4", "other", 30, true); repository.saveAll(Arrays.asList(contact1, contact2, contact3, contact4)); - Assert.assertEquals(3, repository.countByTitle("title")); - Assert.assertEquals(1, repository.countByTitle("other")); + assertEquals(3, repository.countByTitle("title")); + assertEquals(1, repository.countByTitle("other")); - Assert.assertEquals(Long.valueOf(1), repository.countByTitleAndIntValue("title", 25)); - Assert.assertEquals(Long.valueOf(2), repository.countByTitleAndIntValue("title", 30)); + assertEquals(Long.valueOf(1), repository.countByTitleAndIntValue("title", 25)); + assertEquals(Long.valueOf(2), repository.countByTitleAndIntValue("title", 30)); } @Test @@ -61,11 +60,11 @@ public void testCountByQuery() { Contact contact3 = new Contact("3", "different"); repository.saveAll(Arrays.asList(contact1, contact2, contact3)); - Assert.assertEquals(2, repository.countByQueryWithPrimitive("same")); - Assert.assertEquals(1, repository.countByQueryWithPrimitive("different")); + assertEquals(2, repository.countByQueryWithPrimitive("same")); + assertEquals(1, repository.countByQueryWithPrimitive("different")); - Assert.assertEquals(Long.valueOf(2), repository.countByQueryWithNonPrimitive("same")); - Assert.assertEquals(Long.valueOf(1), repository.countByQueryWithNonPrimitive("different")); + assertEquals(Long.valueOf(2), repository.countByQueryWithNonPrimitive("same")); + assertEquals(Long.valueOf(1), repository.countByQueryWithNonPrimitive("different")); } @Test @@ -75,8 +74,8 @@ public void testReactiveCountByField() { Course course3 = new Course("3", "course2", "department"); reactiveRepository.saveAll(Arrays.asList(course1, course2, course3)).blockLast(); - Assert.assertEquals(Long.valueOf(2), reactiveRepository.countByName("course").block()); - Assert.assertEquals(Long.valueOf(1), reactiveRepository.countByName("course2").block()); + assertEquals(Long.valueOf(2), reactiveRepository.countByName("course").block()); + assertEquals(Long.valueOf(1), reactiveRepository.countByName("course2").block()); } @Test @@ -86,8 +85,8 @@ public void testReactiveCountByQuery() { Course course3 = new Course("3", "course2", "department"); reactiveRepository.saveAll(Arrays.asList(course1, course2, course3)).blockLast(); - Assert.assertEquals(Long.valueOf(2), reactiveRepository.countByQuery("course").block()); - Assert.assertEquals(Long.valueOf(1), reactiveRepository.countByQuery("course2").block()); + assertEquals(Long.valueOf(2), reactiveRepository.countByQuery("course").block()); + assertEquals(Long.valueOf(1), reactiveRepository.countByQuery("course2").block()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CustomerRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CustomerRepositoryIT.java index eea90caa27bf..90a6ed88b5ce 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CustomerRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/CustomerRepositoryIT.java @@ -8,23 +8,23 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.CustomerRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class CustomerRepositoryIT { @@ -50,7 +50,7 @@ public class CustomerRepositoryIT { private static final Customer CUSTOMER_1 = new Customer(CUSTOMER_ID_1, CUSTOMER_LEVEL_1, USER_1); private static final Customer CUSTOMER_2 = new Customer(CUSTOMER_ID_2, CUSTOMER_LEVEL_1, USER_2); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -59,24 +59,24 @@ public class CustomerRepositoryIT { @Autowired private CosmosTemplate template; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Customer.class); this.repository.saveAll(Arrays.asList(CUSTOMER_0, CUSTOMER_1, CUSTOMER_2)); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(new CosmosEntityInformation<>(Customer.class)); } private void assertCustomerListEquals(@NonNull List customers, @NonNull List reference) { - Assert.assertEquals(reference.size(), customers.size()); + assertEquals(reference.size(), customers.size()); customers.sort(Comparator.comparing(Customer::getId)); reference.sort(Comparator.comparing(Customer::getId)); - Assert.assertEquals(reference, customers); + assertEquals(reference, customers); } @Test @@ -90,7 +90,7 @@ public void testFindByUserAndLevel() { customers = this.repository.findByUser_Name(FAKE_USER_NAME); - Assert.assertFalse(customers.iterator().hasNext()); + Assertions.assertFalse(customers.iterator().hasNext()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/EtagIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/EtagIT.java index 174f1cb6e5be..defeb6e5f92e 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/EtagIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/EtagIT.java @@ -11,15 +11,14 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.PersonWithEtagRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -32,12 +31,13 @@ import static com.azure.spring.data.cosmos.common.TestConstants.FIRST_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.HOBBIES; import static com.azure.spring.data.cosmos.common.TestConstants.LAST_NAME; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class EtagIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -45,7 +45,7 @@ public class EtagIT { @Autowired PersonWithEtagRepository personWithEtagRepository; - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, PersonWithEtag.class); } @@ -54,7 +54,7 @@ private static PersonWithEtag createPersonWithEtag() { return new PersonWithEtag(UUID.randomUUID().toString(), FIRST_NAME, LAST_NAME, HOBBIES, ADDRESSES); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(new CosmosEntityInformation<>(PersonWithEtag.class)); } @@ -62,17 +62,17 @@ public static void cleanUp() { @Test public void testCrudOperationsShouldApplyEtag() { final PersonWithEtag insertedPersonWithEtag = personWithEtagRepository.save(createPersonWithEtag()); - Assert.assertNotNull(insertedPersonWithEtag.getEtag()); + Assertions.assertNotNull(insertedPersonWithEtag.getEtag()); insertedPersonWithEtag.setFirstName(LAST_NAME); final PersonWithEtag updatedPersonWithEtag = personWithEtagRepository.save(insertedPersonWithEtag); - Assert.assertNotNull(updatedPersonWithEtag.getEtag()); - Assert.assertNotEquals(insertedPersonWithEtag.getEtag(), updatedPersonWithEtag.getEtag()); + Assertions.assertNotNull(updatedPersonWithEtag.getEtag()); + Assertions.assertNotEquals(insertedPersonWithEtag.getEtag(), updatedPersonWithEtag.getEtag()); final Optional foundPersonWithEtag = personWithEtagRepository.findById(insertedPersonWithEtag.getId()); - Assert.assertTrue(foundPersonWithEtag.isPresent()); - Assert.assertNotNull(foundPersonWithEtag.get().getEtag()); - Assert.assertEquals(updatedPersonWithEtag.getEtag(), foundPersonWithEtag.get().getEtag()); + Assertions.assertTrue(foundPersonWithEtag.isPresent()); + Assertions.assertNotNull(foundPersonWithEtag.get().getEtag()); + assertEquals(updatedPersonWithEtag.getEtag(), foundPersonWithEtag.get().getEtag()); } @Test @@ -82,16 +82,16 @@ public void testCrudListOperationsShouldApplyEtag() { people.add(createPersonWithEtag()); final List insertedPeople = toList(personWithEtagRepository.saveAll(people)); - insertedPeople.forEach(person -> Assert.assertNotNull(person.getEtag())); + insertedPeople.forEach(person -> Assertions.assertNotNull(person.getEtag())); insertedPeople.forEach(person -> person.setFirstName(LAST_NAME)); final List updatedPeople = toList(personWithEtagRepository.saveAll(insertedPeople)); for (int i = 0; i < updatedPeople.size(); i++) { PersonWithEtag insertedPersonWithEtag = insertedPeople.get(i); PersonWithEtag updatedPersonWithEtag = updatedPeople.get(i); - Assert.assertEquals(insertedPersonWithEtag.getId(), updatedPersonWithEtag.getId()); - Assert.assertNotNull(updatedPersonWithEtag.getEtag()); - Assert.assertNotEquals(insertedPersonWithEtag.getEtag(), updatedPersonWithEtag.getEtag()); + assertEquals(insertedPersonWithEtag.getId(), updatedPersonWithEtag.getId()); + Assertions.assertNotNull(updatedPersonWithEtag.getEtag()); + Assertions.assertNotEquals(insertedPersonWithEtag.getEtag(), updatedPersonWithEtag.getEtag()); } final List peopleIds = updatedPeople.stream() @@ -101,8 +101,8 @@ public void testCrudListOperationsShouldApplyEtag() { for (int i = 0; i < foundPeople.size(); i++) { PersonWithEtag updatedPersonWithEtag = updatedPeople.get(i); PersonWithEtag foundPersonWithEtag = foundPeople.get(i); - Assert.assertNotNull(foundPersonWithEtag.getEtag()); - Assert.assertEquals(updatedPersonWithEtag.getEtag(), foundPersonWithEtag.getEtag()); + Assertions.assertNotNull(foundPersonWithEtag.getEtag()); + assertEquals(updatedPersonWithEtag.getEtag(), foundPersonWithEtag.getEtag()); } } @@ -121,13 +121,13 @@ public void testShouldFailIfEtagDoesNotMatch() { try { personWithEtagRepository.save(updatedPersonWithEtag); - Assert.fail(); + Assertions.fail(); } catch (CosmosPreconditionFailedException ex) { } try { personWithEtagRepository.delete(updatedPersonWithEtag); - Assert.fail(); + Assertions.fail(); } catch (CosmosPreconditionFailedException ex) { } } @@ -138,7 +138,7 @@ public void testBulkShouldFailIfEtagDoesNotMatch() { people.add(createPersonWithEtag()); final List insertedPeople = toList(personWithEtagRepository.saveAll(people)); - insertedPeople.forEach(person -> Assert.assertNotNull(person.getEtag())); + insertedPeople.forEach(person -> Assertions.assertNotNull(person.getEtag())); final List updatedPeople = toList(insertedPeople); updatedPeople.get(0).setFirstName(LAST_NAME); @@ -148,14 +148,14 @@ public void testBulkShouldFailIfEtagDoesNotMatch() { try { List result = toList(personWithEtagRepository.saveAll(updatedPeopleWithEtag)); - Assert.assertEquals(result.size(), 0); + assertEquals(result.size(), 0); } catch (CosmosAccessException ex) { } try { personWithEtagRepository.deleteAll(updatedPeopleWithEtag); List result2 = toList(personWithEtagRepository.findAll()); - Assert.assertEquals(result2.size(), 1); + assertEquals(result2.size(), 1); } catch (CosmosAccessException ex) { } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/HierarchicalPartitionKeyRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/HierarchicalPartitionKeyRepositoryIT.java index 8049dd4d5add..2f24e534e1cd 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/HierarchicalPartitionKeyRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/HierarchicalPartitionKeyRepositoryIT.java @@ -11,15 +11,14 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.HierarchicalPartitionKeyRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.List; @@ -27,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class HierarchicalPartitionKeyRepositoryIT { @@ -37,7 +36,7 @@ public class HierarchicalPartitionKeyRepositoryIT { private static final HierarchicalPartitionKeyEntity HIERARCHICAL_ENTITY_2 = new HierarchicalPartitionKeyEntity("id_2", "Michael", "Smith", "23456"); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static CosmosEntityInformation hierarchicalPartitionKeyEntityInformation @@ -49,15 +48,15 @@ public class HierarchicalPartitionKeyRepositoryIT { @Autowired HierarchicalPartitionKeyRepository repository; - @BeforeClass + @BeforeAll public static void init() { } - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, HierarchicalPartitionKeyEntity.class); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(hierarchicalPartitionKeyEntityInformation); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IndexPolicyUpdateIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IndexPolicyUpdateIT.java index c1a4287b1b27..3c2c74fc6253 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IndexPolicyUpdateIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IndexPolicyUpdateIT.java @@ -16,25 +16,24 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class IndexPolicyUpdateIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -51,7 +50,7 @@ public class IndexPolicyUpdateIT { CosmosEntityInformation addressEntityInformation = new CosmosEntityInformation<>(Address.class); - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, IndexPolicyEntity.class, ComplexIndexPolicyEntity.class, IndexPolicyOverwriteEntity.class, Address.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IntegerIdDomainRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IntegerIdDomainRepositoryIT.java index b65aa5f73ef9..3240436dbc49 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IntegerIdDomainRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/IntegerIdDomainRepositoryIT.java @@ -10,16 +10,15 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.IntegerIdDomainRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Collections; import java.util.Iterator; @@ -29,8 +28,9 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class IntegerIdDomainRepositoryIT { @@ -38,7 +38,7 @@ public class IntegerIdDomainRepositoryIT { private static final String NAME = "panli"; private static final IntegerIdDomain DOMAIN = new IntegerIdDomain(ID, NAME); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -47,7 +47,7 @@ public class IntegerIdDomainRepositoryIT { @Autowired private IntegerIdDomainRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, IntegerIdDomain.class); this.repository.save(DOMAIN); @@ -56,43 +56,44 @@ public void setUp() { @Test public void testIntegerIdDomain() { this.repository.deleteAll(); - Assert.assertFalse(this.repository.findById(ID).isPresent()); + Assertions.assertFalse(this.repository.findById(ID).isPresent()); this.repository.save(DOMAIN); final Optional foundOptional = this.repository.findById(ID); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(DOMAIN.getNumber(), foundOptional.get().getNumber()); - Assert.assertEquals(DOMAIN.getName(), foundOptional.get().getName()); + Assertions.assertTrue(foundOptional.isPresent()); + assertEquals(DOMAIN.getNumber(), foundOptional.get().getNumber()); + assertEquals(DOMAIN.getName(), foundOptional.get().getName()); this.repository.delete(DOMAIN); - Assert.assertFalse(this.repository.findById(ID).isPresent()); + Assertions.assertFalse(this.repository.findById(ID).isPresent()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidDomain() { - new CosmosEntityInformation(InvalidDomain.class); + assertThrows(IllegalArgumentException.class, () -> + new CosmosEntityInformation(InvalidDomain.class)); } @Test public void testBasicQuery() { final IntegerIdDomain save = this.repository.save(DOMAIN); - Assert.assertNotNull(save); + Assertions.assertNotNull(save); } @Test public void testSaveAndFindById() { - Assert.assertNotNull(this.repository.save(DOMAIN)); + Assertions.assertNotNull(this.repository.save(DOMAIN)); final Optional savedEntity = this.repository.findById(DOMAIN.getNumber()); - Assert.assertTrue(savedEntity.isPresent()); - Assert.assertEquals(DOMAIN, savedEntity.get()); + Assertions.assertTrue(savedEntity.isPresent()); + assertEquals(DOMAIN, savedEntity.get()); } @Test public void testSaveAllAndFindAll() { - Assert.assertTrue(this.repository.findAll().iterator().hasNext()); + Assertions.assertTrue(this.repository.findAll().iterator().hasNext()); final Set entitiesToSave = Collections.singleton(DOMAIN); this.repository.saveAll(entitiesToSave); @@ -100,58 +101,62 @@ public void testSaveAllAndFindAll() { final Set savedEntities = StreamSupport.stream(this.repository.findAll().spliterator(), false) .collect(Collectors.toSet()); - Assert.assertTrue(entitiesToSave.containsAll(savedEntities)); + Assertions.assertTrue(entitiesToSave.containsAll(savedEntities)); } @Test public void testFindAllById() { final Iterable allById = this.repository.findAllById(Collections.singleton(DOMAIN.getNumber())); - Assert.assertTrue(allById.iterator().hasNext()); + Assertions.assertTrue(allById.iterator().hasNext()); } @Test public void testCount() { - Assert.assertEquals(1, repository.count()); + assertEquals(1, repository.count()); } @Test public void testDeleteById() { this.repository.save(DOMAIN); this.repository.deleteById(DOMAIN.getNumber()); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteByIdShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.deleteById(DOMAIN.getNumber()); + assertThrows(CosmosNotFoundException.class, () -> { + this.repository.deleteAll(); + this.repository.deleteById(DOMAIN.getNumber()); + }); } @Test public void testDelete() { this.repository.save(DOMAIN); this.repository.delete(DOMAIN); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.delete(DOMAIN); + assertThrows(CosmosNotFoundException.class, () -> { + this.repository.deleteAll(); + this.repository.delete(DOMAIN); + }); } @Test public void testDeleteAll() { this.repository.save(DOMAIN); this.repository.deleteAll(Collections.singleton(DOMAIN)); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } @Test public void testExistsById() { this.repository.save(DOMAIN); - Assert.assertTrue(this.repository.existsById(DOMAIN.getNumber())); + Assertions.assertTrue(this.repository.existsById(DOMAIN.getNumber())); } @Test @@ -164,17 +169,17 @@ public void testFindAllSort() { final List ascending = StreamSupport .stream(this.repository.findAll(ascSort).spliterator(), false) .collect(Collectors.toList()); - Assert.assertEquals(2, ascending.size()); - Assert.assertEquals(DOMAIN, ascending.get(0)); - Assert.assertEquals(other, ascending.get(1)); + assertEquals(2, ascending.size()); + assertEquals(DOMAIN, ascending.get(0)); + assertEquals(other, ascending.get(1)); final Sort descSort = Sort.by(Sort.Direction.DESC, "number"); final List descending = StreamSupport .stream(this.repository.findAll(descSort).spliterator(), false) .collect(Collectors.toList()); - Assert.assertEquals(2, descending.size()); - Assert.assertEquals(other, descending.get(0)); - Assert.assertEquals(DOMAIN, descending.get(1)); + assertEquals(2, descending.size()); + assertEquals(other, descending.get(0)); + assertEquals(DOMAIN, descending.get(1)); } @@ -186,13 +191,13 @@ public void testFindAllPageable() { final Page page1 = this.repository.findAll(new CosmosPageRequest(0, 1, null)); final Iterator page1Iterator = page1.iterator(); - Assert.assertTrue(page1Iterator.hasNext()); - Assert.assertEquals(DOMAIN, page1Iterator.next()); + Assertions.assertTrue(page1Iterator.hasNext()); + assertEquals(DOMAIN, page1Iterator.next()); final Page page2 = this.repository.findAll(new CosmosPageRequest(1, 1, null)); final Iterator page2Iterator = page2.iterator(); - Assert.assertTrue(page2Iterator.hasNext()); - Assert.assertEquals(other, page2Iterator.next()); + Assertions.assertTrue(page2Iterator.hasNext()); + assertEquals(other, page2Iterator.next()); } private static class InvalidDomain { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/LongIdDomainRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/LongIdDomainRepositoryIT.java index d3524bbe7d80..9c3c95679394 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/LongIdDomainRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/LongIdDomainRepositoryIT.java @@ -11,16 +11,15 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.LongIdDomainRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; @@ -33,8 +32,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class LongIdDomainRepositoryIT { @@ -47,7 +47,7 @@ public class LongIdDomainRepositoryIT { private static final LongIdDomain DOMAIN_1 = new LongIdDomain(ID_1, NAME_1); private static final LongIdDomain DOMAIN_2 = new LongIdDomain(ID_2, NAME_2); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -56,7 +56,7 @@ public class LongIdDomainRepositoryIT { @Autowired private LongIdDomainRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, LongIdDomain.class); this.repository.save(DOMAIN_1); @@ -66,43 +66,44 @@ public void setUp() { @Test public void testLongIdDomain() { this.repository.deleteAll(); - Assert.assertFalse(this.repository.findById(ID_1).isPresent()); + Assertions.assertFalse(this.repository.findById(ID_1).isPresent()); this.repository.save(DOMAIN_1); final Optional foundOptional = this.repository.findById(ID_1); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(DOMAIN_1.getNumber(), foundOptional.get().getNumber()); - Assert.assertEquals(DOMAIN_1.getName(), foundOptional.get().getName()); + Assertions.assertTrue(foundOptional.isPresent()); + assertEquals(DOMAIN_1.getNumber(), foundOptional.get().getNumber()); + assertEquals(DOMAIN_1.getName(), foundOptional.get().getName()); this.repository.delete(DOMAIN_1); - Assert.assertFalse(this.repository.findById(ID_1).isPresent()); + Assertions.assertFalse(this.repository.findById(ID_1).isPresent()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidDomain() { - new CosmosEntityInformation(InvalidDomain.class); + assertThrows(IllegalArgumentException.class, () -> + new CosmosEntityInformation(InvalidDomain.class)); } @Test public void testBasicQuery() { final LongIdDomain save = this.repository.save(DOMAIN_1); - Assert.assertNotNull(save); + Assertions.assertNotNull(save); } @Test public void testSaveAndFindById() { - Assert.assertNotNull(this.repository.save(DOMAIN_1)); + Assertions.assertNotNull(this.repository.save(DOMAIN_1)); final Optional savedEntity = this.repository.findById(DOMAIN_1.getNumber()); - Assert.assertTrue(savedEntity.isPresent()); - Assert.assertEquals(DOMAIN_1, savedEntity.get()); + Assertions.assertTrue(savedEntity.isPresent()); + assertEquals(DOMAIN_1, savedEntity.get()); } @Test public void testSaveAllAndFindAll() { - Assert.assertTrue(this.repository.findAll().iterator().hasNext()); + Assertions.assertTrue(this.repository.findAll().iterator().hasNext()); final Set entitiesToSave = Stream.of(DOMAIN_1, DOMAIN_2).collect(Collectors.toSet()); this.repository.saveAll(entitiesToSave); @@ -110,14 +111,14 @@ public void testSaveAllAndFindAll() { final Set savedEntities = StreamSupport.stream(this.repository.findAll().spliterator(), false) .collect(Collectors.toSet()); - Assert.assertTrue(entitiesToSave.containsAll(savedEntities)); + Assertions.assertTrue(entitiesToSave.containsAll(savedEntities)); } @Test public void testFindAllById() { final Iterable allById = TestUtils.toList(this.repository.findAllById(Arrays.asList(DOMAIN_1.getNumber(), DOMAIN_2.getNumber()))); - Assert.assertTrue(((ArrayList) allById).size() == 2); + Assertions.assertTrue(((ArrayList) allById).size() == 2); Iterator it = allById.iterator(); assertLongIdDomainEquals(Arrays.asList(it.next(), it.next()), Arrays.asList(DOMAIN_1, DOMAIN_2)); } @@ -125,12 +126,12 @@ public void testFindAllById() { private void assertLongIdDomainEquals(List cur, List reference) { cur.sort(Comparator.comparing(LongIdDomain::getNumber)); reference.sort(Comparator.comparing(LongIdDomain::getNumber)); - Assert.assertEquals(reference, cur); + assertEquals(reference, cur); } @Test public void testCount() { - Assert.assertEquals(2, repository.count()); + assertEquals(2, repository.count()); } @Test @@ -139,26 +140,30 @@ public void testDeleteById() { this.repository.save(DOMAIN_2); this.repository.deleteById(DOMAIN_1.getNumber()); this.repository.deleteById(DOMAIN_2.getNumber()); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteByIdShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.deleteById(DOMAIN_1.getNumber()); + assertThrows(CosmosNotFoundException.class, () ->{ + this.repository.deleteAll(); + this.repository.deleteById(DOMAIN_1.getNumber()); + }); } @Test public void testDelete() { this.repository.save(DOMAIN_1); this.repository.delete(DOMAIN_1); - Assert.assertEquals(1, this.repository.count()); + assertEquals(1, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.delete(DOMAIN_1); + assertThrows(CosmosNotFoundException.class, () ->{ + this.repository.deleteAll(); + this.repository.delete(DOMAIN_1); + }); } @Test @@ -166,13 +171,13 @@ public void testDeleteAll() { this.repository.save(DOMAIN_1); this.repository.save(DOMAIN_2); this.repository.deleteAll(Arrays.asList(DOMAIN_1, DOMAIN_2)); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } @Test public void testExistsById() { this.repository.save(DOMAIN_1); - Assert.assertTrue(this.repository.existsById(DOMAIN_1.getNumber())); + Assertions.assertTrue(this.repository.existsById(DOMAIN_1.getNumber())); } @Test @@ -185,19 +190,19 @@ public void testFindAllSort() { final List ascending = StreamSupport .stream(this.repository.findAll(ascSort).spliterator(), false) .collect(Collectors.toList()); - Assert.assertEquals(3, ascending.size()); - Assert.assertEquals(DOMAIN_1, ascending.get(0)); - Assert.assertEquals(other, ascending.get(1)); - Assert.assertEquals(DOMAIN_2, ascending.get(2)); + assertEquals(3, ascending.size()); + assertEquals(DOMAIN_1, ascending.get(0)); + assertEquals(other, ascending.get(1)); + assertEquals(DOMAIN_2, ascending.get(2)); final Sort descSort = Sort.by(Sort.Direction.DESC, "number"); final List descending = StreamSupport .stream(this.repository.findAll(descSort).spliterator(), false) .collect(Collectors.toList()); - Assert.assertEquals(3, descending.size()); - Assert.assertEquals(DOMAIN_2, descending.get(0)); - Assert.assertEquals(other, descending.get(1)); - Assert.assertEquals(DOMAIN_1, descending.get(2)); + assertEquals(3, descending.size()); + assertEquals(DOMAIN_2, descending.get(0)); + assertEquals(other, descending.get(1)); + assertEquals(DOMAIN_1, descending.get(2)); } @@ -208,18 +213,18 @@ public void testFindAllPageable() { final Page page1 = this.repository.findAll(new CosmosPageRequest(0, 1, null)); final Iterator page1Iterator = page1.iterator(); - Assert.assertTrue(page1Iterator.hasNext()); - Assert.assertEquals(DOMAIN_1, page1Iterator.next()); + Assertions.assertTrue(page1Iterator.hasNext()); + assertEquals(DOMAIN_1, page1Iterator.next()); final Page page2 = this.repository.findAll(new CosmosPageRequest(1, 1, null)); final Iterator page2Iterator = page2.iterator(); - Assert.assertTrue(page2Iterator.hasNext()); - Assert.assertEquals(DOMAIN_2, page2Iterator.next()); + Assertions.assertTrue(page2Iterator.hasNext()); + assertEquals(DOMAIN_2, page2Iterator.next()); final Page page3 = this.repository.findAll(new CosmosPageRequest(2, 1, null)); final Iterator page3Iterator = page3.iterator(); - Assert.assertTrue(page3Iterator.hasNext()); - Assert.assertEquals(other, page3Iterator.next()); + Assertions.assertTrue(page3Iterator.hasNext()); + assertEquals(other, page3Iterator.next()); } private static class InvalidDomain { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/MemoRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/MemoRepositoryIT.java index a032499c9979..1df8763fec82 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/MemoRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/MemoRepositoryIT.java @@ -11,16 +11,15 @@ import com.azure.spring.data.cosmos.exception.CosmosAccessException; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.MemoRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -31,8 +30,9 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class MemoRepositoryIT { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(TestConstants.DATE_FORMAT); @@ -47,7 +47,7 @@ public class MemoRepositoryIT { private static Memo testMemo2; private static Memo testMemo3; - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -56,7 +56,7 @@ public class MemoRepositoryIT { @Autowired MemoRepository repository; - @BeforeClass + @BeforeAll public static void init() throws ParseException { memoDate = DATE_FORMAT.parse(TestConstants.DATE_STRING); memoDateBefore = DATE_FORMAT.parse(TestConstants.DATE_BEFORE_STRING); @@ -68,7 +68,7 @@ public static void init() throws ParseException { testMemo3 = new Memo(TestConstants.ID_3, TestConstants.NEW_MESSAGE, memoDateAfter, Importance.LOW); } - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Memo.class); repository.saveAll(Arrays.asList(testMemo1, testMemo2, testMemo3)); @@ -108,12 +108,12 @@ private void assertMemoEquals(Memo actual, Memo expected) { public void testFindByBefore() { List memos = TestUtils.toList(this.repository.findByDateBefore(memoDateBefore)); - Assert.assertTrue(memos.isEmpty()); + Assertions.assertTrue(memos.isEmpty()); memos = TestUtils.toList(this.repository.findByDateBefore(memoDate)); - Assert.assertEquals(1, memos.size()); - Assert.assertEquals(testMemo1, memos.get(0)); + assertEquals(1, memos.size()); + assertEquals(testMemo1, memos.get(0)); memos = TestUtils.toList(this.repository.findByDateBefore(memoDateAfter)); final List reference = Arrays.asList(testMemo1, testMemo2); @@ -121,8 +121,8 @@ public void testFindByBefore() { memos.sort(Comparator.comparing(Memo::getId)); reference.sort(Comparator.comparing(Memo::getId)); - Assert.assertEquals(reference.size(), memos.size()); - Assert.assertEquals(reference, memos); + assertEquals(reference.size(), memos.size()); + assertEquals(reference, memos); } @Test @@ -130,12 +130,12 @@ public void testFindByBeforeWithAndOr() { List memos = TestUtils.toList(this.repository.findByDateBeforeAndMessage(memoDate, TestConstants.NEW_MESSAGE)); - Assert.assertTrue(memos.isEmpty()); + Assertions.assertTrue(memos.isEmpty()); memos = TestUtils.toList(this.repository.findByDateBeforeAndMessage(memoDate, TestConstants.MESSAGE)); - Assert.assertEquals(1, memos.size()); - Assert.assertEquals(testMemo1, memos.get(0)); + assertEquals(1, memos.size()); + assertEquals(testMemo1, memos.get(0)); memos = TestUtils.toList(this.repository.findByDateBeforeOrMessage(memoDateAfter, TestConstants.MESSAGE)); final List reference = Arrays.asList(testMemo1, testMemo2); @@ -143,20 +143,20 @@ public void testFindByBeforeWithAndOr() { memos.sort(Comparator.comparing(Memo::getId)); reference.sort(Comparator.comparing(Memo::getId)); - Assert.assertEquals(reference.size(), memos.size()); - Assert.assertEquals(reference, memos); + assertEquals(reference.size(), memos.size()); + assertEquals(reference, memos); } @Test public void testFindByAfter() { List memos = TestUtils.toList(this.repository.findByDateAfter(memoDateAfter)); - Assert.assertTrue(memos.isEmpty()); + Assertions.assertTrue(memos.isEmpty()); memos = TestUtils.toList(this.repository.findByDateAfter(memoDate)); - Assert.assertEquals(1, memos.size()); - Assert.assertEquals(testMemo3, memos.get(0)); + assertEquals(1, memos.size()); + assertEquals(testMemo3, memos.get(0)); memos = TestUtils.toList(this.repository.findByDateAfter(memoDateBefore)); final List reference = Arrays.asList(testMemo2, testMemo3); @@ -164,20 +164,20 @@ public void testFindByAfter() { memos.sort(Comparator.comparing(Memo::getId)); reference.sort(Comparator.comparing(Memo::getId)); - Assert.assertEquals(reference.size(), memos.size()); - Assert.assertEquals(reference, memos); + assertEquals(reference.size(), memos.size()); + assertEquals(reference, memos); } @Test public void testFindByAfterWithAndOr() { List memos = TestUtils.toList(this.repository.findByDateAfterAndMessage(memoDate, TestConstants.MESSAGE)); - Assert.assertTrue(memos.isEmpty()); + Assertions.assertTrue(memos.isEmpty()); memos = TestUtils.toList(this.repository.findByDateAfterAndMessage(memoDate, TestConstants.NEW_MESSAGE)); - Assert.assertEquals(1, memos.size()); - Assert.assertEquals(testMemo3, memos.get(0)); + assertEquals(1, memos.size()); + assertEquals(testMemo3, memos.get(0)); memos = TestUtils.toList(this.repository.findByDateAfterOrMessage(memoDateBefore, TestConstants.MESSAGE)); final List reference = Arrays.asList(testMemo1, testMemo2, testMemo3); @@ -185,8 +185,8 @@ public void testFindByAfterWithAndOr() { memos.sort(Comparator.comparing(Memo::getId)); reference.sort(Comparator.comparing(Memo::getId)); - Assert.assertEquals(reference.size(), memos.size()); - Assert.assertEquals(reference, memos); + assertEquals(reference.size(), memos.size()); + assertEquals(reference, memos); } @Test @@ -226,22 +226,22 @@ private void assertMemoListEquals(List memos, List reference) { memos.sort(Comparator.comparing(Memo::getId)); reference.sort(Comparator.comparing(Memo::getId)); - Assert.assertEquals(reference.size(), memos.size()); - Assert.assertEquals(reference, memos); + assertEquals(reference.size(), memos.size()); + assertEquals(reference, memos); } - @Test(expected = CosmosAccessException.class) - @Ignore // TODO(pan): Ignore this test case for now, will update this from service update. + @Test + @Disabled // TODO(pan): Ignore this test case for now, will update this from service update. public void testFindByStartsWithWithException() { - repository.findByMessageStartsWith(testMemo1.getMessage()); + assertThrows(CosmosAccessException.class, () -> repository.findByMessageStartsWith(testMemo1.getMessage())); } @Test public void testFindByStartsWith() { final List result = TestUtils.toList(repository.findByMessageStartsWith(testMemo1.getMessage().substring(0, 10))); - Assert.assertEquals(testMemo1, result.get(0)); - Assert.assertEquals(1, result.size()); + assertEquals(testMemo1, result.get(0)); + assertEquals(1, result.size()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/NestedPartitionKeyRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/NestedPartitionKeyRepositoryIT.java index 331228967015..ee5fc4dad925 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/NestedPartitionKeyRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/NestedPartitionKeyRepositoryIT.java @@ -10,14 +10,13 @@ import com.azure.spring.data.cosmos.domain.NestedPartitionKeyEntityWithGeneratedValue; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.NestedPartitionKeyRepository; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.List; @@ -25,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class NestedPartitionKeyRepositoryIT { @@ -35,7 +34,7 @@ public class NestedPartitionKeyRepositoryIT { private static final NestedPartitionKeyEntityWithGeneratedValue NESTED_ENTITY_2 = new NestedPartitionKeyEntityWithGeneratedValue(null, new NestedEntity("partitionKey2")); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -44,10 +43,10 @@ public class NestedPartitionKeyRepositoryIT { @Autowired NestedPartitionKeyRepository repository; - @BeforeClass + @BeforeAll public static void init() { } - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, NestedPartitionKeyEntityWithGeneratedValue.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java index 18707edbe276..249f183af553 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java @@ -14,15 +14,14 @@ import com.azure.spring.data.cosmos.domain.Address; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.PageableAddressRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -39,11 +38,11 @@ import static com.azure.spring.data.cosmos.domain.Address.TEST_ADDRESS4_PARTITION3; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class PageableAddressRepositoryIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -58,7 +57,7 @@ public class PageableAddressRepositoryIT { @Autowired private CosmosFactory cosmosFactory; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Address.class); repository.save(TEST_ADDRESS1_PARTITION1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableMemoRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableMemoRepositoryIT.java index 7cf66204ec4e..4bb625fbd45b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableMemoRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableMemoRepositoryIT.java @@ -13,17 +13,16 @@ import com.azure.spring.data.cosmos.domain.PageableMemo; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.PageableMemoRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -38,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class PageableMemoRepositoryIT { private static final int TOTAL_CONTENT_SIZE = 500; - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -64,7 +63,7 @@ public class PageableMemoRepositoryIT { private static boolean isSetupDone; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreated(template, PageableMemo.class); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java index e28702e04731..ec134cf81533 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java @@ -10,15 +10,14 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.PageablePersonRepository; import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.HashSet; @@ -28,14 +27,14 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class PageablePersonRepositoryIT { private static final int TOTAL_CONTENT_SIZE = 25; public static final int ONE_KB = 1024; - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -48,7 +47,7 @@ public class PageablePersonRepositoryIT { private static boolean isSetupDone; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreated(template, PageablePerson.class); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersistableIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersistableIT.java index d693ee84f421..d9fce23c12c1 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersistableIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersistableIT.java @@ -11,30 +11,27 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.PersistableEntityRepository; import com.azure.spring.data.cosmos.repository.repository.ReactivePersistableEntityRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class PersistableIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -46,11 +43,9 @@ public class PersistableIT { @Autowired private CosmosTemplate template; - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Before + + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, PersistableEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersonCrossPartitionIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersonCrossPartitionIT.java index 472807cc2e02..326d62599a71 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersonCrossPartitionIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PersonCrossPartitionIT.java @@ -15,16 +15,15 @@ import com.azure.spring.data.cosmos.repository.repository.AuditableRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import org.assertj.core.util.Lists; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.List; @@ -43,11 +42,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.data.domain.Sort.Direction.ASC; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class PersonCrossPartitionIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static final PersonCrossPartition TEST_PERSON_CP = new PersonCrossPartition(ID_1, FIRST_NAME, LAST_NAME, HOBBIES, @@ -75,7 +74,7 @@ public class PersonCrossPartitionIT { @Autowired private AddressRepository addressRepository; - @Before + @BeforeEach public void setUp() { personCrossPartitionInfo = new CosmosEntityInformation<>(PersonCrossPartition.class); containerName = personCrossPartitionInfo.getContainerName(); @@ -83,7 +82,7 @@ public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(cosmosTemplate, PersonCrossPartition.class); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(personCrossPartitionInfo); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositoryIT.java index 78a1bba4a862..a4acb6f0c4d8 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositoryIT.java @@ -9,15 +9,14 @@ import com.azure.spring.data.cosmos.domain.Project; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ProjectRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; @@ -27,9 +26,10 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ProjectRepositoryIT { @@ -73,7 +73,7 @@ public class ProjectRepositoryIT { private static final List PROJECTS = Arrays.asList(PROJECT_0, PROJECT_1, PROJECT_2, PROJECT_3, PROJECT_4); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -82,19 +82,19 @@ public class ProjectRepositoryIT { @Autowired private ProjectRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Project.class); this.repository.saveAll(PROJECTS); } private void assertProjectListEquals(@NonNull List projects, @NonNull List reference) { - Assert.assertEquals(reference.size(), projects.size()); + assertEquals(reference.size(), projects.size()); projects.sort(Comparator.comparing(Project::getId)); reference.sort(Comparator.comparing(Project::getId)); - Assert.assertEquals(reference, projects); + assertEquals(reference, projects); } @Test @@ -105,7 +105,7 @@ public void testFindByWithAnd() { projects = TestUtils.toList(this.repository.findByNameAndStarCount(NAME_0, STAR_COUNT_1)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(this.repository.findByNameAndStarCount(NAME_0, STAR_COUNT_0)); @@ -120,7 +120,7 @@ public void testFindByWithOr() { projects = TestUtils.toList(this.repository.findByNameOrForkCount(FAKE_NAME, FAKE_COUNT)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(this.repository.findByNameOrForkCount(NAME_0, FORK_COUNT_1)); @@ -135,7 +135,7 @@ public void testFindByWithAndPartition() { projects = TestUtils.toList(this.repository.findByNameAndCreator(NAME_0, CREATOR_1)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(this.repository.findByNameAndCreator(NAME_0, CREATOR_0)); @@ -157,7 +157,7 @@ public void testFindByWithOrPartition() { projects = TestUtils.toList(this.repository.findByNameOrCreator(FAKE_NAME, FAKE_CREATOR)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(this.repository.findByNameOrCreator(NAME_0, CREATOR_1)); @@ -173,7 +173,7 @@ public void testFindByWithAndOr() { projects = TestUtils.toList(repository.findByNameAndCreatorOrForkCount(NAME_1, CREATOR_2, FAKE_COUNT)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByNameAndCreatorOrForkCount(NAME_1, CREATOR_1, FORK_COUNT_2)); @@ -189,7 +189,7 @@ public void testFindByWithOrAnd() { projects = TestUtils.toList(repository.findByNameOrCreatorAndForkCount(FAKE_NAME, CREATOR_1, FORK_COUNT_2)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByNameOrCreatorAndForkCount(NAME_1, CREATOR_2, FORK_COUNT_2)); @@ -205,7 +205,7 @@ public void testFindByWithOrOr() { projects = TestUtils.toList(repository.findByNameOrCreatorOrForkCount(FAKE_NAME, FAKE_CREATOR, FAKE_COUNT)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); } @Test @@ -224,7 +224,7 @@ public void testFindByWithOrAndOr() { projects = TestUtils.toList(repository.findByNameOrCreatorAndForkCountOrStarCount(FAKE_NAME, CREATOR_1, FORK_COUNT_0, FAKE_COUNT)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); } @Test @@ -235,7 +235,7 @@ public void testFindByGreaterThan() { projects = TestUtils.toList(repository.findByForkCountGreaterThan(FAKE_COUNT)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); } @Test @@ -247,7 +247,7 @@ public void testFindByGreaterThanWithAndOr() { projects = TestUtils.toList(repository.findByCreatorAndForkCountGreaterThan(CREATOR_0, FORK_COUNT_1)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByCreatorOrForkCountGreaterThan(CREATOR_0, FORK_COUNT_2)); @@ -258,7 +258,7 @@ public void testFindByGreaterThanWithAndOr() { public void testFindByLessThan() { List projects = TestUtils.toList(repository.findByStarCountLessThan(STAR_COUNT_0)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByStarCountLessThan(STAR_COUNT_2)); @@ -269,7 +269,7 @@ public void testFindByLessThan() { public void testFindByLessThanEqual() { List projects = TestUtils.toList(repository.findByForkCountLessThanEqual(STAR_COUNT_MIN)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByForkCountLessThanEqual(STAR_COUNT_2)); @@ -281,7 +281,7 @@ public void testFindByLessThanAndGreaterThan() { List projects = TestUtils.toList(repository.findByStarCountLessThanAndForkCountGreaterThan(STAR_COUNT_0, FORK_COUNT_3)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByStarCountLessThanAndForkCountGreaterThan(STAR_COUNT_3, FORK_COUNT_0)); @@ -294,7 +294,7 @@ public void testFindByLessThanEqualsAndGreaterThanEquals() { List projects = TestUtils.toList(repository.findByForkCountLessThanEqualAndStarCountGreaterThan( STAR_COUNT_MIN, FORK_COUNT_0)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByForkCountLessThanEqualAndStarCountGreaterThan(STAR_COUNT_3, FORK_COUNT_0)); @@ -306,7 +306,7 @@ public void testFindByLessThanEqualsAndGreaterThanEquals() { public void testFindByGreaterThanEqual() { List projects = TestUtils.toList(repository.findByStarCountGreaterThanEqual(STAR_COUNT_MAX)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByStarCountGreaterThanEqual(STAR_COUNT_2)); @@ -318,7 +318,7 @@ public void testFindByGreaterThanEqualAnd() { List projects = TestUtils.toList(repository .findByForkCountGreaterThanEqualAndCreator(FORK_COUNT_MAX, CREATOR_2)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByForkCountGreaterThanEqualAndCreator(FORK_COUNT_0, CREATOR_0)); @@ -362,9 +362,9 @@ public void findByIdWithPartitionKey() { final Optional project = repository.findById(PROJECT_0.getId(), new PartitionKey(collectionManager.getEntityInformation(Project.class).getPartitionKeyFieldValue(PROJECT_0))); - Assert.assertTrue(project.isPresent()); + Assertions.assertTrue(project.isPresent()); - Assert.assertEquals(project.get(), PROJECT_0); + assertEquals(project.get(), PROJECT_0); } @Test @@ -372,7 +372,7 @@ public void findByIdWithPartitionKeyNotFound() { final Optional project = repository.findById("unknown-id", new PartitionKey("unknown-partition-key")); - Assert.assertFalse(project.isPresent()); + Assertions.assertFalse(project.isPresent()); } @@ -380,7 +380,7 @@ public void findByIdWithPartitionKeyNotFound() { public void testFindByIn() { List projects = TestUtils.toList(repository.findByCreatorIn(Collections.singleton(FAKE_CREATOR))); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByCreatorIn(Arrays.asList(CREATOR_1, CREATOR_2))); @@ -401,7 +401,7 @@ public void testFindByInWithAnd() { CREATOR_1), Arrays.asList(STAR_COUNT_2, STAR_COUNT_3))); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByCreatorInAndStarCountIn(Arrays.asList(CREATOR_0, CREATOR_1), Arrays.asList(STAR_COUNT_0, STAR_COUNT_2))); @@ -438,7 +438,7 @@ public void testFindByNotIn() { List projects = TestUtils.toList(repository.findByCreatorNotIn( Arrays.asList(CREATOR_0, CREATOR_1, CREATOR_2, CREATOR_3))); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByCreatorNotIn(Arrays.asList(CREATOR_1, CREATOR_2))); @@ -455,7 +455,7 @@ public void testFindByInWithNotIn() { TestUtils.toList(repository.findByCreatorInAndStarCountNotIn(Collections.singletonList(FAKE_CREATOR), Arrays.asList(STAR_COUNT_2, STAR_COUNT_3))); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); projects = TestUtils.toList(repository.findByCreatorInAndStarCountNotIn(Arrays.asList(CREATOR_0, CREATOR_1), Arrays.asList(STAR_COUNT_0, STAR_COUNT_2))); @@ -473,7 +473,7 @@ public void testFindByInWithNotIn() { public void testFindByNameIsNull() { List projects = TestUtils.toList(repository.findByNameIsNull()); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); final Project nullNameProject = new Project("id-999", null, CREATOR_0, true, STAR_COUNT_0, FORK_COUNT_0); @@ -495,14 +495,14 @@ public void testFindByNameIsNotNull() { projects = TestUtils.toList(repository.findByNameIsNotNull()); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); } @Test public void testFindByNameIsNullWithAnd() { List projects = TestUtils.toList(repository.findByNameIsNullAndForkCount(FORK_COUNT_MAX)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); final Project nullNameProject = new Project("id-999", null, CREATOR_0, true, STAR_COUNT_0, FORK_COUNT_0); @@ -523,7 +523,7 @@ public void testFindByNameIsNotNullWithAnd() { this.repository.save(new Project("id-999", null, CREATOR_0, true, STAR_COUNT_0, FORK_COUNT_0)); projects = TestUtils.toList(repository.findByNameIsNotNullAndHasReleased(true)); - Assert.assertTrue(projects.isEmpty()); + Assertions.assertTrue(projects.isEmpty()); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositorySortIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositorySortIT.java index 00c5a3a5e514..d4c5e14826af 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositorySortIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ProjectRepositorySortIT.java @@ -11,17 +11,15 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.SortedProjectRepository; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.Comparator; @@ -30,8 +28,9 @@ import java.util.stream.StreamSupport; import static com.azure.spring.data.cosmos.common.PageTestUtils.validateLastPage; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ProjectRepositorySortIT { @@ -79,7 +78,7 @@ public class ProjectRepositorySortIT { private static final List PROJECTS = Arrays.asList(PROJECT_4, PROJECT_3, PROJECT_2, PROJECT_1, PROJECT_0); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -88,7 +87,7 @@ public class ProjectRepositorySortIT { @Autowired private SortedProjectRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, SortedProject.class); this.repository.saveAll(PROJECTS); @@ -101,8 +100,8 @@ public void testFindAllSortASC() { PROJECTS.sort(Comparator.comparing(SortedProject::getStarCount)); - Assert.assertEquals(PROJECTS.size(), projects.size()); - Assert.assertEquals(PROJECTS, projects); + assertEquals(PROJECTS.size(), projects.size()); + assertEquals(PROJECTS, projects); } @Test @@ -112,8 +111,8 @@ public void testFindAllSortDESC() { PROJECTS.sort(Comparator.comparing(SortedProject::getCreator).reversed()); - Assert.assertEquals(PROJECTS.size(), projects.size()); - Assert.assertEquals(PROJECTS, projects); + assertEquals(PROJECTS.size(), projects.size()); + assertEquals(PROJECTS, projects); } @Test @@ -124,30 +123,36 @@ public void testFindAllUnSorted() { PROJECTS.sort(Comparator.comparing(SortedProject::getId)); projects.sort(Comparator.comparing(SortedProject::getId)); - Assert.assertEquals(PROJECTS.size(), projects.size()); - Assert.assertEquals(PROJECTS, projects); + assertEquals(PROJECTS.size(), projects.size()); + assertEquals(PROJECTS, projects); } - @Test(expected = CosmosBadRequestException.class) + @Test public void testFindAllSortMoreThanOneOrderException() { - final Sort sort = Sort.by(Sort.Direction.ASC, "name", "creator"); + assertThrows(CosmosBadRequestException.class, () -> { + final Sort sort = Sort.by(Sort.Direction.ASC, "name", "creator"); - this.repository.findAll(sort).iterator().next(); + this.repository.findAll(sort).iterator().next(); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testFindAllSortIgnoreCaseException() { - final Sort.Order order = Sort.Order.by("name").ignoreCase(); - final Sort sort = Sort.by(order); + assertThrows(IllegalArgumentException.class, () -> { + final Sort.Order order = Sort.Order.by("name").ignoreCase(); + final Sort sort = Sort.by(order); - this.repository.findAll(sort); + this.repository.findAll(sort); + }); } - @Test(expected = CosmosAccessException.class) + @Test public void testFindAllSortMissMatchException() { - final Sort sort = Sort.by(Sort.Direction.ASC, "fake-name"); + assertThrows(CosmosAccessException.class, () -> { + final Sort sort = Sort.by(Sort.Direction.ASC, "fake-name"); - this.repository.findAll(sort).iterator().next(); + this.repository.findAll(sort).iterator().next(); + }); } public void testFindAllSortWithIdName() { @@ -159,7 +164,7 @@ public void testFindAllSortWithIdName() { false) .collect(Collectors.toList()); - Assert.assertEquals(projectListSortedById, results); + assertEquals(projectListSortedById, results); } @Test @@ -171,8 +176,8 @@ public void testFindSortWithOr() { references.sort(Comparator.comparing(SortedProject::getStarCount)); - Assert.assertEquals(references.size(), projects.size()); - Assert.assertEquals(references, projects); + assertEquals(references.size(), projects.size()); + assertEquals(references, projects); } @Test @@ -184,8 +189,8 @@ public void testFindSortWithAnd() { references.sort(Comparator.comparing(SortedProject::getStarCount)); - Assert.assertEquals(references.size(), projects.size()); - Assert.assertEquals(references, projects); + assertEquals(references.size(), projects.size()); + assertEquals(references, projects); } @Test @@ -196,8 +201,8 @@ public void testFindSortWithEqual() { references.sort(Comparator.comparing(SortedProject::getName).reversed()); - Assert.assertEquals(references.size(), projects.size()); - Assert.assertEquals(references, projects); + assertEquals(references.size(), projects.size()); + assertEquals(references, projects); } @Test @@ -210,8 +215,8 @@ public void testFindAllWithPageableAndSort() { final List references = Arrays.asList(PROJECT_0, PROJECT_1, PROJECT_2, PROJECT_3, PROJECT_4); references.sort(Comparator.comparing(SortedProject::getName).reversed()); - Assert.assertEquals(references.size(), result.getContent().size()); - Assert.assertEquals(references, result.getContent()); + assertEquals(references.size(), result.getContent().size()); + assertEquals(references, result.getContent()); validateLastPage(result, 5); } @@ -226,8 +231,8 @@ public void testFindWithPageableAndSort() { references.sort(Comparator.comparing(SortedProject::getName).reversed()); - Assert.assertEquals(references.size(), result.getContent().size()); - Assert.assertEquals(references, result.getContent()); + assertEquals(references.size(), result.getContent().size()); + assertEquals(references, result.getContent()); validateLastPage(result, 5); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/QuestionRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/QuestionRepositoryIT.java index 36c4e6005318..b3516600469f 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/QuestionRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/QuestionRepositoryIT.java @@ -9,22 +9,22 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.QuestionRepository; import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Collections; import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class QuestionRepositoryIT { @@ -36,7 +36,7 @@ public class QuestionRepositoryIT { private static final Question QUESTION = new Question(QUESTION_ID, QUESTION_URL); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -48,7 +48,7 @@ public class QuestionRepositoryIT { @Autowired private ResponseDiagnosticsTestUtils responseDiagnosticsTestUtils; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Question.class); this.repository.save(QUESTION); @@ -58,34 +58,34 @@ public void setUp() { public void testFindById() { final Optional optional = this.repository.findById(QUESTION_ID); assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNull(); - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(QUESTION, optional.get()); + Assertions.assertTrue(optional.isPresent()); + assertEquals(QUESTION, optional.get()); } @Test public void testFindByIdNull() { final Optional byId = this.repository.findById(NULL_ID); - Assert.assertFalse(byId.isPresent()); + Assertions.assertFalse(byId.isPresent()); } @Test public void testFindAll() { final List questions = Lists.newArrayList(this.repository.findAll()); - Assert.assertEquals(Collections.singletonList(QUESTION), questions); + assertEquals(Collections.singletonList(QUESTION), questions); } @Test public void testDelete() { Optional optional = this.repository.findById(QUESTION_ID); - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(QUESTION, optional.get()); + Assertions.assertTrue(optional.isPresent()); + assertEquals(QUESTION, optional.get()); this.repository.delete(QUESTION); optional = this.repository.findById(QUESTION_ID); - Assert.assertFalse(optional.isPresent()); + Assertions.assertFalse(optional.isPresent()); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveAuditableIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveAuditableIT.java index 4f3890d341cc..18843d56a619 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveAuditableIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveAuditableIT.java @@ -12,13 +12,12 @@ import com.azure.spring.data.cosmos.repository.repository.ReactiveAuditableIdGeneratedRepository; import com.azure.spring.data.cosmos.repository.repository.ReactiveAuditableRepository; import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -30,11 +29,11 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveAuditableIT { - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -48,7 +47,7 @@ public class ReactiveAuditableIT { @Autowired private StubAuditorProvider stubAuditorProvider; - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, AuditableEntity.class, AuditableIdGeneratedEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryIT.java index 276d5423a7a7..6a980e9de356 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryIT.java @@ -19,16 +19,13 @@ import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -40,8 +37,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveCourseRepositoryIT { @@ -68,7 +66,7 @@ public class ReactiveCourseRepositoryIT { private static final Course COURSE_4 = new Course(COURSE_ID_4, COURSE_NAME_4, DEPARTMENT_NAME_1); private static final Course COURSE_5 = new Course(COURSE_ID_5, COURSE_NAME_5, DEPARTMENT_NAME_1); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -99,7 +97,7 @@ public class ReactiveCourseRepositoryIT { private static final CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions(); - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Course.class); entityInformation = collectionManager.getEntityInformation(Course.class); @@ -322,7 +320,7 @@ public void testFindByNameAndDepartmentOrNameAndDepartment() { courseResultSet.add(COURSE_1); courseResultSet.add(COURSE_2); StepVerifier.create(findResult).expectNextCount(2).thenConsumeWhile(value -> { - Assertions.assertThat(courseResultSet.contains(value)).isTrue(); + assertThat(courseResultSet.contains(value)).isTrue(); return true; }).verifyComplete(); } @@ -338,9 +336,9 @@ public void testFindByNameOrDepartmentAllIgnoreCase() { public void testFindByNameJsonNode() { final Flux findResult = repository.annotatedFindByName(COURSE_NAME_1); StepVerifier.create(findResult).consumeNextWith(result -> { - Assert.assertEquals(result.findValue("courseId").asText(), COURSE_1.getCourseId()); - Assert.assertEquals(result.findValue("name").asText(), COURSE_1.getName()); - Assert.assertEquals(result.findValue("department").asText(), COURSE_1.getDepartment()); + assertEquals(result.findValue("courseId").asText(), COURSE_1.getCourseId()); + assertEquals(result.findValue("name").asText(), COURSE_1.getName()); + assertEquals(result.findValue("department").asText(), COURSE_1.getDepartment()); }).verifyComplete(); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryNoMetricsIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryNoMetricsIT.java index 50670aa0fc2b..3212abdcc440 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryNoMetricsIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveCourseRepositoryNoMetricsIT.java @@ -10,13 +10,12 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryNoMetricsConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveCourseRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -24,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryNoMetricsConfig.class) public class ReactiveCourseRepositoryNoMetricsIT { @@ -40,7 +39,7 @@ public class ReactiveCourseRepositoryNoMetricsIT { private static final Course COURSE_1 = new Course(COURSE_ID_1, COURSE_NAME_1, DEPARTMENT_NAME_1); private static final Course COURSE_2 = new Course(COURSE_ID_2, COURSE_NAME_2, DEPARTMENT_NAME_2); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -57,7 +56,7 @@ public class ReactiveCourseRepositoryNoMetricsIT { private CosmosEntityInformation entityInformation; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Course.class); entityInformation = collectionManager.getEntityInformation(Course.class); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveEtagIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveEtagIT.java index 098071c630d7..a72042bce9e1 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveEtagIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveEtagIT.java @@ -8,14 +8,13 @@ import com.azure.spring.data.cosmos.exception.CosmosPreconditionFailedException; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveCourseWithEtagRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -27,12 +26,13 @@ import static com.azure.spring.data.cosmos.common.TestConstants.COURSE_NAME; import static com.azure.spring.data.cosmos.common.TestConstants.DEPARTMENT; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveEtagIT { - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -40,7 +40,7 @@ public class ReactiveEtagIT { @Autowired ReactiveCourseWithEtagRepository reactiveCourseWithEtagRepository; - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, CourseWithEtag.class); } @@ -54,23 +54,23 @@ public void testCrudOperationsShouldApplyEtag() { final Mono insertedCourseWithEtagMono = reactiveCourseWithEtagRepository.save(createCourseWithEtag()); CourseWithEtag insertedCourseWithEtag = insertedCourseWithEtagMono.block(); - Assert.assertNotNull(insertedCourseWithEtag); - Assert.assertNotNull(insertedCourseWithEtag.getEtag()); + Assertions.assertNotNull(insertedCourseWithEtag); + Assertions.assertNotNull(insertedCourseWithEtag.getEtag()); insertedCourseWithEtag.setName("CHANGED"); final Mono updatedCourseWithEtagMono = reactiveCourseWithEtagRepository.save(insertedCourseWithEtag); CourseWithEtag updatedCourseWithEtag = updatedCourseWithEtagMono.block(); - Assert.assertNotNull(updatedCourseWithEtag); - Assert.assertNotNull(updatedCourseWithEtag.getEtag()); - Assert.assertNotEquals(updatedCourseWithEtag.getEtag(), insertedCourseWithEtag.getEtag()); + Assertions.assertNotNull(updatedCourseWithEtag); + Assertions.assertNotNull(updatedCourseWithEtag.getEtag()); + Assertions.assertNotEquals(updatedCourseWithEtag.getEtag(), insertedCourseWithEtag.getEtag()); final Mono foundCourseWithEtagMono = reactiveCourseWithEtagRepository.findById(insertedCourseWithEtag.getCourseId()); CourseWithEtag foundCourseWithEtag = foundCourseWithEtagMono.block(); - Assert.assertNotNull(foundCourseWithEtag); - Assert.assertNotNull(foundCourseWithEtag.getEtag()); - Assert.assertEquals(foundCourseWithEtag.getEtag(), updatedCourseWithEtag.getEtag()); + Assertions.assertNotNull(foundCourseWithEtag); + Assertions.assertNotNull(foundCourseWithEtag.getEtag()); + assertEquals(foundCourseWithEtag.getEtag(), updatedCourseWithEtag.getEtag()); } @Test @@ -82,15 +82,15 @@ public void testCrudListOperationsShouldApplyEtag() { final Flux insertedCourseWithEtagsFlux = reactiveCourseWithEtagRepository.saveAll(courses); List insertedCourseWithEtags = insertedCourseWithEtagsFlux.collectList().block(); - Assert.assertNotNull(insertedCourseWithEtags); - insertedCourseWithEtags.forEach(course -> Assert.assertNotNull(course.getEtag())); + Assertions.assertNotNull(insertedCourseWithEtags); + insertedCourseWithEtags.forEach(course -> Assertions.assertNotNull(course.getEtag())); insertedCourseWithEtags.forEach(course -> course.setName("CHANGED")); final Flux updatedCourseWithEtagsFlux = reactiveCourseWithEtagRepository.saveAll(insertedCourseWithEtags); List updatedCourseWithEtags = updatedCourseWithEtagsFlux.collectList().block(); - Assert.assertNotNull(updatedCourseWithEtags); + Assertions.assertNotNull(updatedCourseWithEtags); insertedCourseWithEtags.sort(Comparator.comparing(CourseWithEtag::getCourseId)); updatedCourseWithEtags.sort(Comparator.comparing(CourseWithEtag::getCourseId)); @@ -98,9 +98,9 @@ public void testCrudListOperationsShouldApplyEtag() { for (int i = 0; i < updatedCourseWithEtags.size(); i++) { CourseWithEtag insertedCourseWithEtag = insertedCourseWithEtags.get(i); CourseWithEtag updatedCourseWithEtag = updatedCourseWithEtags.get(i); - Assert.assertEquals(insertedCourseWithEtag.getCourseId(), updatedCourseWithEtag.getCourseId()); - Assert.assertNotNull(updatedCourseWithEtag.getEtag()); - Assert.assertNotEquals(insertedCourseWithEtag.getEtag(), updatedCourseWithEtag.getEtag()); + assertEquals(insertedCourseWithEtag.getCourseId(), updatedCourseWithEtag.getCourseId()); + Assertions.assertNotNull(updatedCourseWithEtag.getEtag()); + Assertions.assertNotEquals(insertedCourseWithEtag.getEtag(), updatedCourseWithEtag.getEtag()); } } @@ -108,12 +108,12 @@ public void testCrudListOperationsShouldApplyEtag() { public void testShouldFailIfEtagDoesNotMatch() { Mono insertedCourseWithEtagMono = reactiveCourseWithEtagRepository.save(createCourseWithEtag()); CourseWithEtag insertedCourseWithEtag = insertedCourseWithEtagMono.block(); - Assert.assertNotNull(insertedCourseWithEtag); + Assertions.assertNotNull(insertedCourseWithEtag); insertedCourseWithEtag.setName("CHANGED"); Mono updatedCourseWithEtagMono = reactiveCourseWithEtagRepository.save(insertedCourseWithEtag); CourseWithEtag updatedCourseWithEtag = updatedCourseWithEtagMono.block(); - Assert.assertNotNull(updatedCourseWithEtag); + Assertions.assertNotNull(updatedCourseWithEtag); updatedCourseWithEtag.setEtag(insertedCourseWithEtag.getEtag()); @@ -128,23 +128,23 @@ public void testShouldFailIfEtagDoesNotMatch() { public void testBulkShouldFailIfEtagDoesNotMatch() { Flux insertedCourseWithEtagFlux = reactiveCourseWithEtagRepository.saveAll(Flux.just(createCourseWithEtag())); List insertedCourseWithEtag = insertedCourseWithEtagFlux.collectList().block(); - Assert.assertEquals(insertedCourseWithEtag.size(), 1); + assertEquals(insertedCourseWithEtag.size(), 1); insertedCourseWithEtag.get(0).setName("CHANGED"); Flux updatedCourseWithEtagFlux = reactiveCourseWithEtagRepository.saveAll(insertedCourseWithEtag); List updatedCourseWithEtag = updatedCourseWithEtagFlux.collectList().block(); - Assert.assertEquals(updatedCourseWithEtag.size(), 1); + assertEquals(updatedCourseWithEtag.size(), 1); updatedCourseWithEtag.get(0).setEtag(insertedCourseWithEtag.get(0).getEtag()); Flux courseFlux = reactiveCourseWithEtagRepository.saveAll(updatedCourseWithEtag); StepVerifier.create(courseFlux); - Assert.assertEquals(courseFlux.collectList().block().size(), 0); + assertEquals(courseFlux.collectList().block().size(), 0); reactiveCourseWithEtagRepository.deleteAll(updatedCourseWithEtag); Flux courseFlux2 = reactiveCourseWithEtagRepository.findAll(); StepVerifier.create(courseFlux2); - Assert.assertEquals(courseFlux2.collectList().block().size(), 1); + assertEquals(courseFlux2.collectList().block().size(), 1); } } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveHierarchicalPartitionKeyRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveHierarchicalPartitionKeyRepositoryIT.java index 1a2ce6c59280..c2445f7a4e15 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveHierarchicalPartitionKeyRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveHierarchicalPartitionKeyRepositoryIT.java @@ -10,15 +10,14 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveHierarchicalPartitionKeyRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -26,9 +25,9 @@ import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveHierarchicalPartitionKeyRepositoryIT { @@ -38,7 +37,7 @@ public class ReactiveHierarchicalPartitionKeyRepositoryIT { private static final HierarchicalPartitionKeyEntity HIERARCHICAL_ENTITY_2 = new HierarchicalPartitionKeyEntity("id_2", "Michael", "Smith", "23456"); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); private static CosmosEntityInformation hierarchicalPartitionKeyEntityInformation @@ -50,15 +49,15 @@ public class ReactiveHierarchicalPartitionKeyRepositoryIT { @Autowired ReactiveHierarchicalPartitionKeyRepository repository; - @BeforeClass + @BeforeAll public static void init() { } - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(reactiveTemplate, HierarchicalPartitionKeyEntity.class); } - @AfterClass + @AfterAll public static void cleanUp() { collectionManager.deleteContainer(hierarchicalPartitionKeyEntityInformation); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveIndexPolicyUpdateIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveIndexPolicyUpdateIT.java index c40a9d9304d3..bcd15dfa3f0b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveIndexPolicyUpdateIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveIndexPolicyUpdateIT.java @@ -16,25 +16,24 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleReactiveCosmosRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveIndexPolicyUpdateIT { - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -51,7 +50,7 @@ public class ReactiveIndexPolicyUpdateIT { CosmosEntityInformation addressEntityInformation = new CosmosEntityInformation<>(Address.class); - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, IndexPolicyEntity.class, ComplexIndexPolicyEntity.class, IndexPolicyOverwriteEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java index c5bef428dbac..e6fe821d1ef0 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveLongIdDomainPartitionPartitionRepositoryIT.java @@ -10,14 +10,13 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveLongIdDomainPartitionRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -25,7 +24,9 @@ import java.util.Arrays; import java.util.Objects; -@RunWith(SpringJUnit4ClassRunner.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveLongIdDomainPartitionPartitionRepositoryIT { @@ -41,7 +42,7 @@ public class ReactiveLongIdDomainPartitionPartitionRepositoryIT { private static final LongIdDomainPartition DOMAIN_2 = new LongIdDomainPartition(ID_2, NAME_2); private static final LongIdDomainPartition DOMAIN_3 = new LongIdDomainPartition(ID_3, NAME_1); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -52,7 +53,7 @@ public class ReactiveLongIdDomainPartitionPartitionRepositoryIT { private CosmosEntityInformation entityInformation; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, LongIdDomainPartition.class); entityInformation = collectionManager.getEntityInformation(LongIdDomainPartition.class); @@ -84,9 +85,10 @@ public void testLongIdDomainPartition() { StepVerifier.create(afterDelIdMono).expectNextCount(0).verifyComplete(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidDomain() { - new CosmosEntityInformation(InvalidDomain.class); + assertThrows(IllegalArgumentException.class, () -> + new CosmosEntityInformation(InvalidDomain.class)); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveNestedPartitionKeyRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveNestedPartitionKeyRepositoryIT.java index 09e676d1b0fa..1c34677beb82 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveNestedPartitionKeyRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveNestedPartitionKeyRepositoryIT.java @@ -9,14 +9,13 @@ import com.azure.spring.data.cosmos.domain.NestedPartitionKeyEntity; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveNestedPartitionKeyRepository; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -27,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveNestedPartitionKeyRepositoryIT { @@ -37,7 +36,7 @@ public class ReactiveNestedPartitionKeyRepositoryIT { private static final NestedPartitionKeyEntity NESTED_ENTITY_2 = new NestedPartitionKeyEntity(null, new NestedEntity("partitionKey2")); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -46,10 +45,10 @@ public class ReactiveNestedPartitionKeyRepositoryIT { @Autowired ReactiveNestedPartitionKeyRepository repository; - @BeforeClass + @BeforeAll public static void init() { } - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, NestedPartitionKeyEntity.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveRoleRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveRoleRepositoryIT.java index add0b943acd4..af4364dfeefb 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveRoleRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveRoleRepositoryIT.java @@ -8,14 +8,13 @@ import com.azure.spring.data.cosmos.domain.Role; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveRoleRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -25,7 +24,7 @@ import java.util.List; import java.util.Optional; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveRoleRepositoryIT { @@ -41,7 +40,7 @@ public class ReactiveRoleRepositoryIT { private static final Role TEST_ROLE_5 = new Role(TestConstants.ID_5, true, TestConstants.ROLE_NAME_2, TestConstants.LEVEL_2); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -49,7 +48,7 @@ public class ReactiveRoleRepositoryIT { @Autowired private ReactiveRoleRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Role.class); final Flux savedFlux = repository.saveAll(Arrays.asList(TEST_ROLE_1, TEST_ROLE_2, TEST_ROLE_3, TEST_ROLE_4)); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveTeacherRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveTeacherRepositoryIT.java index f9cd828a8aff..b6b9e2bc3a18 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveTeacherRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/ReactiveTeacherRepositoryIT.java @@ -8,14 +8,13 @@ import com.azure.spring.data.cosmos.domain.ReactiveTeacher; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.ReactiveTeacherRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -24,7 +23,7 @@ import java.util.Arrays; import java.util.List; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class ReactiveTeacherRepositoryIT { @@ -48,7 +47,7 @@ public class ReactiveTeacherRepositoryIT { private static final ReactiveTeacher TEACHER_3 = new ReactiveTeacher(TEACHER_ID_3, TEACHER_FIRST_NAME_2, DEPARTMENT_LAST_NAME_1); - @ClassRule + public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); @Autowired @@ -57,7 +56,7 @@ public class ReactiveTeacherRepositoryIT { @Autowired private ReactiveTeacherRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, ReactiveTeacher.class); final Flux savedFlux = repository.saveAll(Arrays.asList(TEACHER_1)); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SpELCosmosAnnotationIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SpELCosmosAnnotationIT.java index 9505ca395342..0e02f5118d3b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SpELCosmosAnnotationIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SpELCosmosAnnotationIT.java @@ -9,22 +9,21 @@ import com.azure.spring.data.cosmos.domain.SpELPropertyStudent; import com.azure.spring.data.cosmos.repository.TestRepositorySpELConfig; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositorySpELConfig.class) public class SpELCosmosAnnotationIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static final SpELPropertyStudent TEST_PROPERTY_STUDENT = new SpELPropertyStudent(TestConstants.ID_1, @@ -33,7 +32,7 @@ public class SpELCosmosAnnotationIT { @Autowired private CosmosTemplate cosmosTemplate; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(cosmosTemplate, SpELPropertyStudent.class); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SquareRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SquareRepositoryIT.java index f4cf427b14b9..fe43f90246df 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SquareRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/SquareRepositoryIT.java @@ -8,26 +8,25 @@ import com.azure.spring.data.cosmos.domain.inheritance.Square; import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.SquareRepository; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class SquareRepositoryIT { private Square square1 = new Square("id_1", 1, 1); private Square square2 = new Square("id_2", 2, 4); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -36,7 +35,7 @@ public class SquareRepositoryIT { @Autowired private SquareRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Square.class); repository.save(square1); diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/StudentRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/StudentRepositoryIT.java index f0c714da7a29..4c2dfa21c0b1 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/StudentRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/StudentRepositoryIT.java @@ -9,24 +9,23 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.StudentRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class StudentRepositoryIT { public static final String ID_0 = "id-0"; @@ -59,7 +58,7 @@ public class StudentRepositoryIT { private static final List PEOPLE = Arrays.asList(STUDENT_0, STUDENT_1, STUDENT_2, STUDENT_3, STUDENT_4, STUDENT_5); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -68,13 +67,13 @@ public class StudentRepositoryIT { @Autowired private StudentRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Student.class); this.repository.saveAll(PEOPLE); } - @AfterClass + @AfterAll public static void teardown() { collectionManager.deleteContainer(new CosmosEntityInformation<>(Student.class)); } @@ -156,7 +155,7 @@ private void assertPeopleEquals(List people, List reference) { people.sort(Comparator.comparing(Student::getId)); reference.sort(Comparator.comparing(Student::getId)); - Assert.assertEquals(reference, people); + assertEquals(reference, people); } @Test diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/TeacherRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/TeacherRepositoryIT.java index 7dfbdd764de8..ccff01a0f465 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/TeacherRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/TeacherRepositoryIT.java @@ -9,24 +9,23 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.TeacherRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Optional; -import static org.junit.Assert.assertFalse; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class TeacherRepositoryIT { public static final String ID_0 = "id-0"; @@ -37,7 +36,7 @@ public class TeacherRepositoryIT { private static final Teacher TEACHER_0 = new Teacher(ID_0, FIRST_NAME_0, LAST_NAME_0); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -46,13 +45,13 @@ public class TeacherRepositoryIT { @Autowired private TeacherRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, Teacher.class); this.repository.save(TEACHER_0); } - @After + @AfterEach public void teardown() { collectionManager.deleteContainer(new CosmosEntityInformation<>(Teacher.class)); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UUIDIdDomainRepositoryIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UUIDIdDomainRepositoryIT.java index 89cc50b85d40..e61ac65bf20b 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UUIDIdDomainRepositoryIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UUIDIdDomainRepositoryIT.java @@ -10,14 +10,13 @@ import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; import com.azure.spring.data.cosmos.repository.repository.UUIDIdDomainRepository; import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.ArrayList; import java.util.Arrays; @@ -31,8 +30,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class UUIDIdDomainRepositoryIT { @@ -45,7 +45,7 @@ public class UUIDIdDomainRepositoryIT { private static final UUIDIdDomain DOMAIN_1 = new UUIDIdDomain(ID_1, NAME_1); private static final UUIDIdDomain DOMAIN_2 = new UUIDIdDomain(ID_2, NAME_2); - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); @Autowired @@ -54,7 +54,7 @@ public class UUIDIdDomainRepositoryIT { @Autowired private UUIDIdDomainRepository repository; - @Before + @BeforeEach public void setUp() { collectionManager.ensureContainersCreatedAndEmpty(template, UUIDIdDomain.class); this.repository.save(DOMAIN_1); @@ -64,43 +64,45 @@ public void setUp() { @Test public void testUUIDIdDomain() { this.repository.deleteAll(); - Assert.assertFalse(this.repository.findById(ID_1).isPresent()); + Assertions.assertFalse(this.repository.findById(ID_1).isPresent()); this.repository.save(DOMAIN_1); final Optional foundOptional = this.repository.findById(ID_1); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(DOMAIN_1.getNumber(), foundOptional.get().getNumber()); - Assert.assertEquals(DOMAIN_1.getName(), foundOptional.get().getName()); + Assertions.assertTrue(foundOptional.isPresent()); + assertEquals(DOMAIN_1.getNumber(), foundOptional.get().getNumber()); + assertEquals(DOMAIN_1.getName(), foundOptional.get().getName()); this.repository.delete(DOMAIN_1); - Assert.assertFalse(this.repository.findById(ID_1).isPresent()); + Assertions.assertFalse(this.repository.findById(ID_1).isPresent()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidDomain() { - new CosmosEntityInformation(InvalidDomain.class); + assertThrows(IllegalArgumentException.class, () -> + new CosmosEntityInformation(InvalidDomain.class)); + } @Test public void testBasicQuery() { final UUIDIdDomain save = this.repository.save(DOMAIN_1); - Assert.assertNotNull(save); + Assertions.assertNotNull(save); } @Test public void testSaveAndFindById() { - Assert.assertNotNull(this.repository.save(DOMAIN_1)); + Assertions.assertNotNull(this.repository.save(DOMAIN_1)); final Optional savedEntity = this.repository.findById(DOMAIN_1.getNumber()); - Assert.assertTrue(savedEntity.isPresent()); - Assert.assertEquals(DOMAIN_1, savedEntity.get()); + Assertions.assertTrue(savedEntity.isPresent()); + assertEquals(DOMAIN_1, savedEntity.get()); } @Test public void testSaveAllAndFindAll() { - Assert.assertTrue(this.repository.findAll().iterator().hasNext()); + Assertions.assertTrue(this.repository.findAll().iterator().hasNext()); final Set entitiesToSave = Stream.of(DOMAIN_1, DOMAIN_2).collect(Collectors.toSet()); this.repository.saveAll(entitiesToSave); @@ -108,14 +110,14 @@ public void testSaveAllAndFindAll() { final Set savedEntities = StreamSupport.stream(this.repository.findAll().spliterator(), false) .collect(Collectors.toSet()); - Assert.assertTrue(entitiesToSave.containsAll(savedEntities)); + Assertions.assertTrue(entitiesToSave.containsAll(savedEntities)); } @Test public void testFindAllById() { final Iterable allById = TestUtils.toList(this.repository.findAllById(Arrays.asList(DOMAIN_1.getNumber(), DOMAIN_2.getNumber()))); - Assert.assertTrue(((ArrayList) allById).size() == 2); + Assertions.assertTrue(((ArrayList) allById).size() == 2); Iterator it = allById.iterator(); assertUUIDIdDomainEquals(Arrays.asList(it.next(), it.next()), Arrays.asList(DOMAIN_1, DOMAIN_2)); } @@ -123,12 +125,12 @@ public void testFindAllById() { private void assertUUIDIdDomainEquals(List cur, List reference) { cur.sort(Comparator.comparing(UUIDIdDomain::getNumber)); reference.sort(Comparator.comparing(UUIDIdDomain::getNumber)); - Assert.assertEquals(reference, cur); + assertEquals(reference, cur); } @Test public void testCount() { - Assert.assertEquals(2, repository.count()); + assertEquals(2, repository.count()); } @Test @@ -137,26 +139,30 @@ public void testDeleteById() { this.repository.save(DOMAIN_2); this.repository.deleteById(DOMAIN_1.getNumber()); this.repository.deleteById(DOMAIN_2.getNumber()); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteByIdShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.deleteById(DOMAIN_1.getNumber()); + assertThrows(CosmosNotFoundException.class, () -> { + this.repository.deleteAll(); + this.repository.deleteById(DOMAIN_1.getNumber()); + }); } @Test public void testDelete() { this.repository.save(DOMAIN_1); this.repository.delete(DOMAIN_1); - Assert.assertEquals(1, this.repository.count()); + assertEquals(1, this.repository.count()); } - @Test(expected = CosmosNotFoundException.class) + @Test public void testDeleteShouldFailIfNothingToDelete() { - this.repository.deleteAll(); - this.repository.delete(DOMAIN_1); + assertThrows(CosmosNotFoundException.class, () -> { + this.repository.deleteAll(); + this.repository.delete(DOMAIN_1); + }); } @Test @@ -164,13 +170,13 @@ public void testDeleteAll() { this.repository.save(DOMAIN_1); this.repository.save(DOMAIN_2); this.repository.deleteAll(Arrays.asList(DOMAIN_1, DOMAIN_2)); - Assert.assertEquals(0, this.repository.count()); + assertEquals(0, this.repository.count()); } @Test public void testExistsById() { this.repository.save(DOMAIN_1); - Assert.assertTrue(this.repository.existsById(DOMAIN_1.getNumber())); + Assertions.assertTrue(this.repository.existsById(DOMAIN_1.getNumber())); } private static class InvalidDomain { diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UniqueKeyPolicyIT.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UniqueKeyPolicyIT.java index 728ee227e207..0d7e9314d18d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UniqueKeyPolicyIT.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/UniqueKeyPolicyIT.java @@ -19,14 +19,13 @@ import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; import com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository; import com.azure.spring.data.cosmos.repository.support.SimpleReactiveCosmosRepository; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Arrays; import java.util.List; @@ -34,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestRepositoryConfig.class) public class UniqueKeyPolicyIT { - @ClassRule + public static final IntegrationTestCollectionManager collectionManager = new IntegrationTestCollectionManager(); private static final UniqueKeyPolicyEntity ENTITY_1 = new UniqueKeyPolicyEntity("id-1", "firstName-1", "lastName" @@ -64,13 +63,13 @@ public class UniqueKeyPolicyIT { private static CosmosEntityInformation information = new CosmosEntityInformation<>(UniqueKeyPolicyEntity.class); - @Before + @BeforeEach public void setup() { collectionManager.ensureContainersCreatedAndEmpty(template, CompositeIndexEntity.class); repository.saveAll(Arrays.asList(ENTITY_1, ENTITY_2, ENTITY_3, ENTITY_4, ENTITY_5)); } - @AfterClass + @AfterAll public static void teardown() { collectionManager.deleteContainer(information); } diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractCosmosQueryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractCosmosQueryUnitTest.java index 33002512f898..4ec575c3c086 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractCosmosQueryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractCosmosQueryUnitTest.java @@ -5,15 +5,15 @@ import com.azure.spring.data.cosmos.core.CosmosOperations; import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; import com.azure.spring.data.cosmos.core.query.CosmosQuery; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.util.Assert; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AbstractCosmosQueryUnitTest { @Mock diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractReactiveCosmosQueryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractReactiveCosmosQueryUnitTest.java index f64a20601134..b41dfcefd1c9 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractReactiveCosmosQueryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/query/AbstractReactiveCosmosQueryUnitTest.java @@ -4,16 +4,16 @@ import com.azure.spring.data.cosmos.core.ReactiveCosmosOperations; import com.azure.spring.data.cosmos.core.query.CosmosQuery; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.springframework.util.Assert; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AbstractReactiveCosmosQueryUnitTest { @Mock diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosEntityInformationUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosEntityInformationUnitTest.java index 555a2383ab22..26600cd8e61d 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosEntityInformationUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosEntityInformationUnitTest.java @@ -10,7 +10,7 @@ import com.azure.spring.data.cosmos.domain.Person; import com.azure.spring.data.cosmos.domain.Student; import com.azure.spring.data.cosmos.domain.UUIDIdDomain; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Version; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryBeanUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryBeanUnitTest.java index 01d75b321d39..b64a27070728 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryBeanUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryBeanUnitTest.java @@ -4,15 +4,15 @@ import com.azure.spring.data.cosmos.core.CosmosTemplate; import com.azure.spring.data.cosmos.repository.repository.PersonRepository; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.repository.core.support.RepositoryFactorySupport; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CosmosRepositoryFactoryBeanUnitTest { @Mock diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryUnitTest.java index 4b58b716e4df..68175a6338e9 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/CosmosRepositoryFactoryUnitTest.java @@ -4,15 +4,15 @@ import com.azure.spring.data.cosmos.core.CosmosTemplate; import com.azure.spring.data.cosmos.domain.Person; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.repository.core.EntityInformation; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CosmosRepositoryFactoryUnitTest { @Mock diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQueryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQueryUnitTest.java index 84e09b749ccc..081296b18a7e 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQueryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedCosmosQueryUnitTest.java @@ -4,17 +4,17 @@ import com.azure.spring.data.cosmos.core.CosmosOperations; import com.azure.spring.data.cosmos.repository.query.CosmosQueryMethod; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class StringBasedCosmosQueryUnitTest { @Mock CosmosQueryMethod cosmosQueryMethod; diff --git a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQueryUnitTest.java b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQueryUnitTest.java index 1ef3ca08d498..4627fac171ef 100644 --- a/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQueryUnitTest.java +++ b/sdk/spring/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/support/StringBasedReactiveCosmosQueryUnitTest.java @@ -4,17 +4,17 @@ import com.azure.spring.data.cosmos.core.ReactiveCosmosOperations; import com.azure.spring.data.cosmos.repository.query.ReactiveCosmosQueryMethod; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class StringBasedReactiveCosmosQueryUnitTest { @Mock ReactiveCosmosQueryMethod reactiveCosmosQueryMethod;