Skip to content

Commit 1b2212a

Browse files
committed
more unit/test & coverage
1 parent 31d8866 commit 1b2212a

File tree

8 files changed

+266
-100
lines changed

8 files changed

+266
-100
lines changed

jooby-aws/src/main/java/org/jooby/internal/aws/AwsGenericManaged.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void stop() throws Exception {
6666
log.debug("no shutdown method found for: {}", dep);
6767
}
6868
} catch (InvocationTargetException ex) {
69-
throw Throwables.propagate(ex.getCause());
69+
Throwables.propagate(ex.getCause());
7070
} finally {
7171
dep = null;
7272
}

jooby-jackson/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
</dependency>
5656

5757
<!-- Test dependencies -->
58+
<dependency>
59+
<groupId>org.jooby</groupId>
60+
<artifactId>jooby</artifactId>
61+
<version>${project.version}</version>
62+
<scope>test</scope>
63+
<classifier>tests</classifier>
64+
</dependency>
65+
5866
<dependency>
5967
<groupId>junit</groupId>
6068
<artifactId>junit</artifactId>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.jooby.json;
2+
3+
import static org.easymock.EasyMock.expect;
4+
5+
import org.jooby.MediaType;
6+
import org.jooby.Parser;
7+
import org.jooby.Parser.Context;
8+
import org.jooby.test.MockUnit;
9+
import org.junit.Test;
10+
11+
import com.fasterxml.jackson.databind.JavaType;
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import com.google.inject.TypeLiteral;
14+
15+
public class JacksonParserTest {
16+
17+
@Test
18+
public void parseAny() throws Exception {
19+
Object value = new Object();
20+
new MockUnit(ObjectMapper.class, Parser.Context.class, MediaType.class)
21+
.expect(unit -> {
22+
MediaType type = unit.get(MediaType.class);
23+
expect(type.isAny()).andReturn(true);
24+
25+
Context ctx = unit.get(Parser.Context.class);
26+
expect(ctx.type()).andReturn(type);
27+
expect(ctx.next()).andReturn(value);
28+
})
29+
.run(unit -> {
30+
new JacksonParser(unit.get(ObjectMapper.class), MediaType.json)
31+
.parse(TypeLiteral.get(JacksonParserTest.class), unit.get(Parser.Context.class));
32+
});
33+
}
34+
35+
@Test
36+
public void parseSkip() throws Exception {
37+
Object value = new Object();
38+
new MockUnit(ObjectMapper.class, Parser.Context.class, MediaType.class, TypeLiteral.class)
39+
.expect(unit -> {
40+
MediaType type = unit.get(MediaType.class);
41+
expect(type.isAny()).andReturn(false);
42+
43+
Context ctx = unit.get(Parser.Context.class);
44+
expect(ctx.type()).andReturn(type);
45+
expect(ctx.next()).andReturn(value);
46+
47+
JavaType javaType = unit.mock(JavaType.class);
48+
49+
ObjectMapper mapper = unit.get(ObjectMapper.class);
50+
expect(mapper.constructType(null)).andReturn(javaType);
51+
})
52+
.run(unit -> {
53+
new JacksonParser(unit.get(ObjectMapper.class), MediaType.json)
54+
.parse(unit.get(TypeLiteral.class), unit.get(Parser.Context.class));
55+
});
56+
}
57+
}

jooby-jade/src/test/java/org/jooby/jade/JadeTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public void testConfigurableSuffix() throws Exception {
5252
});
5353
}
5454

55+
@Test
56+
public void testCachingOn() throws Exception {
57+
new MockUnit(Env.class, Config.class, Binder.class)
58+
.expect(env("prod"))
59+
.expect(conf(".jade", true, false))
60+
.expect(jade(".jade", true, false))
61+
.run(unit -> {
62+
new Jade()
63+
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
64+
});
65+
}
66+
5567
@Test
5668
public void testCachingOnInProduction() throws Exception {
5769
new MockUnit(Env.class, Config.class, Binder.class)
@@ -142,6 +154,9 @@ private Block conf(final String suffix, final boolean caching, final boolean pre
142154
return unit -> {
143155
Config config = unit.get(Config.class);
144156
expect(config.hasPath("jade.caching")).andReturn(caching);
157+
if (caching) {
158+
expect(config.getBoolean("jade.caching")).andReturn(caching);
159+
}
145160
expect(config.hasPath("jade.prettyprint")).andReturn(prettyprint);
146161
};
147162
}

jooby-jdbc/src/main/java/org/jooby/jdbc/Jdbc.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@
148148
* }
149149
* </pre>
150150
*
151-
* <p>application.conf</p>
151+
* <p>
152+
* application.conf
153+
* </p>
152154
*
153155
* <pre>
154156
* # main database
@@ -162,7 +164,9 @@
162164
* db.audit.password = ....
163165
* </pre>
164166
*
165-
* <p>Same principle applies if you need to tweak hikari:</p>
167+
* <p>
168+
* Same principle applies if you need to tweak hikari:
169+
* </p>
166170
*
167171
* <pre>
168172
* # max pool size for main db
@@ -222,8 +226,7 @@ private Config dbConfig(final String key, final Config source) {
222226
if (db.toString().indexOf(':') == -1 && source.hasPath(embeddeddb)) {
223227
Config dbtree = source.getConfig(embeddeddb);
224228
dbtree = dbtree.withValue("url", ConfigValueFactory.fromAnyRef(
225-
dbtree.getString("url").replace("{mem.seed}", System.currentTimeMillis() + "")
226-
));
229+
dbtree.getString("url").replace("{mem.seed}", System.currentTimeMillis() + "")));
227230
// write embedded with current key
228231
return ConfigFactory.empty()
229232
.withValue(key, dbtree.root())
@@ -266,10 +269,8 @@ private HikariDataSourceProvider newDataSource(final String key, final Config co
266269
* # db.* -> dataSource.*
267270
* # hikari.* -> * (no prefix)
268271
*/
269-
dbtype.ifPresent(type ->
270-
config.getConfig("databases." + type)
271-
.entrySet().forEach(entry -> dumper.accept("dataSource.", entry))
272-
);
272+
dbtype.ifPresent(type -> config.getConfig("databases." + type)
273+
.entrySet().forEach(entry -> dumper.accept("dataSource.", entry)));
273274

274275
config.getConfig(key).entrySet().forEach(entry -> dumper.accept("dataSource.", entry));
275276

@@ -294,10 +295,7 @@ private Optional<String> dbtype(final String key, final Config config) {
294295
.findFirst()
295296
.get();
296297

297-
if (config.hasPath("databases." + type)) {
298-
return Optional.of(type);
299-
}
300-
return Optional.empty();
298+
return Optional.of(type);
301299
}
302300

303301
/**

0 commit comments

Comments
 (0)