Skip to content

Commit 2905edd

Browse files
committed
Getting rid of Mockito
1 parent 3ca64e0 commit 2905edd

19 files changed

Lines changed: 215 additions & 75 deletions

File tree

bootique-jdbc-hikaricp-instrumented/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@
6868
</dependency>
6969

7070
<!-- Unit test dependencies -->
71-
<dependency>
72-
<groupId>org.mockito</groupId>
73-
<artifactId>mockito-core</artifactId>
74-
<scope>test</scope>
75-
</dependency>
7671
<dependency>
7772
<groupId>org.apache.derby</groupId>
7873
<artifactId>derby</artifactId>

bootique-jdbc-hikaricp/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060
</dependency>
6161

6262
<!-- Unit test dependencies -->
63-
<dependency>
64-
<groupId>org.mockito</groupId>
65-
<artifactId>mockito-core</artifactId>
66-
<scope>test</scope>
67-
</dependency>
6863
<dependency>
6964
<groupId>io.bootique</groupId>
7065
<artifactId>bootique-junit5</artifactId>

bootique-jdbc-junit5-derby/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959
</dependency>
6060

6161
<!-- Unit test dependencies -->
62-
<dependency>
63-
<groupId>org.mockito</groupId>
64-
<artifactId>mockito-core</artifactId>
65-
<scope>test</scope>
66-
</dependency>
6762
<dependency>
6863
<groupId>org.slf4j</groupId>
6964
<artifactId>slf4j-simple</artifactId>

bootique-jdbc-junit5-testcontainers/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
</dependency>
6868

6969
<!-- Unit test dependencies -->
70-
<dependency>
71-
<groupId>org.mockito</groupId>
72-
<artifactId>mockito-core</artifactId>
73-
<scope>test</scope>
74-
</dependency>
7570
<dependency>
7671
<groupId>org.slf4j</groupId>
7772
<artifactId>slf4j-simple</artifactId>

bootique-jdbc-junit5/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@
7373
</dependency>
7474

7575
<!-- Unit test dependencies -->
76-
<dependency>
77-
<groupId>org.mockito</groupId>
78-
<artifactId>mockito-core</artifactId>
79-
<scope>test</scope>
80-
</dependency>
8176
<dependency>
8277
<groupId>org.slf4j</groupId>
8378
<artifactId>slf4j-simple</artifactId>

