Skip to content

Commit b6e59c2

Browse files
authored
Refactor bootique (eugenp#2380)
1 parent 40b3cc7 commit b6e59c2

8 files changed

Lines changed: 67 additions & 74 deletions

File tree

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
package com.baeldung.bootique;
22

3-
import java.util.function.Supplier;
4-
53
import com.baeldung.bootique.module.ModuleBinder;
64
import com.baeldung.bootique.router.IndexController;
75
import com.baeldung.bootique.router.SaveController;
86
import com.google.inject.Module;
9-
107
import io.bootique.Bootique;
118
import io.bootique.jersey.JerseyModule;
129
import io.bootique.log.BootLogger;
1310

11+
import java.util.function.Supplier;
12+
1413
public class App {
1514

16-
public static void main(String[] args) {
17-
Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class)
18-
.addResource(SaveController.class);
19-
Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() {
20-
@Override
21-
public void trace(Supplier<String> arg0) {
22-
// ...
23-
}
24-
25-
@Override
26-
public void stdout(String arg0) {
27-
// ...
28-
}
29-
30-
@Override
31-
public void stderr(String arg0, Throwable arg1) {
32-
// ...
33-
}
34-
35-
@Override
36-
public void stderr(String arg0) {
37-
// ...
38-
}
39-
}).autoLoadModules().exec();
40-
}
15+
public static void main(String[] args) {
16+
Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class)
17+
.addResource(SaveController.class);
18+
Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() {
19+
@Override
20+
public void trace(Supplier<String> arg0) {
21+
// ...
22+
}
23+
24+
@Override
25+
public void stdout(String arg0) {
26+
// ...
27+
}
28+
29+
@Override
30+
public void stderr(String arg0, Throwable arg1) {
31+
// ...
32+
}
33+
34+
@Override
35+
public void stderr(String arg0) {
36+
// ...
37+
}
38+
}).autoLoadModules().exec();
39+
}
4140

4241
}

bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
public class ModuleBinder implements Module {
99

10-
@Override
11-
public void configure(Binder binder) {
12-
binder.bind(HelloService.class).to(HelloServiceImpl.class);
13-
}
10+
@Override
11+
public void configure(Binder binder) {
12+
binder.bind(HelloService.class).to(HelloServiceImpl.class);
13+
}
1414

1515
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.baeldung.bootique.module;
22

33
import com.google.inject.Module;
4-
54
import io.bootique.BQModuleProvider;
65

76
public class ModuleProvider implements BQModuleProvider {
87

9-
@Override
10-
public Module module() {
11-
return new ModuleBinder();
12-
}
8+
@Override
9+
public Module module() {
10+
return new ModuleBinder();
11+
}
1312

1413
}

bootique/src/main/java/com/baeldung/bootique/router/IndexController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
@Path("/")
77
public class IndexController {
8-
9-
@GET
10-
public String index() {
11-
return "Hello, baeldung!";
12-
}
8+
9+
@GET
10+
public String index() {
11+
return "Hello, baeldung!";
12+
}
1313

1414
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package com.baeldung.bootique.router;
22

3-
import javax.ws.rs.POST;
4-
import javax.ws.rs.Path;
5-
63
import com.baeldung.bootique.service.HelloService;
74
import com.google.inject.Inject;
85

6+
import javax.ws.rs.POST;
7+
import javax.ws.rs.Path;
8+
99
@Path("/save")
1010
public class SaveController {
1111

12-
@Inject
13-
HelloService helloService;
14-
15-
@POST
16-
public String save() {
17-
return "Data Saved!";
18-
}
19-
12+
@Inject
13+
HelloService helloService;
14+
15+
@POST
16+
public String save() {
17+
return "Data Saved!";
18+
}
19+
2020
}
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
package com.baeldung.bootique;
22

3-
import static org.junit.Assert.assertEquals;
4-
5-
import org.junit.Rule;
6-
import org.junit.Test;
7-
83
import com.baeldung.bootique.service.HelloService;
9-
104
import io.bootique.BQRuntime;
115
import io.bootique.test.junit.BQDaemonTestFactory;
126
import io.bootique.test.junit.BQTestFactory;
7+
import org.junit.Rule;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertEquals;
1311

1412
public class AppTest {
1513

16-
@Rule
17-
public BQTestFactory bqTestFactory = new BQTestFactory();
14+
@Rule
15+
public BQTestFactory bqTestFactory = new BQTestFactory();
1816

19-
@Rule
20-
public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory();
17+
@Rule
18+
public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory();
2119

22-
@Test
23-
public void givenService_expectBoolen() {
24-
BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime();
25-
HelloService service = runtime.getInstance(HelloService.class);
26-
assertEquals(true, service.save());
27-
}
20+
@Test
21+
public void givenService_expectBoolen() {
22+
BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime();
23+
HelloService service = runtime.getInstance(HelloService.class);
24+
assertEquals(true, service.save());
25+
}
2826

2927
}

core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.baeldung.hashcode.application;
22

33
import com.baeldung.hashcode.entities.User;
4-
import org.junit.After;
5-
import org.junit.Before;
64
import org.junit.Test;
7-
import java.io.ByteArrayOutputStream;
8-
import java.io.PrintStream;
5+
96
import java.util.HashMap;
107
import java.util.Map;
118

12-
import static org.junit.Assert.assertEquals;
139
import static org.junit.Assert.assertTrue;
1410

1511
public class ApplicationTest {

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<module>apache-thrift</module>
3939
<module>autovalue</module>
4040
<module>axon</module>
41+
<module>bootique</module>
4142

4243
<module>cdi</module>
4344
<!-- <module>core-java-9</module> -->

0 commit comments

Comments
 (0)