From b6e59c2ae7113bc31ae82d07571e2f9a87a70d86 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 6 Aug 2017 13:23:19 +0200 Subject: [PATCH] Refactor bootique (#2380) --- .../main/java/com/baeldung/bootique/App.java | 49 +++++++++---------- .../bootique/module/ModuleBinder.java | 8 +-- .../bootique/module/ModuleProvider.java | 9 ++-- .../bootique/router/IndexController.java | 10 ++-- .../bootique/router/SaveController.java | 22 ++++----- .../java/com/baeldung/bootique/AppTest.java | 30 ++++++------ .../hashcode/application/ApplicationTest.java | 6 +-- pom.xml | 1 + 8 files changed, 64 insertions(+), 71 deletions(-) diff --git a/bootique/src/main/java/com/baeldung/bootique/App.java b/bootique/src/main/java/com/baeldung/bootique/App.java index 2fd03bd6c3..cc1b90ce7d 100644 --- a/bootique/src/main/java/com/baeldung/bootique/App.java +++ b/bootique/src/main/java/com/baeldung/bootique/App.java @@ -1,42 +1,41 @@ package com.baeldung.bootique; -import java.util.function.Supplier; - import com.baeldung.bootique.module.ModuleBinder; import com.baeldung.bootique.router.IndexController; import com.baeldung.bootique.router.SaveController; import com.google.inject.Module; - import io.bootique.Bootique; import io.bootique.jersey.JerseyModule; import io.bootique.log.BootLogger; +import java.util.function.Supplier; + public class App { - public static void main(String[] args) { - Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class) - .addResource(SaveController.class); - Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() { - @Override - public void trace(Supplier arg0) { - // ... - } + public static void main(String[] args) { + Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class) + .addResource(SaveController.class); + Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() { + @Override + public void trace(Supplier arg0) { + // ... + } - @Override - public void stdout(String arg0) { - // ... - } + @Override + public void stdout(String arg0) { + // ... + } - @Override - public void stderr(String arg0, Throwable arg1) { - // ... - } + @Override + public void stderr(String arg0, Throwable arg1) { + // ... + } - @Override - public void stderr(String arg0) { - // ... - } - }).autoLoadModules().exec(); - } + @Override + public void stderr(String arg0) { + // ... + } + }).autoLoadModules().exec(); + } } diff --git a/bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java b/bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java index 8c6fbb9642..8811d48652 100644 --- a/bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java +++ b/bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java @@ -7,9 +7,9 @@ import com.google.inject.Module; public class ModuleBinder implements Module { - @Override - public void configure(Binder binder) { - binder.bind(HelloService.class).to(HelloServiceImpl.class); - } + @Override + public void configure(Binder binder) { + binder.bind(HelloService.class).to(HelloServiceImpl.class); + } } diff --git a/bootique/src/main/java/com/baeldung/bootique/module/ModuleProvider.java b/bootique/src/main/java/com/baeldung/bootique/module/ModuleProvider.java index 8de866fcfb..cf78177e6d 100644 --- a/bootique/src/main/java/com/baeldung/bootique/module/ModuleProvider.java +++ b/bootique/src/main/java/com/baeldung/bootique/module/ModuleProvider.java @@ -1,14 +1,13 @@ package com.baeldung.bootique.module; import com.google.inject.Module; - import io.bootique.BQModuleProvider; public class ModuleProvider implements BQModuleProvider { - @Override - public Module module() { - return new ModuleBinder(); - } + @Override + public Module module() { + return new ModuleBinder(); + } } diff --git a/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java b/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java index 4bb80277a1..6e3b31df41 100644 --- a/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java +++ b/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java @@ -5,10 +5,10 @@ import javax.ws.rs.Path; @Path("/") public class IndexController { - - @GET - public String index() { - return "Hello, baeldung!"; - } + + @GET + public String index() { + return "Hello, baeldung!"; + } } diff --git a/bootique/src/main/java/com/baeldung/bootique/router/SaveController.java b/bootique/src/main/java/com/baeldung/bootique/router/SaveController.java index 0610b9d913..f38f59708c 100644 --- a/bootique/src/main/java/com/baeldung/bootique/router/SaveController.java +++ b/bootique/src/main/java/com/baeldung/bootique/router/SaveController.java @@ -1,20 +1,20 @@ package com.baeldung.bootique.router; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - import com.baeldung.bootique.service.HelloService; import com.google.inject.Inject; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + @Path("/save") public class SaveController { - @Inject - HelloService helloService; - - @POST - public String save() { - return "Data Saved!"; - } - + @Inject + HelloService helloService; + + @POST + public String save() { + return "Data Saved!"; + } + } diff --git a/bootique/src/test/java/com/baeldung/bootique/AppTest.java b/bootique/src/test/java/com/baeldung/bootique/AppTest.java index 0793e2f13c..8856780ed4 100644 --- a/bootique/src/test/java/com/baeldung/bootique/AppTest.java +++ b/bootique/src/test/java/com/baeldung/bootique/AppTest.java @@ -1,29 +1,27 @@ package com.baeldung.bootique; -import static org.junit.Assert.assertEquals; - -import org.junit.Rule; -import org.junit.Test; - import com.baeldung.bootique.service.HelloService; - import io.bootique.BQRuntime; import io.bootique.test.junit.BQDaemonTestFactory; import io.bootique.test.junit.BQTestFactory; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; public class AppTest { - @Rule - public BQTestFactory bqTestFactory = new BQTestFactory(); + @Rule + public BQTestFactory bqTestFactory = new BQTestFactory(); - @Rule - public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory(); + @Rule + public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory(); - @Test - public void givenService_expectBoolen() { - BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime(); - HelloService service = runtime.getInstance(HelloService.class); - assertEquals(true, service.save()); - } + @Test + public void givenService_expectBoolen() { + BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime(); + HelloService service = runtime.getInstance(HelloService.class); + assertEquals(true, service.save()); + } } diff --git a/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java b/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java index 04e32e5fa0..60950fae7a 100644 --- a/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java +++ b/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java @@ -1,15 +1,11 @@ package com.baeldung.hashcode.application; import com.baeldung.hashcode.entities.User; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; + import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class ApplicationTest { diff --git a/pom.xml b/pom.xml index 8401a2f159..f33d63bc48 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ apache-thrift autovalue axon + bootique cdi