bootique-jdbc-junit5/src/main/java/io/bootique/jdbc/junit5/metadata/DbMetadata.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
*/
3535
public class DbMetadata {
3636

37-
private DataSource dataSource;
38-
private DbFlavor flavor;
39-
private Map<TableFQName, DbTableMetadata> tables;
37+
private final DataSource dataSource;
38+
private final DbFlavor flavor;
39+
private final Map<TableFQName, DbTableMetadata> tables;
4040

4141
protected DbMetadata(DataSource dataSource, DbFlavor flavor) {
4242

@@ -53,6 +53,13 @@ public static DbMetadata create(DataSource dataSource) {
5353
return new DbMetadata(dataSource, flavor);
5454
}
5555

56+
/**
57+
* @since 4.0
58+
*/
59+
public static DbMetadata create(DataSource dataSource, DbFlavor flavor) {
60+
return new DbMetadata(dataSource, flavor);
61+
}
62+
5663
public DbFlavor getFlavor() {
5764
return flavor;
5865
}

bootique-jdbc-junit5/src/main/java/io/bootique/jdbc/junit5/metadata/flavors/DbFlavor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public interface DbFlavor {
3535

3636
boolean supportsSchemas();
3737

38-
int columnType(int jdbcType, String nativeType);
38+
default int columnType(int jdbcType, String nativeType) {
39+
return jdbcType;
40+
}
3941

4042
default boolean shouldQuoteIdentifiers() {
4143
// per JDBC spec a space symboil means quotations ar enot supported

bootique-jdbc-junit5/src/main/java/io/bootique/jdbc/junit5/metadata/flavors/GenericFlavor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,4 @@ public boolean supportsCatalogs() {
7070
public boolean supportsSchemas() {
7171
return supportsSchemas;
7272
}
73-
74-
@Override
75-
public int columnType(int jdbcType, String nativeType) {
76-
return jdbcType;
77-
}
7873
}

bootique-jdbc-junit5/src/test/java/io/bootique/jdbc/junit5/TableTest.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,30 @@
2020
package io.bootique.jdbc.junit5;
2121

2222
import io.bootique.jdbc.junit5.connector.DbConnector;
23-
import io.bootique.jdbc.junit5.sql.ExecStatementBuilder;
24-
import io.bootique.jdbc.junit5.sql.InsertBuilder;
2523
import io.bootique.jdbc.junit5.dataset.TableDataSet;
2624
import io.bootique.jdbc.junit5.matcher.TableMatcher;
2725
import io.bootique.jdbc.junit5.metadata.DbColumnMetadata;
26+
import io.bootique.jdbc.junit5.metadata.DbMetadata;
2827
import io.bootique.jdbc.junit5.metadata.DbTableMetadata;
2928
import io.bootique.jdbc.junit5.metadata.TableFQName;
29+
import io.bootique.jdbc.junit5.metadata.flavors.DbFlavor;
30+
import io.bootique.jdbc.junit5.sql.InsertBuilder;
3031
import org.junit.jupiter.api.Test;
3132

33+
import javax.sql.DataSource;
3234
import java.util.Arrays;
3335
import java.util.List;
3436
import java.util.stream.Collectors;
3537

3638
import static java.util.Arrays.asList;
3739
import static org.junit.jupiter.api.Assertions.*;
38-
import static org.mockito.Mockito.mock;
39-
import static org.mockito.Mockito.when;
4040

4141
public class TableTest {
4242

4343
private Table createTable() {
4444

45-
ExecStatementBuilder mockExecBuilder = mock(ExecStatementBuilder.class);
46-
47-
DbConnector mockConnector = mock(DbConnector.class);
48-
when(mockConnector.execStatement()).thenReturn(mockExecBuilder);
45+
DataSource dataSource = new TestDataSource();
46+
DbConnector connector = new DbConnector(dataSource, DbMetadata.create(dataSource, new TestDbFlavor()));
4947

5048
DbColumnMetadata[] columns = new DbColumnMetadata[]{
5149
new DbColumnMetadata("a", DbColumnMetadata.NO_TYPE, false, true),
@@ -54,7 +52,7 @@ private Table createTable() {
5452
};
5553

5654
DbTableMetadata tableMetadata = new DbTableMetadata(new TableFQName(null, null, "t"), columns);
57-
return new Table(mockConnector, tableMetadata);
55+
return new Table(connector, tableMetadata);
5856
}
5957

6058
@Test
@@ -90,4 +88,31 @@ public void csvDataSet() {
9088
assertEquals(0, ds.size());
9189
}
9290

91+
static class TestDbFlavor implements DbFlavor {
92+
93+
@Override
94+
public String getIdentifierQuote() {
95+
return "";
96+
}
97+
98+
@Override
99+
public boolean supportsParamsMetadata() {
100+
return false;
101+
}
102+
103+
@Override
104+
public boolean supportsBatchUpdates() {
105+
return false;
106+
}
107+
108+
@Override
109+
public boolean supportsCatalogs() {
110+
return false;
111+
}
112+
113+
@Override
114+
public boolean supportsSchemas() {
115+
return false;
116+
}
117+
}
93118
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to ObjectStyle LLC under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ObjectStyle LLC licenses
6+
* this file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package io.bootique.jdbc.junit5;
20+
21+
import javax.sql.DataSource;
22+
import java.io.PrintWriter;
23+
import java.sql.Connection;
24+
import java.util.logging.Logger;
25+
26+
class TestDataSource implements DataSource {
27+
@Override
28+
public Connection getConnection() {
29+
return null;
30+
}
31+
32+
@Override
33+
public Connection getConnection(String username, String password) {
34+
return null;
35+
}
36+
37+
@Override
38+
public PrintWriter getLogWriter() {
39+
return null;
40+
}
41+
42+
@Override
43+
public void setLogWriter(PrintWriter out) {
44+
45+
}
46+
47+
@Override
48+
public void setLoginTimeout(int seconds) {
49+
50+
}
51+
52+
@Override
53+
public int getLoginTimeout() {
54+
return 0;
55+
}
56+
57+
@Override
58+
public <T> T unwrap(Class<T> iface) {
59+
return null;
60+
}
61+
62+
@Override
63+
public boolean isWrapperFor(Class<?> iface) {
64+
return false;
65+
}
66+
67+
@Override
68+
public Logger getParentLogger() {
69+
return null;
70+
}
71+
}

0 commit comments

Comments
 (0)