Skip to content

Commit

Permalink
Merge pull request #92 from ppodgorsek/issue-6
Browse files Browse the repository at this point in the history
Issue #6 - Add support for JUnit 5
  • Loading branch information
ppodgorsek authored Feb 5, 2019
2 parents 9ad209c + fd703f0 commit fb6ed00
Show file tree
Hide file tree
Showing 75 changed files with 490 additions and 597 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The dependencies used are:

* Spring Framework 5
* DBUnit 2.6
* JUnit 4
* JUnit 5

## How to use this project

Expand Down
2 changes: 1 addition & 1 deletion eclipse/eclipse-code-formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
Expand Down
6 changes: 3 additions & 3 deletions eclipse/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand Down Expand Up @@ -102,7 +102,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
Expand Down
35 changes: 20 additions & 15 deletions eclipse/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#Sat Mar 10 15:36:37 PST 2012
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_methods=true
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=true
cleanup.always_use_this_for_non_static_field_access=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=false
cleanup.convert_functional_interfaces=true
cleanup.convert_to_enhanced_for_loop=true
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=false
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_modifiers=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
Expand All @@ -43,12 +46,14 @@ cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
cleanup.use_this_for_non_static_method_access=false
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup_profile=_Spring Cleanup Conventions
cleanup_settings_version=2
Expand All @@ -73,7 +78,7 @@ sp_cleanup.add_missing_override_annotations_interface_methods=false
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=true
sp_cleanup.always_use_this_for_non_static_field_access=true
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
Expand Down Expand Up @@ -111,6 +116,6 @@ sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=true
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=true
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
24 changes: 16 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<hibernate.version>5.4.0.Final</hibernate.version>
<hikaricp.version>3.3.0</hikaricp.version>
<hsqldb.version>2.4.1</hsqldb.version>
<junit.version>4.12</junit.version>
<junit-jupiter.version>5.3.2</junit-jupiter.version>
<mockito.version>2.23.4</mockito.version>
<slf4j.version>1.7.25</slf4j.version>
<spring.version>5.1.4.RELEASE</spring.version>
Expand Down Expand Up @@ -148,18 +148,11 @@
<scope>test</scope>
</dependency>

<!-- Expected Dependencies -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>

