diff --git a/doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java b/doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java index 0758806..52e0741 100644 --- a/doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java +++ b/doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java @@ -5,11 +5,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -75,7 +71,7 @@ class DomaAutoConfigurationTest { DataSourceAutoConfiguration.class)); @Test - void testAutoRegisteredConfig() { + void autoRegisteredConfig() { this.contextRunner .run(context -> { Config config = context.getBean(Config.class); @@ -104,7 +100,7 @@ void testAutoRegisteredConfig() { } @Test - void testConfigWithDomaConfigBuilder() { + void configWithDomaConfigBuilder() { this.contextRunner .withUserConfiguration(ConfigBuilderConfigure.class) .run(context -> { @@ -135,7 +131,7 @@ void testConfigWithDomaConfigBuilder() { } @Test - void testConfigWithConfig() { + void configWithConfig() { this.contextRunner .withUserConfiguration(ConfigConfigure.class) .run(context -> { @@ -166,17 +162,15 @@ void testConfigWithConfig() { } @Test - void testExceptionTranslationEnabledSpecifyFalse() { + void exceptionTranslationEnabledSpecifyFalse() { this.contextRunner .withPropertyValues("doma.exception-translation-enabled=false") - .run(context -> { - assertThrows(NoSuchBeanDefinitionException.class, - () -> context.getBean(PersistenceExceptionTranslator.class)); - }); + .run(context -> assertThrows(NoSuchBeanDefinitionException.class, + () -> context.getBean(PersistenceExceptionTranslator.class))); } @Test - void testExceptionTranslationEnabledSpecifyTrue() { + void exceptionTranslationEnabledSpecifyTrue() { this.contextRunner .withPropertyValues("doma.exception-translation-enabled=true") .run(context -> { @@ -188,7 +182,7 @@ void testExceptionTranslationEnabledSpecifyTrue() { } @Test - void testChangeDialect() { + void changeDialect() { this.contextRunner .withPropertyValues("doma.dialect=MYSQL") .run(context -> { @@ -198,7 +192,7 @@ void testChangeDialect() { } @Test - void testChangeMaxRows() { + void changeMaxRows() { this.contextRunner .withPropertyValues("doma.max-rows=100") .run(context -> { @@ -208,7 +202,7 @@ void testChangeMaxRows() { } @Test - void testSQLExceptionTranslator() { + void sqlExceptionTranslator() { this.contextRunner .run(context -> { PersistenceExceptionTranslator translator = context @@ -242,32 +236,34 @@ void testSQLExceptionTranslator() { } @Test - void testAutoRegisteredCriteriaAPI() { + void autoRegisteredCriteriaAPI() { this.contextRunner .run(context -> { Entityql entityql = context.getBean(Entityql.class); - assertNotNull(entityql); + org.assertj.core.api.Assertions.assertThat(entityql).isNotNull(); NativeSql nativeSql = context.getBean(NativeSql.class); - assertNotNull(nativeSql); + org.assertj.core.api.Assertions.assertThat(nativeSql).isNotNull(); }); } @Test - void testCriteriaAPIWithConfig() { + void criteriaAPIWithConfig() { this.contextRunner .withUserConfiguration(MyCriteriaAPIConfig.class) .run(context -> { Map entityqlBeans = context.getBeansOfType(Entityql.class); - assertEquals(1, entityqlBeans.size()); - assertNotNull(entityqlBeans.get("myEntityql")); + org.assertj.core.api.Assertions.assertThat(entityqlBeans.size()).isEqualTo(1); + org.assertj.core.api.Assertions.assertThat(entityqlBeans.get("myEntityql")) + .isNotNull(); Map nativeSqlBeans = context.getBeansOfType(NativeSql.class); - assertEquals(1, nativeSqlBeans.size()); - assertNotNull(nativeSqlBeans.get("myNativeSql")); + org.assertj.core.api.Assertions.assertThat(nativeSqlBeans.size()).isEqualTo(1); + org.assertj.core.api.Assertions.assertThat(nativeSqlBeans.get("myNativeSql")) + .isNotNull(); }); } @Test - void testDialectByDataSourceUrl() { + void dialectByDataSourceUrl() { this.contextRunner .withPropertyValues( "spring.datasource.url=jdbc:postgresql://localhost:1234/example", @@ -279,7 +275,7 @@ void testDialectByDataSourceUrl() { } @Test - void testDialectByJdbConnectionDetails() { + void dialectByJdbConnectionDetails() { this.contextRunner .withPropertyValues( "doma.exception-translation-enabled=false"/* prevent database connections */) @@ -306,20 +302,18 @@ public String getJdbcUrl() { } @Test - void testDialectMissingJdbConnectionDetails() { + void dialectMissingJdbConnectionDetails() { this.contextRunner .withPropertyValues( "doma.exception-translation-enabled=false"/* prevent database connections */) .withBean(DataSource.class, SimpleDriverDataSource::new) - .run(context -> { - assertThat(context.getStartupFailure().getMessage(), containsString( - "No connection details available. You will probably have to set 'doma.dialect' explicitly.")); - }); + .run(context -> assertThat(context.getStartupFailure().getMessage(), containsString( + "No connection details available. You will probably have to set 'doma.dialect' explicitly."))); } @Test - void testDialectMissingJdbConnectionDetailsExplicitDialect() { + void dialectMissingJdbConnectionDetailsExplicitDialect() { this.contextRunner .withPropertyValues( "doma.dialect=POSTGRES", @@ -333,7 +327,7 @@ void testDialectMissingJdbConnectionDetailsExplicitDialect() { } @Test - void testDialectByDomaPropertiesIgnoreDataSourceUrl() { + void dialectByDomaPropertiesIgnoreDataSourceUrl() { this.contextRunner .withPropertyValues( "spring.datasource.url=jdbc:h2:mem:example", @@ -346,7 +340,7 @@ void testDialectByDomaPropertiesIgnoreDataSourceUrl() { } @Test - void testJdbcLoggerSlf4J() { + void jdbcLoggerSlf4J() { this.contextRunner .withPropertyValues("doma.jdbcLogger=SLF4J") @@ -357,29 +351,30 @@ void testJdbcLoggerSlf4J() { } @Test - void testAutoRegisteredQueryDsl() { + void autoRegisteredQueryDsl() { this.contextRunner .run(context -> { QueryDsl queryDsl = context.getBean(QueryDsl.class); - assertNotNull(queryDsl); + org.assertj.core.api.Assertions.assertThat(queryDsl).isNotNull(); }); } @Test - void testQueryDslWithConfig() { + void queryDslWithConfig() { this.contextRunner .withUserConfiguration(MyQueryDslConfig.class) .run(context -> { Map queryDslBeans = context.getBeansOfType(QueryDsl.class); - assertEquals(1, queryDslBeans.size()); - assertNotNull(queryDslBeans.get("myQueryDsl")); + org.assertj.core.api.Assertions.assertThat(queryDslBeans.size()).isEqualTo(1); + org.assertj.core.api.Assertions.assertThat(queryDslBeans.get("myQueryDsl")) + .isNotNull(); }); } @Test - void testThrowExceptionIfDuplicateColumn() { + void throwExceptionIfDuplicateColumn() { this.contextRunner .withPropertyValues("doma.throw-exception-if-duplicate-column=true") @@ -391,7 +386,7 @@ void testThrowExceptionIfDuplicateColumn() { } @Test - void testCustomizeShouldRemoveBlockComment() { + void customizeShouldRemoveBlockComment() { Predicate predicate = mock(Predicate.class); when(predicate.test(anyString())).thenReturn(true); @@ -411,7 +406,7 @@ void testCustomizeShouldRemoveBlockComment() { } @Test - void testCustomizeShouldRemoveLineComment() { + void customizeShouldRemoveLineComment() { Predicate predicate = mock(Predicate.class); when(predicate.test(anyString())).thenReturn(true); @@ -431,7 +426,7 @@ void testCustomizeShouldRemoveLineComment() { } @Test - void testAnonymousPredicateAreNotAffected() { + void anonymousPredicateAreNotAffected() { Predicate predicate = mock(Predicate.class); when(predicate.test(anyString())).thenReturn(true); @@ -450,65 +445,75 @@ void testAnonymousPredicateAreNotAffected() { } @Test - void testShouldRemoveBlankLinesDefaultValue() { + void shouldRemoveBlankLinesDefaultValue() { this.contextRunner .run(context -> { Config config = context.getBean(Config.class); - assertFalse(config.getSqlBuilderSettings().shouldRemoveBlankLines()); + org.assertj.core.api.Assertions + .assertThat(config.getSqlBuilderSettings().shouldRemoveBlankLines()) + .isFalse(); }); } @Test - void testShouldRemoveBlankLinesChangedValue() { + void shouldRemoveBlankLinesChangedValue() { this.contextRunner .withPropertyValues("doma.sql-builder-settings.should-remove-blank-lines=true") .run(context -> { Config config = context.getBean(Config.class); - assertTrue(config.getSqlBuilderSettings().shouldRemoveBlankLines()); + org.assertj.core.api.Assertions + .assertThat(config.getSqlBuilderSettings().shouldRemoveBlankLines()) + .isTrue(); }); } @Test - void testShouldRequireInListPaddingDefaultValue() { + void shouldRequireInListPaddingDefaultValue() { this.contextRunner .run(context -> { Config config = context.getBean(Config.class); - assertFalse(config.getSqlBuilderSettings().shouldRequireInListPadding()); + org.assertj.core.api.Assertions + .assertThat(config.getSqlBuilderSettings().shouldRequireInListPadding()) + .isFalse(); }); } @Test - void testShouldRequireInListPaddingChangedValue() { + void shouldRequireInListPaddingChangedValue() { this.contextRunner .withPropertyValues("doma.sql-builder-settings.should-require-in-list-padding=true") .run(context -> { Config config = context.getBean(Config.class); - assertTrue(config.getSqlBuilderSettings().shouldRequireInListPadding()); + org.assertj.core.api.Assertions + .assertThat(config.getSqlBuilderSettings().shouldRequireInListPadding()) + .isTrue(); }); } @Test - void testStatisticManagerDefaultValue() { + void statisticManagerDefaultValue() { this.contextRunner .run(context -> { Config config = context.getBean(Config.class); - assertFalse(config.getStatisticManager().isEnabled()); + org.assertj.core.api.Assertions + .assertThat(config.getStatisticManager().isEnabled()).isFalse(); }); } @Test - void testStatisticManagerChangedValue() { + void statisticManagerChangedValue() { this.contextRunner .withPropertyValues("doma.statistic-manager.enabled=true") .run(context -> { Config config = context.getBean(Config.class); - assertTrue(config.getStatisticManager().isEnabled()); + org.assertj.core.api.Assertions + .assertThat(config.getStatisticManager().isEnabled()).isTrue(); }); } diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/DomaPersistenceExceptionTranslatorTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/DomaPersistenceExceptionTranslatorTest.java index 20e5a5d..0e369d1 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/DomaPersistenceExceptionTranslatorTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/DomaPersistenceExceptionTranslatorTest.java @@ -1,7 +1,6 @@ package org.seasar.doma.boot; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.assertj.core.api.Assertions.assertThat; import java.sql.SQLException; import java.util.Collections; @@ -36,27 +35,27 @@ class DomaPersistenceExceptionTranslatorTest { new SQLExceptionSubclassTranslator()); @Test - void testOccurNotJdbcException() { + void occurNotJdbcException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new DomaException(Message.DOMA2008)); - assertNull(dataAccessException); + assertThat(dataAccessException).isNull(); } @Test - void testOccurSqlExecutionException() { + void occurSqlExecutionException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new SqlExecutionException( SqlLogType.FORMATTED, SqlKind.SELECT, "select * from todo where todo_id = ?", "select * from todo where todo_id = '000000001'", "TodoDao/findOne.sql", new SQLException(), null)); - assertInstanceOf(UncategorizedSQLException.class, dataAccessException); - assertEquals("select * from todo where todo_id = ?", - ((UncategorizedSQLException) dataAccessException).getSql()); + assertThat(dataAccessException).isInstanceOf(UncategorizedSQLException.class); + assertThat(((UncategorizedSQLException) dataAccessException).getSql()) + .isEqualTo("select * from todo where todo_id = ?"); } @Test - void testThrowOptimisticLockingFailureException() { + void throwOptimisticLockingFailureException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new OptimisticLockException( SqlLogType.FORMATTED, @@ -64,11 +63,11 @@ void testThrowOptimisticLockingFailureException() { "update todo set title = ? where todo_id = ? and version = ?", "update todo set title = 'Modified Title' where todo_id = '000000001' and version = 1", "TodoDao/update.sql")); - assertInstanceOf(OptimisticLockingFailureException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(OptimisticLockingFailureException.class); } @Test - void testThrowDuplicateKeyException() { + void throwDuplicateKeyException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new UniqueConstraintException( SqlLogType.FORMATTED, @@ -76,11 +75,11 @@ void testThrowDuplicateKeyException() { "insert into todo (todo_id, title) values (?, ?)", "insert into todo (todo_id, title) values ('000000001', 'Title')", "TodoDao/insert.sql", new SQLException())); - assertInstanceOf(DuplicateKeyException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(DuplicateKeyException.class); } @Test - void testThrowIncorrectResultSizeDataAccessException() { + void throwIncorrectResultSizeDataAccessException() { { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new NonUniqueResultException( @@ -88,7 +87,8 @@ void testThrowIncorrectResultSizeDataAccessException() { "select * from todo where created_at = ?", "select * from todo where created_at = '2016-03-06'", "TodoDao/findBy.sql")); - assertInstanceOf(IncorrectResultSizeDataAccessException.class, dataAccessException); + assertThat(dataAccessException) + .isInstanceOf(IncorrectResultSizeDataAccessException.class); } { DataAccessException dataAccessException = translator @@ -98,22 +98,23 @@ void testThrowIncorrectResultSizeDataAccessException() { "select todo_id, title from todo where created_at = ?", "select todo_id, title from todo where created_at = '2016-03-06'", "TodoDao/findBy.sql")); - assertInstanceOf(IncorrectResultSizeDataAccessException.class, dataAccessException); + assertThat(dataAccessException) + .isInstanceOf(IncorrectResultSizeDataAccessException.class); } } @Test - void testThrowEmptyResultDataAccessException() { + void throwEmptyResultDataAccessException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new NoResultException(SqlLogType.FORMATTED, SqlKind.SELECT, "select * from todo where todo_id = ?", "select * from todo where todo_id = '000000001'", "TodoDao/findOne.sql")); - assertInstanceOf(EmptyResultDataAccessException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(EmptyResultDataAccessException.class); } @Test - void testThrowTypeMismatchDataAccessException() { + void throwTypeMismatchDataAccessException() { { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new UnknownColumnException( @@ -121,7 +122,7 @@ void testThrowTypeMismatchDataAccessException() { SqlKind.SELECT, "select * from todo where created_at = ?", "select * from todo where created_at = '2016-03-06'", "TodoDao/findBy.sql")); - assertInstanceOf(TypeMismatchDataAccessException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(TypeMismatchDataAccessException.class); } { DataAccessException dataAccessException = translator @@ -134,16 +135,16 @@ void testThrowTypeMismatchDataAccessException() { "select todo_id, title from todo where created_at = ?", "select todo_id, title from todo where created_at = '2016-03-06'", "TodoDao/findBy.sql")); - assertInstanceOf(TypeMismatchDataAccessException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(TypeMismatchDataAccessException.class); } } @Test - void testThrowUncategorizedDataAccessException() { + void throwUncategorizedDataAccessException() { DataAccessException dataAccessException = translator .translateExceptionIfPossible(new ConfigException("DomaConfig", "configure")); - assertInstanceOf(UncategorizedDataAccessException.class, dataAccessException); + assertThat(dataAccessException).isInstanceOf(UncategorizedDataAccessException.class); } } diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java index bffffcc..c4e9f63 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; import org.seasar.doma.jdbc.SelectOptions; @@ -10,24 +10,24 @@ class PageablesTest { @Test - void testToSelectOptions() throws Exception { + void toSelectOptions() throws Exception { SelectOptions options = Pageables.toSelectOptions(pageRequest(0, 10)); - assertEquals(0L, SelectOptionsAccessor.getOffset(options)); - assertEquals(10L, SelectOptionsAccessor.getLimit(options)); + assertThat(SelectOptionsAccessor.getOffset(options)).isEqualTo(0L); + assertThat(SelectOptionsAccessor.getLimit(options)).isEqualTo(10L); } @Test - void testToSelectOptions2() throws Exception { + void toSelectOptions2() throws Exception { SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 10)); - assertEquals(20L, SelectOptionsAccessor.getOffset(options)); - assertEquals(10L, SelectOptionsAccessor.getLimit(options)); + assertThat(SelectOptionsAccessor.getOffset(options)).isEqualTo(20L); + assertThat(SelectOptionsAccessor.getLimit(options)).isEqualTo(10L); } @Test - void testToSelectOptions3() throws Exception { + void toSelectOptions3() throws Exception { SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 5)); - assertEquals(10L, SelectOptionsAccessor.getOffset(options)); - assertEquals(5L, SelectOptionsAccessor.getLimit(options)); + assertThat(SelectOptionsAccessor.getOffset(options)).isEqualTo(10L); + assertThat(SelectOptionsAccessor.getLimit(options)).isEqualTo(5L); } private static PageRequest pageRequest(int page, int size) throws Exception { diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/ResourceLoaderScriptFileLoaderTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/ResourceLoaderScriptFileLoaderTest.java index c54b252..6f30dad 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/ResourceLoaderScriptFileLoaderTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/ResourceLoaderScriptFileLoaderTest.java @@ -1,7 +1,6 @@ package org.seasar.doma.boot; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -14,7 +13,7 @@ class ResourceLoaderScriptFileLoaderTest { @Test - void testLoadAsURL() throws Exception { + void loadAsURL() throws Exception { var location = "META-INF/com/example/dao/TestDao/test.script"; var expectedURL = new URL("file:///" + location); var resourceLoader = mock(ResourceLoader.class); @@ -27,11 +26,11 @@ void testLoadAsURL() throws Exception { var sut = new ResourceLoaderScriptFileLoader(resourceLoader); var actualURL = sut.loadAsURL(location); - assertEquals(expectedURL, actualURL); + assertThat(actualURL).isEqualTo(expectedURL); } @Test - void testLoadAsURLFallback() throws Exception { + void loadAsURLFallback() throws Exception { var location = "META-INF/com/example/dao/TestDao/test.script"; var expectedURL = new URL("file:///" + location); var resourceLoader = mock(ResourceLoader.class); @@ -48,11 +47,11 @@ void testLoadAsURLFallback() throws Exception { var sut = new ResourceLoaderScriptFileLoader(resourceLoader); var actualURL = sut.loadAsURL(location); - assertEquals(expectedURL, actualURL); + assertThat(actualURL).isEqualTo(expectedURL); } @Test - void testLoadAsURLScriptNotFound() { + void loadAsURLScriptNotFound() { var location = "META-INF/com/example/dao/TestDao/test.script"; var resourceLoader = mock(ResourceLoader.class); var notExistsResource = mock(Resource.class); @@ -65,6 +64,6 @@ void testLoadAsURLScriptNotFound() { var sut = new ResourceLoaderScriptFileLoader(resourceLoader); var actualURL = sut.loadAsURL(location); - assertNull(actualURL); + assertThat(actualURL).isNull(); } } diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/TryLookupEntityListenerProviderTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/TryLookupEntityListenerProviderTest.java index aa583d0..95d151f 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/TryLookupEntityListenerProviderTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/TryLookupEntityListenerProviderTest.java @@ -1,7 +1,7 @@ package org.seasar.doma.boot; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import org.junit.jupiter.api.Test; import org.seasar.doma.jdbc.entity.EntityListener; @@ -14,37 +14,36 @@ class TryLookupEntityListenerProviderTest { @Test - void testManaged() throws Exception { + void managed() throws Exception { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { context.register(FooListener.class); context.refresh(); TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider(); provider.setApplicationContext(context); FooListener listener = provider.get(FooListener.class, FooListener::new); - assertTrue(listener.managed); + assertThat(listener.managed).isTrue(); } } @Test - void testManaged_notUnique() throws Exception { + void managedNotUnique() throws Exception { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( FooConfig.class)) { TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider(); provider.setApplicationContext(context); - assertThrows(IllegalStateException.class, () -> { - provider.get(FooListener.class, FooListener::new); - }); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> provider.get(FooListener.class, FooListener::new)); } } @Test - void testNotManaged() throws Exception { + void notManaged() throws Exception { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { context.refresh(); TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider(); provider.setApplicationContext(context); FooListener listener = provider.get(FooListener.class, FooListener::new); - assertFalse(listener.managed); + assertThat(listener.managed).isFalse(); } } diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/UnifiedCriteriaPageableTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/UnifiedCriteriaPageableTest.java index cb9fd8c..c686e39 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/UnifiedCriteriaPageableTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/UnifiedCriteriaPageableTest.java @@ -1,9 +1,7 @@ package org.seasar.doma.boot; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -32,7 +30,7 @@ class UnifiedCriteriaPageableTest { "2 | 10 | 20 | 10", "2 | 5 | 10 | 5", }, delimiter = '|') - void testOffsetAndLimit( + void offsetAndLimit( int pageNumber, int pageSize, int expectedOffset, int expectedLimit) { Pageable pageable = PageRequest.of(pageNumber, pageSize); UnifiedCriteriaPageable p = UnifiedCriteriaPageable.of(pageable, c -> Optional.empty()); @@ -40,24 +38,24 @@ void testOffsetAndLimit( Integer offset = p.offset(); Integer limit = p.limit(); - assertEquals(expectedOffset, offset); - assertEquals(expectedLimit, limit); + assertThat(offset).isEqualTo(expectedOffset); + assertThat(limit).isEqualTo(expectedLimit); } @Test - void testOffsetAndLimitWhenUnpaged() { + void offsetAndLimitWhenUnpaged() { Pageable pageable = Pageable.unpaged(); UnifiedCriteriaPageable p = UnifiedCriteriaPageable.of(pageable, c -> Optional.empty()); Integer offset = p.offset(); Integer limit = p.limit(); - assertNull(offset); - assertNull(limit); + assertThat(offset).isNull(); + assertThat(limit).isNull(); } @Test - void testOrderBy() { + void orderBy() { Pageable pageable = PageRequest.of(0, 10, Sort.by("name").ascending()); Person_ entity = new Person_(); UnifiedCriteriaPageable p = UnifiedCriteriaPageable.of( @@ -75,7 +73,7 @@ void testOrderBy() { } @Test - void testOrderBy2() { + void orderBy2() { Pageable pageable = PageRequest.of(0, 10, Sort.by("name").descending().and(Sort.by("age").ascending())); Person_ entity = new Person_(); @@ -97,7 +95,7 @@ void testOrderBy2() { } @Test - void testOrderByWhenNonSort() { + void orderByWhenNonSort() { Pageable pageable = PageRequest.of(0, 10); UnifiedCriteriaPageable p = UnifiedCriteriaPageable.of( pageable, @@ -111,7 +109,7 @@ void testOrderByWhenNonSort() { } @Test - void testOrderByWhenNonSortAndSetDefault() { + void orderByWhenNonSortAndSetDefault() { Pageable pageable = PageRequest.of(0, 10); Person_ entity = new Person_(); Consumer defaultOrder = c -> c.asc(entity.id); @@ -122,11 +120,11 @@ void testOrderByWhenNonSortAndSetDefault() { Consumer consumer = p.orderBy(); - assertSame(defaultOrder, consumer); + assertThat(consumer).isSameAs(defaultOrder); } @Test - void testOrderBySingleEntity() { + void orderBySingleEntity() { Pageable pageable = PageRequest.of(0, 10, Sort.by("name").descending().and(Sort.by("age").ascending())); Person_ entity = new Person_(); @@ -142,7 +140,7 @@ void testOrderBySingleEntity() { } @Test - void testOrderByWhenMissingProperties() { + void orderByWhenMissingProperties() { Pageable pageable = PageRequest.of(0, 10, Sort.by("dog").and(Sort.by("name")).and(Sort.by("cat"))); Person_ entity = new Person_(); @@ -156,7 +154,7 @@ void testOrderByWhenMissingProperties() { } @Test - void testOrderByWhenMissingAllProperties() { + void orderByWhenMissingAllProperties() { Pageable pageable = PageRequest.of(0, 10, Sort.by("dog").and(Sort.by("cat"))); Person_ entity = new Person_(); @@ -165,11 +163,11 @@ void testOrderByWhenMissingAllProperties() { Consumer consumer = p.orderBy(); - assertSame(defaultOrder, consumer); + assertThat(consumer).isSameAs(defaultOrder); } @Test - void testOrderByWhenMissingPropertiesHandle() { + void orderByWhenMissingPropertiesHandle() { Pageable pageable = PageRequest.of(0, 10, Sort.by("dog").and(Sort.by("name")).and(Sort.by("cat"))); Person_ entity = new Person_(); diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaApplicationListenerTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaApplicationListenerTest.java index ba14612..36c38ce 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaApplicationListenerTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaApplicationListenerTest.java @@ -1,8 +1,8 @@ package org.seasar.doma.boot.event; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.mockito.Mockito.mock; import java.lang.reflect.Method; @@ -61,8 +61,8 @@ void notEntity() throws Exception { Method method = NotEntity.class .getDeclaredMethod("handle", TestEntity3.class); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Test @@ -71,8 +71,8 @@ void invalidContextClass() throws Exception { Method method = InvalidContextClass.class.getDeclaredMethod("handle", TestEntity1.class, PostInsertContext.class); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Test @@ -81,8 +81,8 @@ void invalidContextTypeVar() throws Exception { Method method = InvalidContextTypeVar.class.getDeclaredMethod("handle", TestEntity1.class, PreInsertContext.class); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Test @@ -90,8 +90,8 @@ void noArg() throws Exception { String beanName = ""; Method method = NoArg.class.getDeclaredMethod("handle"); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Test @@ -100,8 +100,8 @@ void tooManyArgs() throws Exception { Method method = TooManyArgs.class.getDeclaredMethod("handle", TestEntity1.class, PreInsertContext.class, Object.class); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Test @@ -110,8 +110,8 @@ void multiAnnotationsWithContext() throws Exception { Method method = MultiAnnotationsWithContext.class.getDeclaredMethod("handle", TestEntity1.class, PreInsertContext.class); BeanFactory beanFactory = mock(BeanFactory.class); - assertThrows(IllegalArgumentException.class, - () -> new DomaApplicationListener(beanName, method, beanFactory)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new DomaApplicationListener(beanName, method, beanFactory)); } @Entity @@ -131,7 +131,7 @@ void handle(TestEntity1 entity) { } } - public static class EntityWithContext { + static class EntityWithContext { @HandlePreInsert void handle(TestEntity1 entity, PreInsertContext context) { } diff --git a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaEventEntityListenerTest.java b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaEventEntityListenerTest.java index 0c3989e..19b3a91 100644 --- a/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaEventEntityListenerTest.java +++ b/doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaEventEntityListenerTest.java @@ -1,8 +1,8 @@ package org.seasar.doma.boot.event; import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.mockito.Mockito.mock; import org.junit.jupiter.api.Test; import org.seasar.doma.boot.event.annotation.HandlePostDelete; @@ -336,7 +336,7 @@ void multiAnnotations() throws Exception { @Test void noArg() throws Exception { - assertThrows(BeanInitializationException.class, () -> { + assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() -> { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { context.register(DomaEventEntityListener.class); context.register(DomaEventListenerFactory.class); diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index 92c10d9..359d5ff 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -34,31 +34,31 @@ void setUp(@Autowired RestClient.Builder restClientBuilder, @Autowired JdbcClien } @Test - void testWithDockerCompose() { + void withDockerCompose() { Message message1 = restClient.get() .uri("/?text={text}", "hello") .retrieve() .body(Message.class); - assertEquals(1, message1.id); - assertEquals("hello", message1.text); + assertThat(message1.id).isEqualTo(1); + assertThat(message1.text).isEqualTo("hello"); Message message2 = restClient.get() .uri("/?text={text}", "world") .retrieve() .body(Message.class); - assertEquals(2, message2.id); - assertEquals("world", message2.text); + assertThat(message2.id).isEqualTo(2); + assertThat(message2.text).isEqualTo("world"); { List messages = restClient.get() .uri("/") .retrieve() .body(typedReference); - assertEquals(2, messages.size()); - assertEquals(message1.id, messages.get(0).id); - assertEquals(message1.text, messages.get(0).text); - assertEquals(message2.id, messages.get(1).id); - assertEquals(message2.text, messages.get(1).text); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).id).isEqualTo(message1.id); + assertThat(messages.get(0).text).isEqualTo(message1.text); + assertThat(messages.get(1).id).isEqualTo(message2.id); + assertThat(messages.get(1).text).isEqualTo(message2.text); } { @@ -66,9 +66,9 @@ void testWithDockerCompose() { .uri("/?page={page}&size={size}", 1, 1) .retrieve() .body(typedReference); - assertEquals(1, messages.size()); - assertEquals(message2.id, messages.get(0).id); - assertEquals(message2.text, messages.get(0).text); + assertThat(messages.size()).isEqualTo(1); + assertThat(messages.get(0).id).isEqualTo(message2.id); + assertThat(messages.get(0).text).isEqualTo(message2.text); } } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index 0bef7f8..df7423d 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.time.LocalDate; import java.util.List; @@ -30,16 +30,16 @@ void test() { UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "hello").build().toUri(), Message.class); - assertEquals(1, message1.id); - assertEquals("hello", message1.text); - assertEquals(now, message1.createdAt); + assertThat(message1.id).isEqualTo(1); + assertThat(message1.text).isEqualTo("hello"); + assertThat(message1.createdAt).isEqualTo(now); Message message2 = restTemplate.getForObject( UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "world").build().toUri(), Message.class); - assertEquals(2, message2.id); - assertEquals("world", message2.text); - assertEquals(now, message2.createdAt); + assertThat(message2.id).isEqualTo(2); + assertThat(message2.text).isEqualTo("world"); + assertThat(message2.createdAt).isEqualTo(now); { List messages = restTemplate.exchange( @@ -47,11 +47,11 @@ void test() { .build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference).getBody(); - assertEquals(2, messages.size()); - assertEquals(message1.id, messages.get(0).id); - assertEquals(message1.text, messages.get(0).text); - assertEquals(message2.id, messages.get(1).id); - assertEquals(message2.text, messages.get(1).text); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).id).isEqualTo(message1.id); + assertThat(messages.get(0).text).isEqualTo(message1.text); + assertThat(messages.get(1).id).isEqualTo(message2.id); + assertThat(messages.get(1).text).isEqualTo(message2.text); } { @@ -61,9 +61,9 @@ void test() { .toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference) .getBody(); - assertEquals(1, messages.size()); - assertEquals(message2.id, messages.get(0).id); - assertEquals(message2.text, messages.get(0).text); + assertThat(messages.size()).isEqualTo(1); + assertThat(messages.get(0).id).isEqualTo(message2.id); + assertThat(messages.get(0).text).isEqualTo(message2.text); } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-event-handler/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-event-handler/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index 0bef7f8..df7423d 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-event-handler/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-event-handler/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.time.LocalDate; import java.util.List; @@ -30,16 +30,16 @@ void test() { UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "hello").build().toUri(), Message.class); - assertEquals(1, message1.id); - assertEquals("hello", message1.text); - assertEquals(now, message1.createdAt); + assertThat(message1.id).isEqualTo(1); + assertThat(message1.text).isEqualTo("hello"); + assertThat(message1.createdAt).isEqualTo(now); Message message2 = restTemplate.getForObject( UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "world").build().toUri(), Message.class); - assertEquals(2, message2.id); - assertEquals("world", message2.text); - assertEquals(now, message2.createdAt); + assertThat(message2.id).isEqualTo(2); + assertThat(message2.text).isEqualTo("world"); + assertThat(message2.createdAt).isEqualTo(now); { List messages = restTemplate.exchange( @@ -47,11 +47,11 @@ void test() { .build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference).getBody(); - assertEquals(2, messages.size()); - assertEquals(message1.id, messages.get(0).id); - assertEquals(message1.text, messages.get(0).text); - assertEquals(message2.id, messages.get(1).id); - assertEquals(message2.text, messages.get(1).text); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).id).isEqualTo(message1.id); + assertThat(messages.get(0).text).isEqualTo(message1.text); + assertThat(messages.get(1).id).isEqualTo(message2.id); + assertThat(messages.get(1).text).isEqualTo(message2.text); } { @@ -61,9 +61,9 @@ void test() { .toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference) .getBody(); - assertEquals(1, messages.size()); - assertEquals(message2.id, messages.get(0).id); - assertEquals(message2.text, messages.get(0).text); + assertThat(messages.size()).isEqualTo(1); + assertThat(messages.get(0).id).isEqualTo(message2.id); + assertThat(messages.get(0).text).isEqualTo(message2.text); } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-simple/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-simple/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index 41c076f..39ff69c 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-simple/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-simple/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -30,14 +30,14 @@ void test() { UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "hello").build().toUri(), Message.class); - assertEquals(1, message1.id); - assertEquals("hello", message1.text); + assertThat(message1.id).isEqualTo(1); + assertThat(message1.text).isEqualTo("hello"); Message message2 = restTemplate.getForObject( UriComponentsBuilder.fromUriString("http://localhost").port(port) .queryParam("text", "world").build().toUri(), Message.class); - assertEquals(2, message2.id); - assertEquals("world", message2.text); + assertThat(message2.id).isEqualTo(2); + assertThat(message2.text).isEqualTo("world"); { List messages = restTemplate.exchange( @@ -45,11 +45,11 @@ void test() { .build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference).getBody(); - assertEquals(2, messages.size()); - assertEquals(message1.id, messages.get(0).id); - assertEquals(message1.text, messages.get(0).text); - assertEquals(message2.id, messages.get(1).id); - assertEquals(message2.text, messages.get(1).text); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).id).isEqualTo(message1.id); + assertThat(messages.get(0).text).isEqualTo(message1.text); + assertThat(messages.get(1).id).isEqualTo(message2.id); + assertThat(messages.get(1).text).isEqualTo(message2.text); } { @@ -59,9 +59,9 @@ void test() { .toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference) .getBody(); - assertEquals(1, messages.size()); - assertEquals(message2.id, messages.get(0).id); - assertEquals(message2.text, messages.get(0).text); + assertThat(messages.size()).isEqualTo(1); + assertThat(messages.get(0).id).isEqualTo(message2.id); + assertThat(messages.get(0).text).isEqualTo(message2.text); } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-testcontainers/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-testcontainers/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index b9e9891..895e34e 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-testcontainers/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-testcontainers/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -33,31 +33,31 @@ void setUp(@Autowired RestClient.Builder restClientBuilder) { } @Test - void testWithTestContainers() { + void withTestContainers() { Message message1 = restClient.get() .uri("/?text={text}", "hello") .retrieve() .body(Message.class); - assertEquals(1, message1.id); - assertEquals("hello", message1.text); + assertThat(message1.id).isEqualTo(1); + assertThat(message1.text).isEqualTo("hello"); Message message2 = restClient.get() .uri("/?text={text}", "world") .retrieve() .body(Message.class); - assertEquals(2, message2.id); - assertEquals("world", message2.text); + assertThat(message2.id).isEqualTo(2); + assertThat(message2.text).isEqualTo("world"); { List messages = restClient.get() .uri("/") .retrieve() .body(typedReference); - assertEquals(2, messages.size()); - assertEquals(message1.id, messages.get(0).id); - assertEquals(message1.text, messages.get(0).text); - assertEquals(message2.id, messages.get(1).id); - assertEquals(message2.text, messages.get(1).text); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).id).isEqualTo(message1.id); + assertThat(messages.get(0).text).isEqualTo(message1.text); + assertThat(messages.get(1).id).isEqualTo(message2.id); + assertThat(messages.get(1).text).isEqualTo(message2.text); } { @@ -65,9 +65,9 @@ void testWithTestContainers() { .uri("/?page={page}&size={size}", 1, 1) .retrieve() .body(typedReference); - assertEquals(1, messages.size()); - assertEquals(message2.id, messages.get(0).id); - assertEquals(message2.text, messages.get(0).text); + assertThat(messages.size()).isEqualTo(1); + assertThat(messages.get(0).id).isEqualTo(message2.id); + assertThat(messages.get(0).text).isEqualTo(message2.text); } } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-two-datasource/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-two-datasource/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index dc3462b..3242bed 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-two-datasource/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-two-datasource/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,8 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; import org.seasar.doma.boot.sample.entity.PrimaryMessage; @@ -18,15 +20,15 @@ class ApplicationTest { @Test void primary() { PrimaryMessage message = service.primaryMessage(1).orElseGet(() -> fail()); - assertEquals(1, message.id); - assertEquals("primary message", message.content); + assertThat(message.id).isEqualTo(1); + assertThat(message.content).isEqualTo("primary message"); } @Test void secondary() { SecondaryMessage message = service.secondaryMessage(2).orElseGet(() -> fail()); - assertEquals(2, message.id); - assertEquals("secondary message", message.content); + assertThat(message.id).isEqualTo(2); + assertThat(message.content).isEqualTo("secondary message"); } @Test @@ -40,8 +42,8 @@ void commitPrimary() { } { PrimaryMessage message = service.primaryMessage(10).orElseGet(() -> fail()); - assertEquals(10, message.id); - assertEquals("primary commit", message.content); + assertThat(message.id).isEqualTo(10); + assertThat(message.content).isEqualTo("primary commit"); } } @@ -52,11 +54,11 @@ void rollbackPrimary() { boolean thrownException = true; - assertThrows(RuntimeException.class, - () -> service.insertPrimary(message, thrownException)); + assertThatExceptionOfType(RuntimeException.class) + .isThrownBy(() -> service.insertPrimary(message, thrownException)); } - assertFalse(service.primaryMessage(100).isPresent()); + assertThat(service.primaryMessage(100).isPresent()).isFalse(); } @Test @@ -70,8 +72,8 @@ void commitSecondary() { } { SecondaryMessage message = service.secondaryMessage(20).orElseGet(() -> fail()); - assertEquals(20, message.id); - assertEquals("secondary commit", message.content); + assertThat(message.id).isEqualTo(20); + assertThat(message.content).isEqualTo("secondary commit"); } } @@ -82,10 +84,10 @@ void rollbackSecondary() { boolean thrownException = true; - assertThrows(RuntimeException.class, - () -> service.insertSecondary(message, thrownException)); + assertThatExceptionOfType(RuntimeException.class) + .isThrownBy(() -> service.insertSecondary(message, thrownException)); } - assertFalse(service.secondaryMessage(200).isPresent()); + assertThat(service.secondaryMessage(200).isPresent()).isFalse(); } } diff --git a/doma-spring-boot-samples/doma-spring-boot-sample-unified-criteria/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java b/doma-spring-boot-samples/doma-spring-boot-sample-unified-criteria/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java index 5debe6e..9c1d41c 100644 --- a/doma-spring-boot-samples/doma-spring-boot-sample-unified-criteria/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java +++ b/doma-spring-boot-samples/doma-spring-boot-sample-unified-criteria/src/test/java/org/seasar/doma/boot/sample/ApplicationTest.java @@ -1,6 +1,6 @@ package org.seasar.doma.boot.sample; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import java.util.Map; @@ -38,10 +38,10 @@ void test() { List messages = http.get() .retrieve() .body(typedReference); - assertEquals(3, messages.size()); - assertEquals("message0", messages.get(0).text()); - assertEquals("message1", messages.get(1).text()); - assertEquals("message2", messages.get(2).text()); + assertThat(messages.size()).isEqualTo(3); + assertThat(messages.get(0).text()).isEqualTo("message0"); + assertThat(messages.get(1).text()).isEqualTo("message1"); + assertThat(messages.get(2).text()).isEqualTo("message2"); } { @@ -49,9 +49,9 @@ void test() { .uri(builder -> builder.queryParam("page", 3).queryParam("size", 2) .queryParam("sort", "id,desc").build()) .retrieve().body(typedReference); - assertEquals(2, messages.size()); - assertEquals("message3", messages.get(0).text()); - assertEquals("message2", messages.get(1).text()); + assertThat(messages.size()).isEqualTo(2); + assertThat(messages.get(0).text()).isEqualTo("message3"); + assertThat(messages.get(1).text()).isEqualTo("message2"); } }