Skip to content

Commit 9553c5a

Browse files
committed
add other versions of java to test pipeline
1 parent 421a03a commit 9553c5a

File tree

7 files changed

+64
-62
lines changed

7 files changed

+64
-62
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
java: [8]
9+
java: [8, 11, 15]
1010
steps:
1111
- name: Checkout project
1212
uses: actions/checkout@v1

build.gradle

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ ext {
2222
[name: '5.3.1', spring: '5.3.1', 'zonky-postgres': 'default', opentable: 'default', yandex: 'default', 'mssql-driver': 'default', 'mysql-driver': 'default', 'mariadb-driver': 'default']
2323
]],
2424
[name: 'flyway', versions: [
25-
[name: '3.0', flyway: '3.0', 'flyway-test': '3.0.1', spring: '4.3.8.RELEASE', 'spring-boot': '1.4.6.RELEASE', 'zonky-postgres': 'default'],
26-
[name: '3.1', flyway: '3.1', 'flyway-test': '3.1', spring: '4.3.8.RELEASE', 'spring-boot': '1.4.6.RELEASE', 'zonky-postgres': 'default'],
27-
[name: '3.2.1', flyway: '3.2.1', 'flyway-test': '3.2.1.1', spring: '4.3.8.RELEASE', 'spring-boot': '1.4.6.RELEASE', 'zonky-postgres': 'default'],
2825
[name: '4.0.3', flyway: '4.0.3', 'flyway-test': '4.0.1', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE', 'zonky-postgres': 'default'],
2926
[name: '4.1.2', flyway: '4.1.2', 'flyway-test': '4.1.0', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE', 'zonky-postgres': 'default'],
3027
[name: '4.2.0', flyway: '4.2.0', 'flyway-test': '4.2.0.2', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE', 'zonky-postgres': 'default'],
@@ -46,7 +43,6 @@ ext {
4643
[name: 'no_sb', flyway: 'default', 'flyway-test': 'default', 'zonky-postgres': 'default']
4744
]],
4845
[name: 'liquibase', versions: [
49-
[name: '3.5.3', liquibase: '3.5.3', spring: '4.3.8.RELEASE', 'spring-boot': '1.4.6.RELEASE'],
5046
[name: '3.5.5', liquibase: '3.5.5', spring: '4.3.25.RELEASE', 'spring-boot': '1.5.22.RELEASE'],
5147
[name: '3.6.3', liquibase: '3.6.3', spring: '5.1.19.RELEASE', 'spring-boot': '2.1.18.RELEASE'],
5248
[name: '3.7.0', liquibase: '3.7.0', spring: '5.1.19.RELEASE', 'spring-boot': '2.1.18.RELEASE'],
@@ -211,11 +207,11 @@ project(':embedded-database-spring-test') {
211207

212208
compile 'org.flywaydb:flyway-core:7.3.0', optional
213209
compile 'org.flywaydb.flyway-test-extensions:flyway-spring-test:7.0.0', optional
214-
compile 'org.springframework.boot:spring-boot-starter-test:1.5.22.RELEASE', optional
210+
compile 'org.springframework.boot:spring-boot-starter-test:2.0.9.RELEASE', optional
215211
compile 'org.liquibase:liquibase-core:3.5.5', optional
216212

217-
compile 'org.springframework:spring-context:4.3.25.RELEASE'
218-
compile 'org.springframework:spring-test:4.3.25.RELEASE'
213+
compile 'org.springframework:spring-context:5.0.13.RELEASE'
214+
compile 'org.springframework:spring-test:5.0.13.RELEASE'
219215
compile 'com.google.guava:guava:23.0'
220216

221217
compile 'org.apache.commons:commons-lang3:3.4' // TODO
@@ -225,9 +221,9 @@ project(':embedded-database-spring-test') {
225221
exclude group: 'org.apache.logging.log4j'
226222
}
227223

228-
testCompile 'org.springframework:spring-jdbc:4.3.25.RELEASE'
224+
testCompile 'org.springframework:spring-jdbc:5.0.13.RELEASE'
229225
testCompile 'ch.qos.logback:logback-classic:1.2.3'
230-
testCompile 'org.mockito:mockito-core:1.10.19'
226+
testCompile 'org.mockito:mockito-core:3.9.0'
231227
testCompile 'org.assertj:assertj-core:3.18.1'
232228
}
233229

embedded-database-spring-test/src/test/java/io/zonky/test/db/DatabaseRefreshIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77
import org.junit.runner.RunWith;
88
import org.mockito.Mockito;
9+
import org.springframework.beans.factory.InitializingBean;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.beans.factory.config.BeanPostProcessor;
1112
import org.springframework.context.ApplicationContext;
@@ -22,7 +23,6 @@
2223
import org.springframework.test.context.junit4.SpringRunner;
2324
import org.springframework.test.context.support.AbstractTestExecutionListener;
2425

25-
import javax.annotation.PostConstruct;
2626
import javax.sql.DataSource;
2727
import java.util.List;
2828
import java.util.Map;
@@ -68,7 +68,7 @@ public BeanPostProcessor spyPostProcessor() {
6868
}
6969
}
7070

71-
public static class TestDatabaseInitializer {
71+
public static class TestDatabaseInitializer implements InitializingBean {
7272

7373
private final DataSource dataSource;
7474
private final ResourceLoader resourceLoader;
@@ -78,8 +78,8 @@ public TestDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoa
7878
this.resourceLoader = resourceLoader;
7979
}
8080

81-
@PostConstruct
82-
public void init() {
81+
@Override
82+
public void afterPropertiesSet() throws Exception {
8383
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
8484
populator.addScript(this.resourceLoader.getResource("db/create_address_table.sql"));
8585
DatabasePopulatorUtils.execute(populator, this.dataSource);

embedded-database-spring-test/src/test/java/io/zonky/test/db/DatabaseRefreshPropertyIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77
import org.junit.runner.RunWith;
88
import org.mockito.Mockito;
9+
import org.springframework.beans.factory.InitializingBean;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.beans.factory.config.BeanPostProcessor;
1112
import org.springframework.context.ApplicationContext;
@@ -23,7 +24,6 @@
2324
import org.springframework.test.context.junit4.SpringRunner;
2425
import org.springframework.test.context.support.AbstractTestExecutionListener;
2526

26-
import javax.annotation.PostConstruct;
2727
import javax.sql.DataSource;
2828
import java.util.List;
2929
import java.util.Map;
@@ -69,7 +69,7 @@ public BeanPostProcessor spyPostProcessor() {
6969
}
7070
}
7171

72-
public static class TestDatabaseInitializer {
72+
public static class TestDatabaseInitializer implements InitializingBean {
7373

7474
private final DataSource dataSource;
7575
private final ResourceLoader resourceLoader;
@@ -79,8 +79,8 @@ public TestDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoa
7979
this.resourceLoader = resourceLoader;
8080
}
8181

82-
@PostConstruct
83-
public void init() {
82+
@Override
83+
public void afterPropertiesSet() throws Exception {
8484
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
8585
populator.addScript(this.resourceLoader.getResource("db/create_address_table.sql"));
8686
DatabasePopulatorUtils.execute(populator, this.dataSource);

embedded-database-spring-test/src/test/java/io/zonky/test/db/context/DefaultProviderResolverTest.java

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
import io.zonky.test.db.support.DatabaseDefinition;
88
import io.zonky.test.db.support.DefaultProviderResolver;
99
import io.zonky.test.db.support.ProviderDescriptor;
10+
import org.junit.Before;
1011
import org.junit.Test;
1112
import org.junit.experimental.categories.Category;
1213
import org.junit.runner.RunWith;
1314
import org.mariadb.jdbc.MariaDbDataSource;
14-
import org.mockito.InjectMocks;
1515
import org.mockito.Mock;
1616
import org.mockito.runners.MockitoJUnitRunner;
1717
import org.postgresql.ds.PGSimpleDataSource;
1818
import org.springframework.core.env.Environment;
1919

20+
import java.util.HashSet;
21+
import java.util.Set;
22+
2023
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider;
2124
import static org.assertj.core.api.Assertions.assertThat;
2225
import static org.assertj.core.api.Assertions.assertThatCode;
23-
import static org.mockito.Matchers.any;
24-
import static org.mockito.Mockito.doReturn;
25-
import static org.mockito.Mockito.doThrow;
26-
import static org.mockito.Mockito.verifyZeroInteractions;
26+
import static org.mockito.Mockito.verifyNoInteractions;
2727
import static org.mockito.Mockito.when;
2828

2929
@RunWith(MockitoJUnitRunner.class)
@@ -32,20 +32,25 @@ public class DefaultProviderResolverTest {
3232

3333
@Mock
3434
private Environment environment;
35-
@Mock
36-
private ClassLoader classLoader;
3735

38-
@InjectMocks
36+
private TestClassLoader classLoader;
37+
3938
private DefaultProviderResolver resolver;
4039

40+
@Before
41+
public void setUp() throws Exception {
42+
classLoader = new TestClassLoader();
43+
resolver = new DefaultProviderResolver(environment, classLoader);
44+
}
45+
4146
@Test
4247
public void explicitParameters() {
4348
ProviderDescriptor descriptor = resolver.getDescriptor(new DatabaseDefinition("", DatabaseType.MSSQL, DatabaseProvider.DOCKER));
4449

4550
assertThat(descriptor.getDatabaseName()).isEqualTo("mssql");
4651
assertThat(descriptor.getProviderName()).isEqualTo("docker");
4752

48-
verifyZeroInteractions(environment, classLoader);
53+
verifyNoInteractions(environment);
4954
}
5055

5156
@Test
@@ -60,12 +65,11 @@ public void configurationProperties() {
6065
}
6166

6267
@Test
63-
public void configurationPropertiesContainingDefaultValues() throws ClassNotFoundException {
68+
public void configurationPropertiesContainingDefaultValues() {
6469
when(environment.getProperty("zonky.test.database.type")).thenReturn("auto");
6570
when(environment.getProperty("zonky.test.database.provider", "docker")).thenReturn("default");
6671

67-
doThrow(ClassNotFoundException.class).when(classLoader).loadClass(any());
68-
doReturn(SQLServerDataSource.class).when(classLoader).loadClass("com.microsoft.sqlserver.jdbc.SQLServerDataSource");
72+
classLoader.addClass(SQLServerDataSource.class);
6973

7074
ProviderDescriptor descriptor = resolver.getDescriptor(new DatabaseDefinition("", DatabaseType.AUTO, DatabaseProvider.DEFAULT));
7175

@@ -74,9 +78,8 @@ public void configurationPropertiesContainingDefaultValues() throws ClassNotFoun
7478
}
7579

7680
@Test
77-
public void autoDetectionMode() throws ClassNotFoundException {
78-
doThrow(ClassNotFoundException.class).when(classLoader).loadClass(any());
79-
doReturn(MysqlDataSource.class).when(classLoader).loadClass("com.mysql.cj.jdbc.MysqlDataSource");
81+
public void autoDetectionMode() {
82+
classLoader.addClass(MysqlDataSource.class);
8083

8184
ProviderDescriptor descriptor = resolver.getDescriptor(new DatabaseDefinition("", DatabaseType.AUTO, DatabaseProvider.DEFAULT));
8285

@@ -85,22 +88,35 @@ public void autoDetectionMode() throws ClassNotFoundException {
8588
}
8689

8790
@Test
88-
public void noDatabaseDetected() throws ClassNotFoundException {
89-
doThrow(ClassNotFoundException.class).when(classLoader).loadClass(any());
90-
91+
public void noDatabaseDetected() {
9192
assertThatCode(() -> resolver.getDescriptor(new DatabaseDefinition("", DatabaseType.AUTO, DatabaseProvider.DEFAULT)))
9293
.isExactlyInstanceOf(IllegalStateException.class)
9394
.hasMessageContaining("no database driver detected");
9495
}
9596

9697
@Test
97-
public void multipleDatabasesDetected() throws ClassNotFoundException {
98-
doThrow(ClassNotFoundException.class).when(classLoader).loadClass(any());
99-
doReturn(PGSimpleDataSource.class).when(classLoader).loadClass("org.postgresql.ds.PGSimpleDataSource");
100-
doReturn(MariaDbDataSource.class).when(classLoader).loadClass("org.mariadb.jdbc.MariaDbDataSource");
98+
public void multipleDatabasesDetected() {
99+
classLoader.addClass(PGSimpleDataSource.class);
100+
classLoader.addClass(MariaDbDataSource.class);
101101

102102
assertThatCode(() -> resolver.getDescriptor(new DatabaseDefinition("", DatabaseType.AUTO, DatabaseProvider.DEFAULT)))
103103
.isExactlyInstanceOf(IllegalStateException.class)
104104
.hasMessageContaining("multiple database drivers detected");
105105
}
106+
107+
private static class TestClassLoader extends ClassLoader {
108+
109+
private final Set<Class<?>> availableClasses = new HashSet<>();
110+
111+
public void addClass(Class<?> clazz) {
112+
availableClasses.add(clazz);
113+
}
114+
115+
@Override
116+
public Class<?> loadClass(String name) throws ClassNotFoundException {
117+
return availableClasses.stream()
118+
.filter(cls -> cls.getName().equals(name))
119+
.findAny().orElseThrow(ClassNotFoundException::new);
120+
}
121+
}
106122
}

embedded-database-spring-test/src/test/java/io/zonky/test/db/preparer/RecordingDataSourceTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,12 @@ public void testBlobType() throws SQLException {
235235
// it is not possible to use Mockito#verify method
236236
// because the verification must take place immediately
237237
// when the PreparedStatement#setBlob method is called
238-
doNothing().when(mockStatement).setBlob(eq(1), argThat(new ArgumentMatcher<Blob>() {
239-
@Override
240-
public boolean matches(Object argument) {
241-
try {
242-
Blob blob = (Blob) argument;
243-
byte[] bytes = blob.getBytes(1, 4);
244-
return Arrays.equals(bytes, new byte[] { 0, 1, 2, 3 });
245-
} catch (SQLException e) {
246-
throw new RuntimeException(e);
247-
}
238+
doNothing().when(mockStatement).setBlob(eq(1), argThat((ArgumentMatcher<Blob>) blob1 -> {
239+
try {
240+
byte[] bytes = blob1.getBytes(1, 4);
241+
return Arrays.equals(bytes, new byte[] { 0, 1, 2, 3 });
242+
} catch (SQLException e) {
243+
throw new RuntimeException(e);
248244
}
249245
}));
250246

@@ -299,7 +295,7 @@ public void testInputStream() throws SQLException {
299295
DataSource targetDataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
300296
PreparedStatement preparedStatement = targetDataSource.getConnection().prepareStatement(any());
301297
doAnswer(invocation -> {
302-
InputStream stream = invocation.getArgumentAt(1, InputStream.class);
298+
InputStream stream = invocation.getArgument(1, InputStream.class);
303299
byte[] bytes = IOUtils.readFully(stream, 4);
304300
checkState(Arrays.equals(bytes, new byte[] { 0, 1, 2, 3 }));
305301
return null;
@@ -323,7 +319,7 @@ public void testInputStream() throws SQLException {
323319
when(mockConnection.prepareStatement(any())).thenReturn(mockStatement);
324320

325321
doAnswer(invocation -> {
326-
InputStream stream = invocation.getArgumentAt(1, InputStream.class);
322+
InputStream stream = invocation.getArgument(1, InputStream.class);
327323
byte[] bytes = IOUtils.readFully(stream, 4);
328324
checkState(Arrays.equals(bytes, new byte[] { 0, 1, 2, 3 }));
329325
return null;
@@ -340,7 +336,7 @@ public void testReader() throws SQLException {
340336
DataSource targetDataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
341337
PreparedStatement preparedStatement = targetDataSource.getConnection().prepareStatement(any());
342338
doAnswer(invocation -> {
343-
Reader reader = invocation.getArgumentAt(1, Reader.class);
339+
Reader reader = invocation.getArgument(1, Reader.class);
344340
checkState("test".equals(IOUtils.toString(reader)));
345341
return null;
346342
}).when(preparedStatement).setCharacterStream(anyInt(), any());
@@ -363,7 +359,7 @@ public void testReader() throws SQLException {
363359
when(mockConnection.prepareStatement(any())).thenReturn(mockStatement);
364360

365361
doAnswer(invocation -> {
366-
Reader reader = invocation.getArgumentAt(1, Reader.class);
362+
Reader reader = invocation.getArgument(1, Reader.class);
367363
checkState("test".equals(IOUtils.toString(reader)));
368364
return null;
369365
}).when(mockStatement).setCharacterStream(eq(1), any());

embedded-database-spring-test/src/test/java/io/zonky/test/db/provider/TemplatingDatabaseProviderTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,8 @@ private static DatabaseRequest databaseRequest(DatabasePreparer preparer) {
154154
}
155155

156156
private static DatabaseRequest databaseRequest(DatabasePreparer preparer, DatabaseTemplate template) {
157-
return argThat(new ArgumentMatcher<DatabaseRequest>() {
158-
@Override
159-
public boolean matches(Object argument) {
160-
DatabaseRequest request = (DatabaseRequest) argument;
161-
return Objects.equals(request.getPreparer(), preparer)
162-
&& Objects.equals(request.getTemplate(), template);
163-
}
164-
});
157+
return argThat(request -> Objects.equals(request.getPreparer(), preparer)
158+
&& Objects.equals(request.getTemplate(), template));
165159
}
166160

167161
private static class TestDatabaseTemplate implements DatabaseTemplate {

0 commit comments

Comments
 (0)