Skip to content

Commit 5427f9c

Browse files
committed
move unit test support to his own project
1 parent 406f349 commit 5427f9c

File tree

18 files changed

+163
-108
lines changed

18 files changed

+163
-108
lines changed

jooby/pom.xml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,6 @@
110110
</executions>
111111
</plugin>
112112

113-
<plugin>
114-
<groupId>org.apache.maven.plugins</groupId>
115-
<artifactId>maven-jar-plugin</artifactId>
116-
<executions>
117-
<execution>
118-
<goals>
119-
<goal>test-jar</goal>
120-
</goals>
121-
<configuration>
122-
<includes>
123-
<include>io/jooby/*</include>
124-
</includes>
125-
<excludes>
126-
<exclude>**/*Test.*</exclude>
127-
<exclude>**/*Test$*.*</exclude>
128-
<exclude>**/internal</exclude>
129-
</excludes>
130-
</configuration>
131-
</execution>
132-
</executions>
133-
</plugin>
134-
135113
<!-- sure-fire -->
136114
<plugin>
137115
<groupId>org.apache.maven.plugins</groupId>
@@ -263,6 +241,12 @@
263241
<artifactId>logback-classic</artifactId>
264242
<scope>test</scope>
265243
</dependency>
244+
245+
<dependency>
246+
<groupId>org.mockito</groupId>
247+
<artifactId>mockito-core</artifactId>
248+
<scope>test</scope>
249+
</dependency>
266250
</dependencies>
267251

268252
</project>

jooby/src/test/java/io/jooby/internal/ChiTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.jooby.internal;
22

3+
import static org.mockito.Mockito.mock;
4+
35
import io.jooby.Context;
4-
import io.jooby.MockContext;
56
import io.jooby.Renderer;
67
import io.jooby.Route;
78
import io.jooby.Throwing;
@@ -11,6 +12,7 @@
1112

1213
import static org.junit.jupiter.api.Assertions.assertEquals;
1314
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
import static org.mockito.Mockito.when;
1416

