Skip to content

Commit daa7d6d

Browse files
authored
Merge pull request #9 from JavaWebStack/TimothyGillespie/expandFactoryTest
Expand factory tests
2 parents a3f6160 + d4485b0 commit daa7d6d

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

src/test/java/org/javawebstack/orm/test/SQLDriverFactoryTest.java

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@
22

33
import static org.junit.jupiter.api.Assertions.*;
44

5+
import org.javawebstack.orm.wrapper.MySQL;
56
import org.javawebstack.orm.wrapper.SQLDriverFactory;
67
import org.javawebstack.orm.wrapper.SQLDriverNotFoundException;
8+
import org.junit.jupiter.api.BeforeEach;
79
import org.junit.jupiter.api.Test;
810

911
import java.util.HashMap;
12+
import java.util.Map;
1013

1114
class SQLDriverFactoryTest {
12-
private SQLDriverFactory factory = new SQLDriverFactory(new HashMap<String, String>() {{
13-
put("file", "sb.sqlite");
14-
put("host", "localhost");
15-
put("port", "3306");
16-
put("name", "app");
17-
put("user", "root");
18-
put("password", "");
19-
}});
2015

16+
private SQLDriverFactory factory;
17+
private final Map<String, String > configMap = new HashMap<String, String >(){
18+
{
19+
put("file", "sb.sqlite");
20+
put("host", "localhost");
21+
put("port", "3306");
22+
put("name", "app");
23+
put("user", "root");
24+
put("password", "");
25+
}
26+
};
27+
28+
29+
@BeforeEach
30+
public void beforeEach() {
31+
factory = new SQLDriverFactory(configMap);
32+
}
33+
34+
/*
35+
* Normal Cases
36+
*/
2137
@Test
2238
public void testSQLite() throws SQLDriverNotFoundException {
2339
assertNotNull(factory.getDriver("sqlite"));
@@ -27,4 +43,41 @@ public void testSQLite() throws SQLDriverNotFoundException {
2743
public void testMySQL() throws SQLDriverNotFoundException {
2844
assertNotNull(factory.getDriver("mysql"));
2945
}
46+
47+
@Test
48+
public void testRegisrtration() throws SQLDriverNotFoundException {
49+
factory.registerDriver("mariadb", () -> new MySQL(
50+
configMap.get("host"),
51+
Integer.parseInt(configMap.get("port")),
52+
configMap.get("name"),
53+
configMap.get("user"),
54+
configMap.get("password")
55+
));
56+
57+
assertNotNull(factory.getDriver("mariadb"));
58+
}
59+
60+
/*
61+
* Edge Cases
62+
*/
63+
64+
@Test
65+
public void testDriverNameIsCaseSensitive() {
66+
assertThrows(
67+
SQLDriverNotFoundException.class,
68+
() -> factory.getDriver("MySQL")
69+
);
70+
}
71+
72+
/*
73+
* Error Cases
74+
*/
75+
76+
@Test
77+
public void testCannotFindUninitializedDriver() {
78+
assertThrows(
79+
SQLDriverNotFoundException.class,
80+
() -> factory.getDriver("nodriver")
81+
);
82+
}
3083
}

0 commit comments

Comments
 (0)