DATAES-619 - Migrate remaining tests to AssertJ.

This commit is contained in:
Mark Paluch 2019-07-29 15:48:09 +02:00
parent e23f6f1d33
commit 2c4ca358f3
5 changed files with 25 additions and 22 deletions

View File

@ -15,7 +15,7 @@
*/ */
package org.springframework.data.elasticsearch.config.nested; package org.springframework.data.elasticsearch.config.nested;
import static org.junit.Assert.*; import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.elasticsearch.annotations.FieldType.*; import static org.springframework.data.elasticsearch.annotations.FieldType.*;
import lombok.Builder; import lombok.Builder;
@ -70,7 +70,7 @@ public class EnableNestedElasticsearchRepositoriesTests {
@Test @Test
public void hasNestedRepository() { public void hasNestedRepository() {
assertNotNull(nestedRepository); assertThat(nestedRepository).isNotNull();
} }
@Data @Data

View File

@ -15,7 +15,7 @@
*/ */
package org.springframework.data.elasticsearch.core.aggregation; package org.springframework.data.elasticsearch.core.aggregation;
import static org.junit.Assert.*; import static org.assertj.core.api.Assertions.*;
import java.util.Arrays; import java.util.Arrays;
@ -34,9 +34,9 @@ public class AggregatedPageImplTest {
public void constructFacetedPageWithPageable() { public void constructFacetedPageWithPageable() {
Page<String> page = new AggregatedPageImpl<>(Arrays.asList("Test", "Test 2"), PageRequest.of(0, 2), 10); Page<String> page = new AggregatedPageImpl<>(Arrays.asList("Test", "Test 2"), PageRequest.of(0, 2), 10);
assertEquals(10, page.getTotalElements()); assertThat(page.getTotalElements()).isEqualTo(10);
assertEquals(2, page.getNumberOfElements()); assertThat(page.getNumberOfElements()).isEqualTo(2);
assertEquals(2, page.getSize()); assertThat(page.getSize()).isEqualTo(2);
assertEquals(5, page.getTotalPages()); assertThat(page.getTotalPages()).isEqualTo(5);
} }
} }

View File

@ -15,13 +15,14 @@
*/ */
package org.springframework.data.elasticsearch.core.convert; package org.springframework.data.elasticsearch.core.convert;
import static org.assertj.core.api.Assertions.*;
import java.util.Calendar; import java.util.Calendar;
import java.util.TimeZone; import java.util.TimeZone;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
/** /**
@ -32,32 +33,32 @@ public class DateTimeConvertersTests {
@Test @Test
public void testJodaDateTimeConverterWithNullValue() { public void testJodaDateTimeConverterWithNullValue() {
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null)); assertThat(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null)).isNull();
} }
@Test @Test
public void testJodaDateTimeConverter() { public void testJodaDateTimeConverter() {
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC); DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
Assert.assertEquals("2013-01-24T06:35:00.000Z", assertThat(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime))
DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime)); .isEqualTo("2013-01-24T06:35:00.000Z");
} }
@Test @Test
public void testJodaLocalDateTimeConverterWithNullValue() { public void testJodaLocalDateTimeConverterWithNullValue() {
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null)); assertThat(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null)).isNull();
} }
@Test @Test
public void testJodaLocalDateTimeConverter() { public void testJodaLocalDateTimeConverter() {
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(), LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
DateTimeZone.UTC); DateTimeZone.UTC);
Assert.assertEquals("2013-01-24T06:35:00.000Z", assertThat(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime))
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime)); .isEqualTo("2013-01-24T06:35:00.000Z");
} }
@Test @Test
public void testJavaDateConverterWithNullValue() { public void testJavaDateConverterWithNullValue() {
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null)); assertThat(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null)).isNull();
} }
@Test @Test
@ -67,7 +68,7 @@ public class DateTimeConvertersTests {
calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(dateTime.getMillis()); calendar.setTimeInMillis(dateTime.getMillis());
Assert.assertEquals("2013-01-24T06:35:00.000Z", assertThat(DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()))
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime())); .isEqualTo("2013-01-24T06:35:00.000Z");
} }
} }

View File

@ -15,12 +15,13 @@
*/ */
package org.springframework.data.elasticsearch.repositories.dynamicindex; package org.springframework.data.elasticsearch.repositories.dynamicindex;
import static org.junit.Assert.*; import static org.assertj.core.api.Assertions.*;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
@ -74,11 +75,11 @@ public class DynamicIndexEntityTests {
indexNameProvider.setIndexName("index1"); indexNameProvider.setIndexName("index1");
repository.save(new DynamicIndexEntity()); repository.save(new DynamicIndexEntity());
assertTrue(indexNameProvider.callsCount > initialCallsCount); assertThat(indexNameProvider.callsCount > initialCallsCount).isTrue();
assertEquals(1L, repository.count()); assertThat(repository.count()).isEqualTo(1L);
indexNameProvider.setIndexName("index2"); indexNameProvider.setIndexName("index2");
assertEquals(0L, repository.count()); assertThat(repository.count()).isEqualTo(0L);
} }
@ImportResource(value = "classpath:/dynamic-index-repository-test.xml") @ImportResource(value = "classpath:/dynamic-index-repository-test.xml")

View File

@ -15,11 +15,12 @@
*/ */
package org.springframework.data.elasticsearch.repository.config; package org.springframework.data.elasticsearch.repository.config;
import static org.junit.Assert.*; import static org.assertj.core.api.Assertions.*;
import java.util.Collection; import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;