diff --git a/bootique/config.yml b/bootique/config.yml
new file mode 100644
index 0000000000..269b4ab867
--- /dev/null
+++ b/bootique/config.yml
@@ -0,0 +1,11 @@
+log:
+ level: warn
+ appenders:
+ - type: file
+ logFormat: '%c{20}: %m%n'
+ file: /home/logger.log
+
+jetty:
+ context: /hello
+ connector:
+ port: 10001
diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml
new file mode 100644
index 0000000000..ed18f4e42a
--- /dev/null
+++ b/bootique/dependency-reduced-pom.xml
@@ -0,0 +1,50 @@
+
+
+
+ bootique-parent
+ io.bootique.parent
+ 0.12
+
+ 4.0.0
+ com.baeldung.bootique
+ bootique
+ bootique
+ 1.0-SNAPSHOT
+ http://maven.apache.org
+
+
+
+ maven-shade-plugin
+
+
+
+
+
+ io.bootique
+ bootique-test
+ 0.23
+ test
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+
+
+ io.bootique.bom
+ bootique-bom
+ 0.23
+ pom
+ import
+
+
+
+
+ com.baeldung.bootique.App
+
+
+
diff --git a/bootique/pom.xml b/bootique/pom.xml
new file mode 100644
index 0000000000..28b716e104
--- /dev/null
+++ b/bootique/pom.xml
@@ -0,0 +1,66 @@
+
+ 4.0.0
+ com.baeldung.bootique
+ bootique
+ jar
+ 1.0-SNAPSHOT
+ bootique
+ http://maven.apache.org
+
+
+ com.baeldung.bootique.App
+
+
+
+ io.bootique.parent
+ bootique-parent
+ 0.12
+
+
+
+
+
+ io.bootique.bom
+ bootique-bom
+ 0.23
+ pom
+ import
+
+
+
+
+
+
+ io.bootique.jersey
+ bootique-jersey
+ compile
+
+
+ io.bootique.logback
+ bootique-logback
+ compile
+
+
+ io.bootique
+ bootique-test
+ test
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/bootique/src/main/java/com/baeldung/bootique/App.java b/bootique/src/main/java/com/baeldung/bootique/App.java
new file mode 100644
index 0000000000..cc1b90ce7d
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/App.java
@@ -0,0 +1,41 @@
+package com.baeldung.bootique;
+
+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) {
+ // ...
+ }
+
+ @Override
+ public void stdout(String arg0) {
+ // ...
+ }
+
+ @Override
+ public void stderr(String arg0, Throwable arg1) {
+ // ...
+ }
+
+ @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
new file mode 100644
index 0000000000..8811d48652
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/module/ModuleBinder.java
@@ -0,0 +1,15 @@
+package com.baeldung.bootique.module;
+
+import com.baeldung.bootique.service.HelloService;
+import com.baeldung.bootique.service.impl.HelloServiceImpl;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+
+public class ModuleBinder implements Module {
+
+ @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
new file mode 100644
index 0000000000..cf78177e6d
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/module/ModuleProvider.java
@@ -0,0 +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();
+ }
+
+}
diff --git a/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java b/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java
new file mode 100644
index 0000000000..6e3b31df41
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/router/IndexController.java
@@ -0,0 +1,14 @@
+package com.baeldung.bootique.router;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("/")
+public class IndexController {
+
+ @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
new file mode 100644
index 0000000000..f38f59708c
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/router/SaveController.java
@@ -0,0 +1,20 @@
+package com.baeldung.bootique.router;
+
+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!";
+ }
+
+}
diff --git a/bootique/src/main/java/com/baeldung/bootique/service/HelloService.java b/bootique/src/main/java/com/baeldung/bootique/service/HelloService.java
new file mode 100644
index 0000000000..74c0401cc3
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/service/HelloService.java
@@ -0,0 +1,7 @@
+package com.baeldung.bootique.service;
+
+public interface HelloService {
+
+ boolean save();
+
+}
diff --git a/bootique/src/main/java/com/baeldung/bootique/service/impl/HelloServiceImpl.java b/bootique/src/main/java/com/baeldung/bootique/service/impl/HelloServiceImpl.java
new file mode 100644
index 0000000000..d2c0b5b838
--- /dev/null
+++ b/bootique/src/main/java/com/baeldung/bootique/service/impl/HelloServiceImpl.java
@@ -0,0 +1,12 @@
+package com.baeldung.bootique.service.impl;
+
+import com.baeldung.bootique.service.HelloService;
+
+public class HelloServiceImpl implements HelloService {
+
+ @Override
+ public boolean save() {
+ return true;
+ }
+
+}
diff --git a/bootique/src/main/resources/META-INF/services/io.bootique.BQModuleProvider b/bootique/src/main/resources/META-INF/services/io.bootique.BQModuleProvider
new file mode 100644
index 0000000000..714cf3a2df
--- /dev/null
+++ b/bootique/src/main/resources/META-INF/services/io.bootique.BQModuleProvider
@@ -0,0 +1 @@
+com.baeldung.bootique.module.ModuleProvider
\ No newline at end of file
diff --git a/bootique/src/test/java/com/baeldung/bootique/AppTest.java b/bootique/src/test/java/com/baeldung/bootique/AppTest.java
new file mode 100644
index 0000000000..8856780ed4
--- /dev/null
+++ b/bootique/src/test/java/com/baeldung/bootique/AppTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.bootique;
+
+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 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());
+ }
+
+}
diff --git a/core-java/hashcode/pom.xml b/core-java/hashcode/pom.xml
deleted file mode 100644
index 393aa69153..0000000000
--- a/core-java/hashcode/pom.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
- 4.0.0
- com.baeldung.hashcode
- hashcode
- 1.0
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 1.8
-
-
-
-
-
-
- junit
- junit
- 4.12
- test
-
-
- org.slf4j
- slf4j-api
- 1.7.25
-
-
- org.slf4j
- slf4j-simple
- 1.7.25
-
-
-
\ No newline at end of file
diff --git a/core-java/hashcode/src/main/java/com/baeldung/application/Application.java b/core-java/hashcode/src/main/java/com/baeldung/application/Application.java
deleted file mode 100644
index 08c670c82f..0000000000
--- a/core-java/hashcode/src/main/java/com/baeldung/application/Application.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.application;
-
-import com.baeldung.entities.User;
-import java.util.HashMap;
-import java.util.Map;
-
-public class Application {
-
- public static void main(String[] args) {
- Map users = new HashMap<>();
- User user1 = new User(1L, "John", "john@domain.com");
- User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
- User user3 = new User(3L, "Mary", "mary@domain.com");
-
- users.put(user1, user1);
- users.put(user2, user2);
- users.put(user3, user3);
-
- if (users.containsKey(user1)) {
- System.out.print("User found in the collection");
- }
- }
-}
diff --git a/core-java/hashcode/src/main/java/com/baeldung/entities/User.java b/core-java/hashcode/src/main/java/com/baeldung/entities/User.java
deleted file mode 100644
index a976233562..0000000000
--- a/core-java/hashcode/src/main/java/com/baeldung/entities/User.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung.entities;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class User {
-
- private final Logger logger = LoggerFactory.getLogger(User.class);
- private long id;
- private String name;
- private String email;
-
- public User(long id, String name, String email) {
- this.id = id;
- this.name = name;
- this.email = email;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null) return false;
- if (this.getClass() != o.getClass()) return false;
- User user = (User) o;
- return id != user.id && (!name.equals(user.name) && !email.equals(user.email));
- }
-
- @Override
- public int hashCode() {
- int hash = 7;
- hash = 31 * hash + (int) id;
- hash = 31 * hash + (name == null ? 0 : name.hashCode());
- hash = 31 * hash + (email == null ? 0 : email.hashCode());
- logger.info("hashCode() method called - Computed hash: " + hash);
- return hash;
- }
- // getters and setters here
-}
diff --git a/core-java/hashcode/src/test/java/com/baeldung/application/ApplicationTest.java b/core-java/hashcode/src/test/java/com/baeldung/application/ApplicationTest.java
deleted file mode 100644
index dcd853f451..0000000000
--- a/core-java/hashcode/src/test/java/com/baeldung/application/ApplicationTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.application;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import static org.junit.Assert.assertEquals;
-
-public class ApplicationTest {
-
- private ByteArrayOutputStream outContent;
-
- @Before
- public void setUpPrintStreamInstance() throws Exception {
- this.outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
- }
-
- @After
- public void tearDownByteArrayOutputStream() throws Exception {
- outContent = null;
- }
-
- @Test
- public void main_NoInputState_TextPrintedToConsole() throws Exception {
- Application.main(new String[]{});
- assertEquals("User found in the collection", outContent.toString());
- }
-}
\ No newline at end of file
diff --git a/core-java/hashcode/src/test/java/com/baeldung/entities/UserTest.java b/core-java/hashcode/src/test/java/com/baeldung/entities/UserTest.java
deleted file mode 100644
index 01f6085d7e..0000000000
--- a/core-java/hashcode/src/test/java/com/baeldung/entities/UserTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.entities;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class UserTest {
-
- private User user;
- private User comparisonUser;
-
- @Before
- public void setUpUserInstances() {
- this.user = new User(1L, "test", "test@domain.com");
- this.comparisonUser = this.user;
- }
-
- @After
- public void tearDownUserInstances() {
- user = null;
- comparisonUser = null;
- }
-
- @Test
- public void equals_EqualUserInstance_TrueAssertion(){
- Assert.assertTrue(user.equals(comparisonUser));
- }
-
- @Test
- public void hashCode_UserHash_TrueAssertion() {
- Assert.assertEquals(1792276941, user.hashCode());
- }
-}
\ No newline at end of file
diff --git a/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java b/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java
index 977dae4fdb..758bdecd0c 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java
@@ -15,14 +15,12 @@ public class CyclicBarrierDemo {
private int NUM_PARTIAL_RESULTS;
private int NUM_WORKERS;
-
private void runSimulation(int numWorkers, int numberOfPartialResults) {
NUM_PARTIAL_RESULTS = numberOfPartialResults;
NUM_WORKERS = numWorkers;
cyclicBarrier = new CyclicBarrier(NUM_WORKERS, new AggregatorThread());
- System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute "
- + NUM_PARTIAL_RESULTS + " partial results each");
+ System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute " + NUM_PARTIAL_RESULTS + " partial results each");
for (int i = 0; i < NUM_WORKERS; i++) {
Thread worker = new Thread(new NumberCruncherThread());
worker.setName("Thread " + i);
@@ -38,8 +36,7 @@ public class CyclicBarrierDemo {
List partialResult = new ArrayList<>();
for (int i = 0; i < NUM_PARTIAL_RESULTS; i++) {
Integer num = random.nextInt(10);
- System.out.println(thisThreadName
- + ": Crunching some numbers! Final result - " + num);
+ System.out.println(thisThreadName + ": Crunching some numbers! Final result - " + num);
partialResult.add(num);
}
partialResults.add(partialResult);
@@ -57,13 +54,12 @@ public class CyclicBarrierDemo {
@Override
public void run() {
String thisThreadName = Thread.currentThread().getName();
- System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS
- + " workers, having " + NUM_PARTIAL_RESULTS + " results each.");
+ System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS + " workers, having " + NUM_PARTIAL_RESULTS + " results each.");
int sum = 0;
for (List threadResult : partialResults) {
System.out.print("Adding ");
for (Integer partialResult : threadResult) {
- System.out.print(partialResult+" ");
+ System.out.print(partialResult + " ");
sum += partialResult;
}
System.out.println();
diff --git a/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java b/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java
index c5672706ad..4de420900a 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java
@@ -15,7 +15,8 @@ public class Philosopher implements Runnable {
Thread.sleep(((int) (Math.random() * 100)));
}
- @Override public void run() {
+ @Override
+ public void run() {
try {
while (true) {
doAction(System.nanoTime() + ": Thinking"); // thinking
diff --git a/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java b/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java
index ae2b279d9a..83a9fb6692 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java
@@ -6,22 +6,22 @@ import java.util.concurrent.TimeUnit;
public class ExecutorServiceDemo {
- ExecutorService executor = Executors.newFixedThreadPool(10);
+ ExecutorService executor = Executors.newFixedThreadPool(10);
- public void execute() {
+ public void execute() {
- executor.submit(() -> {
- new Task();
- });
+ executor.submit(() -> {
+ new Task();
+ });
- executor.shutdown();
- executor.shutdownNow();
- try {
- executor.awaitTermination(20l, TimeUnit.NANOSECONDS);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ executor.shutdown();
+ executor.shutdownNow();
+ try {
+ executor.awaitTermination(20l, TimeUnit.NANOSECONDS);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
- }
+ }
}
diff --git a/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java b/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java
index 7cb611be0f..4794d5cb61 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java
@@ -9,36 +9,36 @@ import java.util.concurrent.TimeoutException;
public class FutureDemo {
- public String invoke() {
+ public String invoke() {
- String str = null;
+ String str = null;
- ExecutorService executorService = Executors.newFixedThreadPool(10);
+ ExecutorService executorService = Executors.newFixedThreadPool(10);
- Future future = executorService.submit(() -> {
- // Task
- Thread.sleep(10000l);
- return "Hellow world";
- });
+ Future future = executorService.submit(() -> {
+ // Task
+ Thread.sleep(10000l);
+ return "Hellow world";
+ });
- future.cancel(false);
+ future.cancel(false);
- try {
- future.get(20, TimeUnit.SECONDS);
- } catch (InterruptedException | ExecutionException | TimeoutException e1) {
- e1.printStackTrace();
- }
+ try {
+ future.get(20, TimeUnit.SECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e1) {
+ e1.printStackTrace();
+ }
- if (future.isDone() && !future.isCancelled()) {
- try {
- str = future.get();
- } catch (InterruptedException | ExecutionException e) {
- e.printStackTrace();
- }
- }
+ if (future.isDone() && !future.isCancelled()) {
+ try {
+ str = future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
- return str;
+ return str;
- }
+ }
}
diff --git a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java
index 8744027e40..f708804cae 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java
@@ -4,20 +4,20 @@ import java.util.concurrent.ThreadFactory;
public class BaeldungThreadFactory implements ThreadFactory {
- private int threadId;
- private String name;
+ private int threadId;
+ private String name;
- public BaeldungThreadFactory(String name) {
- threadId = 1;
- this.name = name;
- }
+ public BaeldungThreadFactory(String name) {
+ threadId = 1;
+ this.name = name;
+ }
- @Override
- public Thread newThread(Runnable r) {
- Thread t = new Thread(r, name + "-Thread_" + threadId);
- System.out.println("created new thread with id : " + threadId + " and name : " + t.getName());
- threadId++;
- return t;
- }
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, name + "-Thread_" + threadId);
+ System.out.println("created new thread with id : " + threadId + " and name : " + t.getName());
+ threadId++;
+ return t;
+ }
}
diff --git a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java
index 04ba62d457..a69623c667 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java
@@ -2,9 +2,9 @@ package com.baeldung.concurrent.threadfactory;
public class Task implements Runnable {
- @Override
- public void run() {
- // task details
- }
-
+ @Override
+ public void run() {
+ // task details
+ }
+
}
diff --git a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java
index 4afce56e39..7e6bb5d3b2 100644
--- a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java
+++ b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java
@@ -14,26 +14,25 @@ public class LookupFSJNDI {
super();
init();
}
-
+
private void init() throws NamingException {
Hashtable env = new Hashtable();
-
- env.put (Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.fscontext.RefFSContextFactory");
+
+ env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
// URI to namespace (actual directory)
env.put(Context.PROVIDER_URL, "file:./src/test/resources");
-
+
ctx = new InitialContext(env);
}
public InitialContext getCtx() {
return ctx;
}
-
+
public File getFile(String fileName) {
File file;
try {
- file = (File)getCtx().lookup(fileName);
+ file = (File) getCtx().lookup(fileName);
} catch (NamingException e) {
file = null;
}
diff --git a/core-java/src/main/java/com/baeldung/hashcode/application/Application.java b/core-java/src/main/java/com/baeldung/hashcode/application/Application.java
deleted file mode 100644
index 08c670c82f..0000000000
--- a/core-java/src/main/java/com/baeldung/hashcode/application/Application.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.application;
-
-import com.baeldung.entities.User;
-import java.util.HashMap;
-import java.util.Map;
-
-public class Application {
-
- public static void main(String[] args) {
- Map users = new HashMap<>();
- User user1 = new User(1L, "John", "john@domain.com");
- User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
- User user3 = new User(3L, "Mary", "mary@domain.com");
-
- users.put(user1, user1);
- users.put(user2, user2);
- users.put(user3, user3);
-
- if (users.containsKey(user1)) {
- System.out.print("User found in the collection");
- }
- }
-}
diff --git a/core-java/src/main/java/com/baeldung/hashcode/entities/User.java b/core-java/src/main/java/com/baeldung/hashcode/entities/User.java
index a976233562..c46c3de65a 100644
--- a/core-java/src/main/java/com/baeldung/hashcode/entities/User.java
+++ b/core-java/src/main/java/com/baeldung/hashcode/entities/User.java
@@ -1,4 +1,4 @@
-package com.baeldung.entities;
+package com.baeldung.hashcode.entities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,13 +18,16 @@ public class User {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null) return false;
- if (this.getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null)
+ return false;
+ if (this.getClass() != o.getClass())
+ return false;
User user = (User) o;
return id != user.id && (!name.equals(user.name) && !email.equals(user.email));
}
-
+
@Override
public int hashCode() {
int hash = 7;
diff --git a/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java b/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java
index 220b9a8ec6..21044f82c4 100644
--- a/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java
+++ b/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java
@@ -10,7 +10,6 @@ public class JMXTutorialMainlauncher {
private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class);
-
public static void main(String[] args) {
// TODO Auto-generated method stub
diff --git a/core-java/src/main/java/com/baeldung/socket/EchoClient.java b/core-java/src/main/java/com/baeldung/socket/EchoClient.java
index cf5c253276..fa3901d5da 100644
--- a/core-java/src/main/java/com/baeldung/socket/EchoClient.java
+++ b/core-java/src/main/java/com/baeldung/socket/EchoClient.java
@@ -8,9 +8,8 @@ import java.net.*;
public class EchoClient {
-
private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
-
+
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
diff --git a/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java b/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java
index ae00fc7cb4..d79a7c3ecb 100644
--- a/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java
+++ b/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java
@@ -1,6 +1,5 @@
package com.baeldung.stream;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/core-java/src/main/java/com/baeldung/string/StringHelper.java b/core-java/src/main/java/com/baeldung/string/StringHelper.java
index dac0d1272e..a9cc71d36a 100644
--- a/core-java/src/main/java/com/baeldung/string/StringHelper.java
+++ b/core-java/src/main/java/com/baeldung/string/StringHelper.java
@@ -12,15 +12,10 @@ class StringHelper {
}
static String removeLastCharOptional(String s) {
- return Optional.ofNullable(s)
- .filter(str -> str.length() != 0)
- .map(str -> str.substring(0, str.length() - 1))
- .orElse(s);
+ return Optional.ofNullable(s).filter(str -> str.length() != 0).map(str -> str.substring(0, str.length() - 1)).orElse(s);
}
static String removeLastCharRegexOptional(String s) {
- return Optional.ofNullable(s)
- .map(str -> str.replaceAll(".$", ""))
- .orElse(s);
+ return Optional.ofNullable(s).map(str -> str.replaceAll(".$", "")).orElse(s);
}
}
diff --git a/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java b/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java
index 130218acc2..21164a976c 100644
--- a/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java
+++ b/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java
@@ -25,11 +25,7 @@ public class MyTokenizer {
}
public List getTokensWithCollection(String str) {
- return Collections
- .list(new StringTokenizer(str, ","))
- .stream()
- .map(token -> (String) token)
- .collect(Collectors.toList());
+ return Collections.list(new StringTokenizer(str, ",")).stream().map(token -> (String) token).collect(Collectors.toList());
}
public List getTokensFromFile(String path, String delim) {
diff --git a/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java b/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java
index bfb6681f7c..5631616ea8 100644
--- a/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java
+++ b/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java
@@ -11,12 +11,12 @@ public class CustomTemporalAdjuster implements TemporalAdjuster {
@Override
public Temporal adjustInto(Temporal temporal) {
switch (DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))) {
- case FRIDAY:
- return temporal.plus(3, ChronoUnit.DAYS);
- case SATURDAY:
- return temporal.plus(2, ChronoUnit.DAYS);
- default:
- return temporal.plus(1, ChronoUnit.DAYS);
+ case FRIDAY:
+ return temporal.plus(3, ChronoUnit.DAYS);
+ case SATURDAY:
+ return temporal.plus(2, ChronoUnit.DAYS);
+ default:
+ return temporal.plus(1, ChronoUnit.DAYS);
}
}
}
diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java
index 69d7ff2390..a5f70d9df5 100644
--- a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java
+++ b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java
@@ -9,7 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public class Consumer implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);
-
private final TransferQueue transferQueue;
private final String name;
private final int numberOfMessagesToConsume;
diff --git a/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java b/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java
index 2f1abef64e..8cddf31245 100644
--- a/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java
@@ -15,28 +15,24 @@ public class LongAccumulatorUnitTest {
@Test
public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException {
- //given
+ // given
ExecutorService executorService = Executors.newFixedThreadPool(8);
LongBinaryOperator sum = Long::sum;
LongAccumulator accumulator = new LongAccumulator(sum, 0L);
int numberOfThreads = 4;
int numberOfIncrements = 100;
- //when
- Runnable accumulateAction = () -> IntStream
- .rangeClosed(0, numberOfIncrements)
- .forEach(accumulator::accumulate);
+ // when
+ Runnable accumulateAction = () -> IntStream.rangeClosed(0, numberOfIncrements).forEach(accumulator::accumulate);
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(accumulateAction);
}
-
- //then
+ // then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(accumulator.get(), 20200);
-
}
}
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 dcd853f451..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,30 +1,26 @@
-package com.baeldung.application;
+package com.baeldung.hashcode.application;
-import org.junit.After;
-import org.junit.Before;
+import com.baeldung.hashcode.entities.User;
import org.junit.Test;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
public class ApplicationTest {
- private ByteArrayOutputStream outContent;
-
- @Before
- public void setUpPrintStreamInstance() throws Exception {
- this.outContent = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outContent));
- }
-
- @After
- public void tearDownByteArrayOutputStream() throws Exception {
- outContent = null;
- }
-
@Test
public void main_NoInputState_TextPrintedToConsole() throws Exception {
- Application.main(new String[]{});
- assertEquals("User found in the collection", outContent.toString());
+ Map users = new HashMap<>();
+ User user1 = new User(1L, "John", "john@domain.com");
+ User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
+ User user3 = new User(3L, "Mary", "mary@domain.com");
+
+ users.put(user1, user1);
+ users.put(user2, user2);
+ users.put(user3, user3);
+
+ assertTrue(users.containsKey(user1));
}
}
\ No newline at end of file
diff --git a/core-java/src/test/java/com/baeldung/hashcode/entities/UserTest.java b/core-java/src/test/java/com/baeldung/hashcode/entities/UserTest.java
index 01f6085d7e..e356b4beef 100644
--- a/core-java/src/test/java/com/baeldung/hashcode/entities/UserTest.java
+++ b/core-java/src/test/java/com/baeldung/hashcode/entities/UserTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.entities;
+package com.baeldung.hashcode.entities;
import org.junit.After;
import org.junit.Assert;
@@ -23,7 +23,7 @@ public class UserTest {
}
@Test
- public void equals_EqualUserInstance_TrueAssertion(){
+ public void equals_EqualUserInstance_TrueAssertion() {
Assert.assertTrue(user.equals(comparisonUser));
}
diff --git a/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java b/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java
index 0fd6f7dfe8..fe10266043 100644
--- a/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java
@@ -15,7 +15,6 @@ public class LambdaExceptionWrappersUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersUnitTest.class);
-
private List integers;
@Before
diff --git a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java
index 7a23afa12f..5327e5f4f0 100644
--- a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java
@@ -29,12 +29,9 @@ public class ListOfListsUnitTest {
@Test
public void givenListOfLists_thenCheckNames() {
- assertEquals("Pen 1", ((Pen) listOfLists.get(0)
- .get(0)).getName());
- assertEquals("Pencil 1", ((Pencil) listOfLists.get(1)
- .get(0)).getName());
- assertEquals("Rubber 1", ((Rubber) listOfLists.get(2)
- .get(0)).getName());
+ assertEquals("Pen 1", ((Pen) listOfLists.get(0).get(0)).getName());
+ assertEquals("Pencil 1", ((Pencil) listOfLists.get(1).get(0)).getName());
+ assertEquals("Rubber 1", ((Rubber) listOfLists.get(2).get(0)).getName());
}
@SuppressWarnings("unchecked")
@@ -43,11 +40,9 @@ public class ListOfListsUnitTest {
((ArrayList) listOfLists.get(1)).remove(0);
listOfLists.remove(1);
- assertEquals("Rubber 1", ((Rubber) listOfLists.get(1)
- .get(0)).getName());
+ assertEquals("Rubber 1", ((Rubber) listOfLists.get(1).get(0)).getName());
listOfLists.remove(0);
- assertEquals("Rubber 1", ((Rubber) listOfLists.get(0)
- .get(0)).getName());
+ assertEquals("Rubber 1", ((Rubber) listOfLists.get(0).get(0)).getName());
}
@Test
@@ -67,11 +62,8 @@ public class ListOfListsUnitTest {
list.add(pencils);
list.add(rubbers);
- assertEquals("Pen 1", ((Pen) list.get(0)
- .get(0)).getName());
- assertEquals("Pencil 1", ((Pencil) list.get(1)
- .get(0)).getName());
- assertEquals("Rubber 1", ((Rubber) list.get(2)
- .get(0)).getName());
+ assertEquals("Pen 1", ((Pen) list.get(0).get(0)).getName());
+ assertEquals("Pencil 1", ((Pencil) list.get(1).get(0)).getName());
+ assertEquals("Rubber 1", ((Rubber) list.get(2).get(0)).getName());
}
}
diff --git a/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java b/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java
index 9d8d3c884b..5fb85bb2c4 100644
--- a/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java
@@ -13,7 +13,6 @@ public class CoreThreadPoolIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(CoreThreadPoolIntegrationTest.class);
-
@Test(timeout = 1000)
public void whenCallingExecuteWithRunnable_thenRunnableIsExecuted() throws InterruptedException {
diff --git a/jooq/README.md b/jooq/README.md
deleted file mode 100644
index 2f09cab46b..0000000000
--- a/jooq/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### Relevant articles
-
-- [Introduction to jOOL](http://www.baeldung.com/jool)
diff --git a/jooq/pom.xml b/jooq/pom.xml
deleted file mode 100644
index 667640d085..0000000000
--- a/jooq/pom.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
- parent-modules
- com.baeldung
- 1.0.0-SNAPSHOT
-
- 4.0.0
-
- jooq
-
-
-
- org.jooq
- jool
- ${jool.version}
-
-
-
-
- 0.9.12
-
-
-
\ No newline at end of file
diff --git a/libraries/pom.xml b/libraries/pom.xml
index efdf20423a..87971fb26e 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -181,6 +181,11 @@
jetty-servlet
${jetty.version}
+
+ rome
+ rome
+ ${rome.version}
+
io.specto
hoverfly-java
@@ -497,5 +502,6 @@
1.6.0
1.7.1
2.1.2
+ 1.0
diff --git a/libraries/src/main/java/com/baeldung/rome/RSSRomeExample.java b/libraries/src/main/java/com/baeldung/rome/RSSRomeExample.java
new file mode 100644
index 0000000000..66a9e0ebce
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/rome/RSSRomeExample.java
@@ -0,0 +1,76 @@
+package com.baeldung.rome;
+
+import com.sun.syndication.feed.synd.*;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.XmlReader;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class RSSRomeExample {
+
+ public static void main(String[] args) throws IOException, FeedException {
+ SyndFeed feed = createFeed();
+ addEntryToFeed(feed);
+ publishFeed(feed);
+ readFeed();
+ }
+
+ private static SyndFeed createFeed() {
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setFeedType("rss_1.0");
+ feed.setTitle("Test title");
+ feed.setLink("http://www.somelink.com");
+ feed.setDescription("Basic description");
+
+ return feed;
+ }
+
+ private static void addEntryToFeed(SyndFeed feed) {
+ SyndEntry entry = new SyndEntryImpl();
+ entry.setTitle("Entry title");
+ entry.setLink("http://www.somelink.com/entry1");
+
+ addDescriptionToEntry(entry);
+ addCategoryToEntry(entry);
+
+ feed.setEntries(Arrays.asList(entry));
+ }
+
+ private static void addDescriptionToEntry(SyndEntry entry) {
+ SyndContent description = new SyndContentImpl();
+ description.setType("text/html");
+ description.setValue("First entry");
+
+ entry.setDescription(description);
+ }
+
+ private static void addCategoryToEntry(SyndEntry entry) {
+ List categories = new ArrayList<>();
+ SyndCategory category = new SyndCategoryImpl();
+ category.setName("Sophisticated category");
+ categories.add(category);
+
+ entry.setCategories(categories);
+ }
+
+ private static void publishFeed(SyndFeed feed) throws IOException, FeedException {
+ Writer writer = new FileWriter("xyz.txt");
+ SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
+ syndFeedOutput.output(feed, writer);
+ writer.close();
+ }
+
+ private static SyndFeed readFeed() throws IOException, FeedException {
+ URL feedSource = new URL("http://rssblog.whatisrss.com/feed/");
+ SyndFeedInput input = new SyndFeedInput();
+ return input.build(new XmlReader(feedSource));
+ }
+}
\ No newline at end of file
diff --git a/jooq/src/test/java/com/baeldung/JOOLUnitTest.java b/libraries/src/test/java/com/baeldung/jool/JOOLTest.java
similarity index 64%
rename from jooq/src/test/java/com/baeldung/JOOLUnitTest.java
rename to libraries/src/test/java/com/baeldung/jool/JOOLTest.java
index 17873db50a..ba20e153fd 100644
--- a/jooq/src/test/java/com/baeldung/JOOLUnitTest.java
+++ b/libraries/src/test/java/com/baeldung/jool/JOOLTest.java
@@ -1,4 +1,4 @@
-package com.baeldung;
+package com.baeldung.jool;
import org.jooq.lambda.Seq;
import org.jooq.lambda.Unchecked;
@@ -13,6 +13,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -20,7 +21,7 @@ import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static org.jooq.lambda.tuple.Tuple.tuple;
-public class JOOLUnitTest {
+public class JOOLTest {
@Test
public void givenSeq_whenCheckContains_shouldReturnTrue() {
List concat = Seq.of(1, 2, 3).concat(Seq.of(4, 5, 6)).toList();
@@ -54,58 +55,58 @@ public class JOOLUnitTest {
@Test
public void givenSeq_whenJoin_shouldHaveElementsFromBothSeq() {
assertEquals(
- Seq.of(1, 2, 4).innerJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
- Arrays.asList(tuple(1, 1), tuple(2, 2))
+ Seq.of(1, 2, 4).innerJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
+ Arrays.asList(tuple(1, 1), tuple(2, 2))
);
assertEquals(
- Seq.of(1, 2, 4).leftOuterJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
- Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(4, null))
+ Seq.of(1, 2, 4).leftOuterJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
+ Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(4, null))
);
assertEquals(
- Seq.of(1, 2, 4).rightOuterJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
- Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(null, 3))
+ Seq.of(1, 2, 4).rightOuterJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
+ Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(null, 3))
);
assertEquals(
- Seq.of(1, 2).crossJoin(Seq.of("A", "B")).toList(),
- Arrays.asList(tuple(1, "A"), tuple(1, "B"), tuple(2, "A"), tuple(2, "B"))
+ Seq.of(1, 2).crossJoin(Seq.of("A", "B")).toList(),
+ Arrays.asList(tuple(1, "A"), tuple(1, "B"), tuple(2, "A"), tuple(2, "B"))
);
}
@Test
public void givenSeq_whenManipulateSeq_seqShouldHaveNewElementsInIt() {
assertEquals(
- Seq.of(1, 2, 3).cycle().limit(9).toList(),
- Arrays.asList(1, 2, 3, 1, 2, 3, 1, 2, 3)
+ Seq.of(1, 2, 3).cycle().limit(9).toList(),
+ Arrays.asList(1, 2, 3, 1, 2, 3, 1, 2, 3)
);
assertEquals(
- Seq.of(1, 2, 3).duplicate().map((first, second) -> tuple(first.toList(), second.toList())),
- tuple(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3))
+ Seq.of(1, 2, 3).duplicate().map((first, second) -> tuple(first.toList(), second.toList())),
+ tuple(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3))
);
assertEquals(
- Seq.of(1, 2, 3, 4).intersperse(0).toList(),
- Arrays.asList(1, 0, 2, 0, 3, 0, 4)
+ Seq.of(1, 2, 3, 4).intersperse(0).toList(),
+ Arrays.asList(1, 0, 2, 0, 3, 0, 4)
);
assertEquals(
- Seq.of(1, 2, 3, 4, 5).shuffle().toList().size(),
- 5
+ Seq.of(1, 2, 3, 4, 5).shuffle().toList().size(),
+ 5
);
assertEquals(
- Seq.of(1, 2, 3, 4).partition(i -> i > 2).map((first, second) -> tuple(first.toList(), second.toList())),
- tuple(Arrays.asList(3, 4), Arrays.asList(1, 2))
+ Seq.of(1, 2, 3, 4).partition(i -> i > 2).map((first, second) -> tuple(first.toList(), second.toList())),
+ tuple(Arrays.asList(3, 4), Arrays.asList(1, 2))
);
assertEquals(
- Seq.of(1, 2, 3, 4).reverse().toList(),
- Arrays.asList(4, 3, 2, 1)
+ Seq.of(1, 2, 3, 4).reverse().toList(),
+ Arrays.asList(4, 3, 2, 1)
);
}
@@ -117,20 +118,20 @@ public class JOOLUnitTest {
expectedAfterGroupBy.put(0, Arrays.asList(2, 4));
assertEquals(
- Seq.of(1, 2, 3, 4).groupBy(i -> i % 2),
- expectedAfterGroupBy
+ Seq.of(1, 2, 3, 4).groupBy(i -> i % 2),
+ expectedAfterGroupBy
);
assertEquals(
- Seq.of("a", "b", "c").foldLeft("!", (u, t) -> u + t),
- "!abc"
+ Seq.of("a", "b", "c").foldLeft("!", (u, t) -> u + t),
+ "!abc"
);
assertEquals(
- Seq.of("a", "b", "c").foldRight("!", (t, u) -> t + u),
- "abc!"
+ Seq.of("a", "b", "c").foldRight("!", (t, u) -> t + u),
+ "abc!"
);
}
@@ -138,13 +139,13 @@ public class JOOLUnitTest {
public void givenSeq_whenUsingSeqWhile_shouldBehaveAsWhileLoop() {
assertEquals(
- Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3).toList(),
- Arrays.asList(3, 4, 5)
+ Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3).toList(),
+ Arrays.asList(3, 4, 5)
);
assertEquals(
- Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3).toList(),
- Arrays.asList(3, 4, 5)
+ Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3).toList(),
+ Arrays.asList(3, 4, 5)
);
}
@@ -152,19 +153,19 @@ public class JOOLUnitTest {
public void givenSeq_whenZip_shouldHaveZippedSeq() {
assertEquals(
- Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c")).toList(),
- Arrays.asList(tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
+ Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c")).toList(),
+ Arrays.asList(tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
);
assertEquals(
- Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (x, y) -> x + ":" + y).toList(),
- Arrays.asList("1:a", "2:b", "3:c")
+ Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (x, y) -> x + ":" + y).toList(),
+ Arrays.asList("1:a", "2:b", "3:c")
);
assertEquals(
- Seq.of("a", "b", "c").zipWithIndex().toList(),
- Arrays.asList(tuple("a", 0L), tuple("b", 1L), tuple("c", 2L))
+ Seq.of("a", "b", "c").zipWithIndex().toList(),
+ Arrays.asList(tuple("a", 0L), tuple("b", 1L), tuple("c", 2L))
);
}
@@ -187,8 +188,8 @@ public class JOOLUnitTest {
//then
assertEquals(
- collect,
- Arrays.asList(1, 1, 1)
+ collect,
+ Arrays.asList(1, 1, 1)
);
}
@@ -197,13 +198,13 @@ public class JOOLUnitTest {
public void givenOperationThatThrowsCheckedException_whenExecuteUsingUncheckedFuction_shouldPass() {
//when
List collect = Stream.of("a", "b", "c")
- .map(Unchecked.function(elem -> methodThatThrowsChecked(elem)))
- .collect(Collectors.toList());
+ .map(Unchecked.function(this::methodThatThrowsChecked))
+ .collect(Collectors.toList());
//then
assertEquals(
- collect,
- Arrays.asList(1, 1, 1)
+ collect,
+ Arrays.asList(1, 1, 1)
);
}
@@ -236,5 +237,4 @@ public class JOOLUnitTest {
Arrays.asList(tuple("michael", "similar", "winter", "summer"), tuple("jodie", "variable", "winter", "summer"))
);
}
-
}
diff --git a/pom.xml b/pom.xml
index 3feba96d5a..f33d63bc48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
apache-thrift
autovalue
axon
+ bootique
cdi
@@ -80,10 +81,9 @@
javax-servlets
javaxval
jaxb
-
+ jee7
jjwt
- jooq
jpa-storedprocedure
jsf
json-path
diff --git a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java
index fd184556c4..96b551c03c 100644
--- a/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java
+++ b/spring-activiti/src/main/java/com/example/activitiwithspring/ActivitiController.java
@@ -42,16 +42,11 @@ public class ActivitiController {
}
@GetMapping("/complete-task-A/{processInstanceId}")
- public TaskRepresentation completeTaskA(@PathVariable String processInstanceId) {
+ public void completeTaskA(@PathVariable String processInstanceId) {
Task task = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.singleResult();
taskService.complete(task.getId());
logger.info("Task completed");
- task = taskService.createTaskQuery()
- .processInstanceId(processInstanceId)
- .singleResult();
-
- return new TaskRepresentation(task.getId(), task.getName(), task.getProcessInstanceId());
}
}
diff --git a/spring-activiti/src/main/java/com/example/activitiwithspring/servicetasks/SendEmailServiceTask.java b/spring-activiti/src/main/java/com/example/activitiwithspring/servicetasks/SendEmailServiceTask.java
new file mode 100644
index 0000000000..c11b48f37a
--- /dev/null
+++ b/spring-activiti/src/main/java/com/example/activitiwithspring/servicetasks/SendEmailServiceTask.java
@@ -0,0 +1,12 @@
+package com.example.activitiwithspring.servicetasks;
+
+import org.activiti.engine.delegate.DelegateExecution;
+import org.activiti.engine.delegate.JavaDelegate;
+
+public class SendEmailServiceTask implements JavaDelegate {
+
+ public void execute(DelegateExecution execution) {
+ //logic to sent email confirmation
+ }
+
+}
diff --git a/spring-activiti/src/main/resources/processes/my-process.bpmn20.xml b/spring-activiti/src/main/resources/processes/my-process.bpmn20.xml
index 3ced8d6b7c..6f151af458 100644
--- a/spring-activiti/src/main/resources/processes/my-process.bpmn20.xml
+++ b/spring-activiti/src/main/resources/processes/my-process.bpmn20.xml
@@ -1,66 +1,35 @@
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
-
+
-
+
-
+
-
-
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java
index baca58f6ff..65fd33bfc6 100644
--- a/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java
+++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ActivitiControllerIntegrationTest.java
@@ -106,14 +106,12 @@ public class ActivitiControllerIntegrationTest {
.get(0);
logger.info("process instance = " + pi.getId());
- String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/complete-task-A/" + pi.getId()))
- .andReturn()
- .getResponse()
- .getContentAsString();
-
- ObjectMapper mapper = new ObjectMapper();
- TaskRepresentation task = mapper.readValue(responseBody, TaskRepresentation.class);
- assertEquals("B", task.getName());
+ this.mockMvc.perform(MockMvcRequestBuilders.get("/complete-task-A/" + pi.getId()))
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ List list = runtimeService.createProcessInstanceQuery().list();
+ assertEquals(0, list.size());
}
}
diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessEngineCreationTests.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessEngineCreationTests.java
new file mode 100644
index 0000000000..7f07191cde
--- /dev/null
+++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessEngineCreationTests.java
@@ -0,0 +1,64 @@
+package com.example.activitiwithspring;
+
+import org.activiti.engine.ProcessEngine;
+import org.activiti.engine.ProcessEngineConfiguration;
+import org.activiti.engine.ProcessEngines;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+public class ProcessEngineCreationTests {
+
+ @Test
+ public void givenXMLConfig_whenGetDefault_thenGotProcessEngine() {
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("root", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+
+ @Test
+ public void givenXMLConfig_whenCreateDefaultConfiguration_thenGotProcessEngine() {
+ ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
+ ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("root", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+
+ @Test
+ public void givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
+ ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my.activiti.cfg.xml");
+ ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+
+ @Test
+ public void givenDifferentBeanNameInXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
+ ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
+ .createProcessEngineConfigurationFromResource("my.activiti.cfg.xml", "myProcessEngineConfiguration");
+ ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+
+ @Test
+ public void givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated() {
+ ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
+ ProcessEngine processEngine = processEngineConfiguration
+ .setJdbcUrl("jdbc:h2:mem:my-own-in-mem-db;DB_CLOSE_DELAY=1000")
+ .buildProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+
+ @Test
+ public void givenNoXMLConfig_whenCreateProcessEngineConfig_thenCreated() {
+ ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
+ ProcessEngine processEngine = processEngineConfiguration
+ .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
+ .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
+ .buildProcessEngine();
+ assertNotNull(processEngine);
+ assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
+ }
+}
diff --git a/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessExecutionTests.java b/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessExecutionTests.java
new file mode 100644
index 0000000000..cae28d5281
--- /dev/null
+++ b/spring-activiti/src/test/java/com/example/activitiwithspring/ProcessExecutionTests.java
@@ -0,0 +1,97 @@
+package com.example.activitiwithspring;
+
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.activiti.engine.ActivitiException;
+import org.activiti.engine.ProcessEngine;
+import org.activiti.engine.ProcessEngines;
+import org.activiti.engine.RepositoryService;
+import org.activiti.engine.RuntimeService;
+import org.activiti.engine.TaskService;
+import org.activiti.engine.runtime.ProcessInstance;
+import org.activiti.engine.task.Task;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+public class ProcessExecutionTests {
+
+ @Test
+ public void givenBPMN_whenDeployProcess_thenDeployed() {
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+ RepositoryService repositoryService = processEngine.getRepositoryService();
+ repositoryService.createDeployment()
+ .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
+ .deploy();
+ Long count = repositoryService.createProcessDefinitionQuery().count();
+ assertTrue(count >= 1);
+ }
+
+ @Test
+ public void givenProcessDefinition_whenStartProcessInstance_thenProcessRunning() {
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+ RepositoryService repositoryService = processEngine.getRepositoryService();
+ repositoryService.createDeployment()
+ .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
+ .deploy();
+
+ Map variables = new HashMap();
+ variables.put("employeeName", "Kermit");
+ variables.put("numberOfDays", new Integer(4));
+ variables.put("vacationMotivation", "I'm really tired!");
+
+ RuntimeService runtimeService = processEngine.getRuntimeService();
+ ProcessInstance processInstance = runtimeService
+ .startProcessInstanceByKey("vacationRequest", variables);
+
+ Long count = runtimeService.createProcessInstanceQuery().count();
+ assertTrue(count >= 1);
+ }
+
+ @Test
+ public void givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues() {
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+ RepositoryService repositoryService = processEngine.getRepositoryService();
+ repositoryService.createDeployment()
+ .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
+ .deploy();
+
+ Map variables = new HashMap();
+ variables.put("employeeName", "Kermit");
+ variables.put("numberOfDays", new Integer(4));
+ variables.put("vacationMotivation", "I'm really tired!");
+
+ RuntimeService runtimeService = processEngine.getRuntimeService();
+ ProcessInstance processInstance = runtimeService
+ .startProcessInstanceByKey("vacationRequest", variables);
+
+ TaskService taskService = processEngine.getTaskService();
+ List tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
+
+ Task task = tasks.get(0);
+
+ Map taskVariables = new HashMap();
+ taskVariables.put("vacationApproved", "false");
+ taskVariables.put("comments", "We have a tight deadline!");
+ taskService.complete(task.getId(), taskVariables);
+
+ Task currentTask = taskService.createTaskQuery().taskName("Modify vacation request").singleResult();
+ assertNotNull(currentTask);
+ }
+
+ @Test(expected = ActivitiException.class)
+ public void givenProcessDefinition_whenSuspend_thenNoProcessInstanceCreated() {
+ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
+ RepositoryService repositoryService = processEngine.getRepositoryService();
+ repositoryService.createDeployment()
+ .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
+ .deploy();
+
+ RuntimeService runtimeService = processEngine.getRuntimeService();
+ repositoryService.suspendProcessDefinitionByKey("vacationRequest");
+ runtimeService.startProcessInstanceByKey("vacationRequest");
+ }
+}
diff --git a/spring-activiti/src/test/resources/activiti.cfg.xml b/spring-activiti/src/test/resources/activiti.cfg.xml
new file mode 100644
index 0000000000..1ee117d936
--- /dev/null
+++ b/spring-activiti/src/test/resources/activiti.cfg.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-activiti/src/test/resources/my.activiti.cfg.xml b/spring-activiti/src/test/resources/my.activiti.cfg.xml
new file mode 100644
index 0000000000..07e4206dad
--- /dev/null
+++ b/spring-activiti/src/test/resources/my.activiti.cfg.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-activiti/src/test/resources/org/activiti/test/vacationRequest.bpmn20.xml b/spring-activiti/src/test/resources/org/activiti/test/vacationRequest.bpmn20.xml
new file mode 100644
index 0000000000..354c633385
--- /dev/null
+++ b/spring-activiti/src/test/resources/org/activiti/test/vacationRequest.bpmn20.xml
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ ${employeeName} would like to take ${numberOfDays} day(s) of vacation (Motivation: ${reason}).
+
+
+
+
+
+
+
+
+
+ management
+
+
+
+
+
+
+
+
+
+ Your manager has disapproved your vacation request for ${numberOfDays} days.
+ Reason: ${comments}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-core/src/main/java/com/baeldung/valuewithdefaults/ValuesWithDefaultsApp.java b/spring-core/src/main/java/com/baeldung/valuewithdefaults/ValuesWithDefaultsApp.java
new file mode 100644
index 0000000000..d2cda19ae6
--- /dev/null
+++ b/spring-core/src/main/java/com/baeldung/valuewithdefaults/ValuesWithDefaultsApp.java
@@ -0,0 +1,75 @@
+package com.baeldung.valuewithdefaults;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.util.Assert;
+
+import com.google.common.collect.Lists;
+import com.google.common.primitives.Ints;
+
+/**
+ * Demonstrates setting defaults for @Value annotation. Note that there are no properties
+ * defined in the specified property source. We also assume that the user here
+ * does not have a system property named some.key.
+ *
+ */
+@Configuration
+@PropertySource(name = "myProperties", value = "valueswithdefaults.properties")
+public class ValuesWithDefaultsApp {
+
+ @Value("${some.key:my default value}")
+ private String stringWithDefaultValue;
+
+ @Value("${some.key:}")
+ private String stringWithBlankDefaultValue;
+
+ @Value("${some.key:true}")
+ private boolean booleanWithDefaultValue;
+
+ @Value("${some.key:42}")
+ private int intWithDefaultValue;
+
+ @Value("${some.key:one,two,three}")
+ private String[] stringArrayWithDefaults;
+
+ @Value("${some.key:1,2,3}")
+ private int[] intArrayWithDefaults;
+
+ @Value("#{systemProperties['some.key'] ?: 'my default system property value'}")
+ private String spelWithDefaultValue;
+
+
+ public static void main(String[] args) {
+ ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class);
+ }
+
+ @PostConstruct
+ public void afterInitialize() {
+ // strings
+ Assert.isTrue(stringWithDefaultValue.equals("my default value"));
+ Assert.isTrue(stringWithBlankDefaultValue.equals(""));
+
+ // other primitives
+ Assert.isTrue(booleanWithDefaultValue);
+ Assert.isTrue(intWithDefaultValue == 42);
+
+ // arrays
+ List stringListValues = Lists.newArrayList("one", "two", "three");
+ Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
+
+ List intListValues = Lists.newArrayList(1, 2, 3);
+ Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues));
+
+ // SpEL
+ Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
+
+ }
+}
diff --git a/spring-core/src/main/resources/valueswithdefaults.properties b/spring-core/src/main/resources/valueswithdefaults.properties
new file mode 100644
index 0000000000..e69de29bb2