<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
Expand All @@ -181,6 +174,21 @@
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.github.springtestdbunit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand All @@ -31,8 +31,8 @@
import org.dbunit.database.DatabaseDataSourceConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextLoader;
Expand Down Expand Up @@ -61,29 +61,29 @@ public class DbUnitTestExecutionListenerPrepareTest {

private DataSource dataSource;

@Before
@BeforeEach
public void setup() {
this.applicationContext = mock(ApplicationContext.class);
this.databaseConnection = mock(IDatabaseConnection.class);
this.dataSource = mock(DataSource.class);
DbUnitTestExecutionListenerPrepareTest.applicationContextThreadLocal.set(this.applicationContext);
applicationContext = mock(ApplicationContext.class);
databaseConnection = mock(IDatabaseConnection.class);
dataSource = mock(DataSource.class);
DbUnitTestExecutionListenerPrepareTest.applicationContextThreadLocal.set(applicationContext);
}

@SuppressWarnings("unchecked")
private void addBean(String beanName, Object bean) {
given(this.applicationContext.containsBean(beanName)).willReturn(true);
given(this.applicationContext.getBean(beanName)).willReturn(bean);
given(this.applicationContext.getBean(eq(beanName), (Class) any())).willReturn(bean);
given(applicationContext.containsBean(beanName)).willReturn(true);
given(applicationContext.getBean(beanName)).willReturn(bean);
given(applicationContext.getBean(eq(beanName), (Class) any())).willReturn(bean);
}

@Test
public void shouldUseSensibleDefaultsOnClassWithNoDbUnitConfiguration() throws Exception {
addBean("dbUnitDatabaseConnection", this.databaseConnection);
addBean("dbUnitDatabaseConnection", databaseConnection);
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NoDbUnitConfiguration.class);
testContextManager.prepareTestInstance();
DatabaseConnections databaseConnections = (DatabaseConnections) testContextManager
.getTestContextAttribute(DbUnitTestExecutionListener.CONNECTION_ATTRIBUTE);
assertSame(this.databaseConnection, databaseConnections.get("dbUnitDatabaseConnection"));
assertSame(databaseConnection, databaseConnections.get("dbUnitDatabaseConnection"));
assertEquals(FlatXmlDataSetLoader.class, testContextManager
.getTestContextAttribute(DbUnitTestExecutionListener.DATA_SET_LOADER_ATTRIBUTE).getClass());
assertEquals(DefaultDatabaseOperationLookup.class, testContextManager
Expand All @@ -101,19 +101,19 @@ public void shouldTryBeanFactoryForCommonBeanNamesWithEmptyDatabaseConnection()
}

private void testCommonBeanNames(Class<?> testClass) throws Exception {
addBean("dataSource", this.dataSource);
addBean("dataSource", dataSource);
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(testClass);
testContextManager.prepareTestInstance();
verify(this.applicationContext).containsBean("dbUnitDataSetLoader");
verify(this.applicationContext).containsBean("dbUnitDatabaseConnection");
verify(this.applicationContext).containsBean("dataSource");
verify(this.applicationContext).getBean("dataSource");
verifyNoMoreInteractions(this.applicationContext);
verify(applicationContext).containsBean("dbUnitDataSetLoader");
verify(applicationContext).containsBean("dbUnitDatabaseConnection");
verify(applicationContext).containsBean("dataSource");
verify(applicationContext).getBean("dataSource");
verifyNoMoreInteractions(applicationContext);
}

@Test
public void shouldConvertDatasetDatabaseConnection() throws Exception {
addBean("dataSource", this.dataSource);
addBean("dataSource", dataSource);
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NoDbUnitConfiguration.class);
testContextManager.prepareTestInstance();
DatabaseConnections databaseConnections = (DatabaseConnections) testContextManager
Expand Down Expand Up @@ -146,13 +146,13 @@ public void shouldFailIfDatabaseConnectionOfWrongTypeIsFound() throws Exception

@Test
public void shouldSupportAllDbUnitConfigurationAttributes() throws Exception {
addBean("customBean", this.databaseConnection);
addBean("customBean", databaseConnection);
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(CustomConfiguration.class);
testContextManager.prepareTestInstance();
verify(this.applicationContext).getBean("customBean");
verify(applicationContext).getBean("customBean");
DatabaseConnections databaseConnections = (DatabaseConnections) testContextManager
.getTestContextAttribute(DbUnitTestExecutionListener.CONNECTION_ATTRIBUTE);
assertSame(this.databaseConnection, databaseConnections.get("customBean"));
assertSame(databaseConnection, databaseConnections.get("customBean"));
assertEquals(CustomDataSetLoader.class, testContextManager
.getTestContextAttribute(DbUnitTestExecutionListener.DATA_SET_LOADER_ATTRIBUTE).getClass());
assertEquals(CustomDatabaseOperationLookup.class, testContextManager
Expand All @@ -161,7 +161,7 @@ public void shouldSupportAllDbUnitConfigurationAttributes() throws Exception {

@Test
public void shouldFailIfDatasetLoaderCannotBeCreated() throws Exception {
addBean("dbUnitDatabaseConnection", this.databaseConnection);
addBean("dbUnitDatabaseConnection", databaseConnection);
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NonCreatableDataSetLoader.class);
try {
testContextManager.prepareTestInstance();
Expand All @@ -174,7 +174,7 @@ public void shouldFailIfDatasetLoaderCannotBeCreated() throws Exception {

@Test
public void shouldSupportCustomLoaderBean() throws Exception {
addBean("dataSource", this.dataSource);
addBean("dataSource", dataSource);
addBean("dbUnitDataSetLoader", new CustomDataSetLoader());
ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(EmptyDbUnitConfiguration.class);
testContextManager.prepareTestInstance();
Expand Down
Loading

0 comments on commit fb6ed00

Please sign in to comment.