1517
public class ChiTest {
1618

@@ -23,12 +25,19 @@ public void routeOverride() {
2325
router.insert(bar);
2426

2527
RouterMatch result = router
26-
.find(new MockContext().setPathString("/abcd"), Renderer.TO_STRING,
28+
.find(ctx("/abcd"), Renderer.TO_STRING,
2729
Collections.emptyList());
2830
assertTrue(result.matches);
2931
assertEquals(bar, result.route());
3032
}
3133

34+
private Context ctx(String path) {
35+
Context context = mock(Context.class);
36+
when(context.pathString()).thenReturn(path);
37+
when(context.getMethod()).thenReturn("GET");
38+
return context;
39+
}
40+
3241
@Test
3342
public void routeCase() {
3443
$Chi router = new $Chi();
@@ -39,7 +48,7 @@ public void routeCase() {
3948
router.insert(foos);
4049

4150
RouterMatch result = router
42-
.find(new MockContext().setPathString("/abcd/"), Renderer.TO_STRING,
51+
.find(ctx("/abcd/"), Renderer.TO_STRING,
4352
Collections.emptyList());
4453
assertTrue(result.matches);
4554
assertEquals(foos, result.route());
@@ -73,8 +82,9 @@ public void wildOnRoot() throws Exception {
7382
});
7483
}
7584

76-
private void find($Chi router, String pattern, Throwing.Consumer2<Context, RouterMatch> consumer) {
77-
Context rootctx = new MockContext().setPathString(pattern);
85+
private void find($Chi router, String pattern,
86+
Throwing.Consumer2<Context, RouterMatch> consumer) {
87+
Context rootctx = ctx(pattern);
7888
RouterMatch result = router
7989
.find(rootctx, Renderer.TO_STRING, Collections.emptyList());
8090
consumer.accept(rootctx, result);

modules/jooby-freemarker/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@
5353

5454
<dependency>
5555
<groupId>io.jooby</groupId>
56-
<artifactId>jooby</artifactId>
56+
<artifactId>jooby-test</artifactId>
5757
<version>${jooby.version}</version>
58-
<classifier>tests</classifier>
5958
<scope>test</scope>
6059
</dependency>
6160
</dependencies>

modules/jooby-guice/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,5 @@
4444
<classifier>runtime</classifier>
4545
<scope>test</scope>
4646
</dependency>
47-
48-
<dependency>
49-
<groupId>com.squareup.okhttp3</groupId>
50-
<artifactId>okhttp</artifactId>
51-
<scope>test</scope>
52-
</dependency>
53-
54-
<dependency>
55-
<groupId>io.jooby</groupId>
56-
<artifactId>jooby</artifactId>
57-
<version>${jooby.version}</version>
58-
<classifier>tests</classifier>
59-
<scope>test</scope>
60-
</dependency>
6147
</dependencies>
6248
</project>

modules/jooby-handlebars/pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353

5454
<dependency>
5555
<groupId>io.jooby</groupId>
56-
<artifactId>jooby</artifactId>
57-
<version>${jooby.version}</version>
58-
<classifier>tests</classifier>
56+
<artifactId>jooby-test</artifactId>
5957
<scope>test</scope>
6058
</dependency>
6159
</dependencies>

modules/jooby-hikari/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,5 @@
6464
<artifactId>log4jdbc</artifactId>
6565
<scope>test</scope>
6666
</dependency>
67-
68-
<dependency>
69-
<groupId>io.jooby</groupId>
70-
<artifactId>jooby</artifactId>
71-
<version>${jooby.version}</version>
72-
<classifier>tests</classifier>
73-
<scope>test</scope>
74-
</dependency>
7567
</dependencies>
7668
</project>

modules/jooby-jackson/pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@
7272
</dependency>
7373

7474
<dependency>
75-
<groupId>io.jooby</groupId>
76-
<artifactId>jooby</artifactId>
77-
<version>${jooby.version}</version>
78-
<classifier>tests</classifier>
75+
<groupId>org.mockito</groupId>
76+
<artifactId>mockito-core</artifactId>
7977
<scope>test</scope>
8078
</dependency>
8179
</dependencies>

modules/jooby-jackson/src/test/java/io/jooby/json/JacksonTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
package io.jooby.json;
22

3-
import io.jooby.MockContext;
3+
import io.jooby.Body;
4+
import io.jooby.Context;
5+
import io.jooby.MediaType;
46
import org.junit.jupiter.api.Test;
57

68
import java.nio.charset.StandardCharsets;
79
import java.util.HashMap;
810
import java.util.Map;
911

1012
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.mockito.Mockito.mock;
14+
import static org.mockito.Mockito.verify;
15+
import static org.mockito.Mockito.when;
1216

1317
public class JacksonTest {
1418

1519
@Test
1620
public void render() throws Exception {
21+
Context ctx = mock(Context.class);
22+
1723
Jackson jackson = new Jackson();
18-
MockContext ctx = new MockContext();
19-
byte [] bytes = jackson.render(ctx, mapOf("k", "v"));
24+
25+
byte[] bytes = jackson.render(ctx, mapOf("k", "v"));
2026
assertEquals("{\"k\":\"v\"}", new String(bytes, StandardCharsets.UTF_8));
21-
/** Type: */
22-
assertEquals("application/json", ctx.getResponseContentType().getValue());
23-
assertEquals("utf-8", ctx.getResponseCharset().name().toLowerCase());
27+
28+
verify(ctx).setDefaultContentType(MediaType.json);
2429
}
2530

2631
@Test
2732
public void parse() throws Exception {
33+
byte[] bytes = "{\"k\":\"v\"}".getBytes(StandardCharsets.UTF_8);
34+
Body body = mock(Body.class);
35+
when(body.isInMemory()).thenReturn(true);
36+
when(body.bytes()).thenReturn(bytes);
37+
38+
Context ctx = mock(Context.class);
39+
when(ctx.body()).thenReturn(body);
40+
2841
Jackson jackson = new Jackson();
29-
MockContext ctx = new MockContext();
30-
ctx.setBody("{\"k\":\"v\"}".getBytes(StandardCharsets.UTF_8));
3142

3243
Map<String, String> result = jackson.parse(ctx, Map.class);
3344
assertEquals(mapOf("k", "v"), result);

modules/jooby-rocker/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,5 @@
5858
<artifactId>okhttp</artifactId>
5959
<scope>test</scope>
6060
</dependency>
61-
62-
<dependency>
63-
<groupId>io.jooby</groupId>
64-
<artifactId>jooby</artifactId>
65-
<version>${jooby.version}</version>
66-
<classifier>tests</classifier>
67-
<scope>test</scope>
68-
</dependency>
6961
</dependencies>
7062
</project>

modules/jooby-spring/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,5 @@
5151
<scope>test</scope>
5252
</dependency>
5353

54-
<dependency>
55-
<groupId>io.jooby</groupId>
56-
<artifactId>jooby</artifactId>
57-
<version>${jooby.version}</version>
58-
<classifier>tests</classifier>
59-
<scope>test</scope>
60-
</dependency>
6154
</dependencies>
6255
</project>

0 commit comments

Comments
 (0)