diff --git a/algorithms/pom.xml b/algorithms/pom.xml
index 884c804d13..17d302a9ca 100644
--- a/algorithms/pom.xml
+++ b/algorithms/pom.xml
@@ -76,6 +76,17 @@
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*LongRunningUnitTest.java
+ **/*IntegrationTest.java
+
+
+
diff --git a/algorithms/src/test/java/algorithms/AntColonyOptimizationLongRunningUnitTest.java b/algorithms/src/test/java/algorithms/AntColonyOptimizationLongRunningUnitTest.java
new file mode 100644
index 0000000000..b0218ae23e
--- /dev/null
+++ b/algorithms/src/test/java/algorithms/AntColonyOptimizationLongRunningUnitTest.java
@@ -0,0 +1,22 @@
+package algorithms;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
+
+public class AntColonyOptimizationLongRunningUnitTest {
+
+ @Test
+ public void testGenerateRandomMatrix() {
+ AntColonyOptimization antTSP = new AntColonyOptimization(5);
+ Assert.assertNotNull(antTSP.generateRandomMatrix(5));
+ }
+
+ @Test
+ public void testStartAntOptimization() {
+ AntColonyOptimization antTSP = new AntColonyOptimization(5);
+ Assert.assertNotNull(antTSP.solve());
+ }
+
+}
diff --git a/algorithms/src/test/java/algorithms/AntColonyOptimizationTest.java b/algorithms/src/test/java/algorithms/AntColonyOptimizationTest.java
deleted file mode 100644
index a11f5db698..0000000000
--- a/algorithms/src/test/java/algorithms/AntColonyOptimizationTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package algorithms;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
-
-public class AntColonyOptimizationTest {
-
- @Test
- public void testGenerateRandomMatrix() {
- AntColonyOptimization antTSP = new AntColonyOptimization(5);
- Assert.assertNotNull(antTSP.generateRandomMatrix(5));
- }
-
- @Test
- public void testStartAntOptimization() {
- AntColonyOptimization antTSP = new AntColonyOptimization(5);
- Assert.assertNotNull(antTSP.solve());
- }
-
-}
diff --git a/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java b/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java
new file mode 100644
index 0000000000..fa8ecdee77
--- /dev/null
+++ b/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmLongRunningUnitTest.java
@@ -0,0 +1,16 @@
+package algorithms;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
+
+public class BinaryGeneticAlgorithmLongRunningUnitTest {
+
+ @Test
+ public void testGA() {
+ SimpleGeneticAlgorithm ga = new SimpleGeneticAlgorithm();
+ Assert.assertTrue(ga.runAlgorithm(50, "1011000100000100010000100000100111001000000100000100000000001111"));
+ }
+
+}
diff --git a/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmUnitTest.java b/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmUnitTest.java
deleted file mode 100644
index 2ba516d310..0000000000
--- a/algorithms/src/test/java/algorithms/BinaryGeneticAlgorithmUnitTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package algorithms;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
-
-public class BinaryGeneticAlgorithmUnitTest {
-
- @Test
- public void testGA() {
- SimpleGeneticAlgorithm ga = new SimpleGeneticAlgorithm();
- Assert.assertTrue(ga.runAlgorithm(50, "1011000100000100010000100000100111001000000100000100000000001111"));
- }
-
-}
diff --git a/algorithms/src/test/java/algorithms/DijkstraAlgorithmTest.java b/algorithms/src/test/java/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
similarity index 74%
rename from algorithms/src/test/java/algorithms/DijkstraAlgorithmTest.java
rename to algorithms/src/test/java/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
index 4d8cebed25..68386278fc 100644
--- a/algorithms/src/test/java/algorithms/DijkstraAlgorithmTest.java
+++ b/algorithms/src/test/java/algorithms/DijkstraAlgorithmLongRunningUnitTest.java
@@ -1,76 +1,86 @@
-package algorithms;
-
-import org.junit.Test;
-
-import com.baeldung.algorithms.ga.dijkstra.Dijkstra;
-import com.baeldung.algorithms.ga.dijkstra.Graph;
-import com.baeldung.algorithms.ga.dijkstra.Node;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-
-public class DijkstraAlgorithmTest {
-
- @Test
- public void whenSPPSolved_thenCorrect() {
-
- Node nodeA = new Node("A");
- Node nodeB = new Node("B");
- Node nodeC = new Node("C");
- Node nodeD = new Node("D");
- Node nodeE = new Node("E");
- Node nodeF = new Node("F");
-
- nodeA.addDestination(nodeB, 10);
- nodeA.addDestination(nodeC, 15);
-
- nodeB.addDestination(nodeD, 12);
- nodeB.addDestination(nodeF, 15);
-
- nodeC.addDestination(nodeE, 10);
-
- nodeD.addDestination(nodeE, 2);
- nodeD.addDestination(nodeF, 1);
-
- nodeF.addDestination(nodeE, 5);
-
- Graph graph = new Graph();
-
- graph.addNode(nodeA);
- graph.addNode(nodeB);
- graph.addNode(nodeC);
- graph.addNode(nodeD);
- graph.addNode(nodeE);
- graph.addNode(nodeF);
-
- graph = Dijkstra.calculateShortestPathFromSource(graph, nodeA);
-
- List shortestPathForNodeB = Arrays.asList(nodeA);
- List shortestPathForNodeC = Arrays.asList(nodeA);
- List shortestPathForNodeD = Arrays.asList(nodeA, nodeB);
- List shortestPathForNodeE = Arrays.asList(nodeA, nodeB, nodeD);
- List shortestPathForNodeF = Arrays.asList(nodeA, nodeB, nodeD);
-
- for (Node node : graph.getNodes()) {
- switch (node.getName()) {
- case "B":
- assertTrue(node.getShortestPath().equals(shortestPathForNodeB));
- break;
- case "C":
- assertTrue(node.getShortestPath().equals(shortestPathForNodeC));
- break;
- case "D":
- assertTrue(node.getShortestPath().equals(shortestPathForNodeD));
- break;
- case "E":
- assertTrue(node.getShortestPath().equals(shortestPathForNodeE));
- break;
- case "F":
- assertTrue(node.getShortestPath().equals(shortestPathForNodeF));
- break;
- }
- }
- }
-}
+package algorithms;
+
+import org.junit.Test;
+
+import com.baeldung.algorithms.ga.dijkstra.Dijkstra;
+import com.baeldung.algorithms.ga.dijkstra.Graph;
+import com.baeldung.algorithms.ga.dijkstra.Node;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+
+public class DijkstraAlgorithmLongRunningUnitTest {
+
+ @Test
+ public void whenSPPSolved_thenCorrect() {
+
+ Node nodeA = new Node("A");
+ Node nodeB = new Node("B");
+ Node nodeC = new Node("C");
+ Node nodeD = new Node("D");
+ Node nodeE = new Node("E");
+ Node nodeF = new Node("F");
+
+ nodeA.addDestination(nodeB, 10);
+ nodeA.addDestination(nodeC, 15);
+
+ nodeB.addDestination(nodeD, 12);
+ nodeB.addDestination(nodeF, 15);
+
+ nodeC.addDestination(nodeE, 10);
+
+ nodeD.addDestination(nodeE, 2);
+ nodeD.addDestination(nodeF, 1);
+
+ nodeF.addDestination(nodeE, 5);
+
+ Graph graph = new Graph();
+
+ graph.addNode(nodeA);
+ graph.addNode(nodeB);
+ graph.addNode(nodeC);
+ graph.addNode(nodeD);
+ graph.addNode(nodeE);
+ graph.addNode(nodeF);
+
+ graph = Dijkstra.calculateShortestPathFromSource(graph, nodeA);
+
+ List shortestPathForNodeB = Arrays.asList(nodeA);
+ List shortestPathForNodeC = Arrays.asList(nodeA);
+ List shortestPathForNodeD = Arrays.asList(nodeA, nodeB);
+ List shortestPathForNodeE = Arrays.asList(nodeA, nodeB, nodeD);
+ List shortestPathForNodeF = Arrays.asList(nodeA, nodeB, nodeD);
+
+ for (Node node : graph.getNodes()) {
+ switch (node.getName()) {
+ case "B":
+ assertTrue(node
+ .getShortestPath()
+ .equals(shortestPathForNodeB));
+ break;
+ case "C":
+ assertTrue(node
+ .getShortestPath()
+ .equals(shortestPathForNodeC));
+ break;
+ case "D":
+ assertTrue(node
+ .getShortestPath()
+ .equals(shortestPathForNodeD));
+ break;
+ case "E":
+ assertTrue(node
+ .getShortestPath()
+ .equals(shortestPathForNodeE));
+ break;
+ case "F":
+ assertTrue(node
+ .getShortestPath()
+ .equals(shortestPathForNodeF));
+ break;
+ }
+ }
+ }
+}
diff --git a/algorithms/src/test/java/algorithms/RtFiniteStateMachineTest.java b/algorithms/src/test/java/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
similarity index 72%
rename from algorithms/src/test/java/algorithms/RtFiniteStateMachineTest.java
rename to algorithms/src/test/java/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
index 089b38ec3f..c6800e9a64 100644
--- a/algorithms/src/test/java/algorithms/RtFiniteStateMachineTest.java
+++ b/algorithms/src/test/java/algorithms/RtFiniteStateMachineLongRunningUnitTest.java
@@ -1,38 +1,37 @@
package algorithms;
-import static org.junit.Assert.*;
-import org.junit.Test;
import com.baeldung.automata.*;
+import org.junit.Test;
-/**
- * Tests for {@link RtFiniteStateMachine}
- */
-public final class RtFiniteStateMachineTest {
+import static org.junit.Assert.assertTrue;
+
+public final class RtFiniteStateMachineLongRunningUnitTest {
@Test
public void acceptsSimplePair() {
String json = "{\"key\":\"value\"}";
FiniteStateMachine machine = this.buildJsonStateMachine();
- for (int i=0;itest
-
- org.testng
- testng
- ${testng.version}
- test
-
-
org.mockito
mockito-core
diff --git a/core-java/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java b/core-java/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java
index b19bc3fe1a..6bb055d360 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/sleepwait/ThreadA.java
@@ -1,9 +1,15 @@
package com.baeldung.concurrent.sleepwait;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/***
* Example of waking up a waiting thread
*/
public class ThreadA {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadA.class);
+
private static final ThreadB b = new ThreadB();
public static void main(String... args) throws InterruptedException {
@@ -11,11 +17,11 @@ public class ThreadA {
synchronized (b) {
while (b.sum == 0) {
- System.out.println("Waiting for ThreadB to complete...");
+ LOG.debug("Waiting for ThreadB to complete...");
b.wait();
}
- System.out.println("ThreadB has completed. Sum from that thread is: " + b.sum);
+ LOG.debug("ThreadB has completed. Sum from that thread is: " + b.sum);
}
}
}
diff --git a/core-java/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java b/core-java/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java
index e84fe29d87..0311d9b0b2 100644
--- a/core-java/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java
+++ b/core-java/src/main/java/com/baeldung/concurrent/sleepwait/WaitSleepExample.java
@@ -1,9 +1,15 @@
package com.baeldung.concurrent.sleepwait;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/***
* Example of wait() and sleep() methods
*/
public class WaitSleepExample {
+
+ private static final Logger LOG = LoggerFactory.getLogger(WaitSleepExample.class);
+
private static final Object LOCK = new Object();
public static void main(String... args) throws InterruptedException {
@@ -12,11 +18,11 @@ public class WaitSleepExample {
private static void sleepWaitInSyncronizedBlocks() throws InterruptedException {
Thread.sleep(1000); // called on the thread
- System.out.println("Thread '" + Thread.currentThread().getName() + "' is woken after sleeping for 1 second");
+ LOG.debug("Thread '" + Thread.currentThread().getName() + "' is woken after sleeping for 1 second");
synchronized (LOCK) {
LOCK.wait(1000); // called on the object, synchronization required
- System.out.println("Object '" + LOCK + "' is woken after waiting for 1 second");
+ LOG.debug("Object '" + LOCK + "' is woken after waiting for 1 second");
}
}
diff --git a/core-java/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java b/core-java/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java
index 49030b5352..f9028bd159 100644
--- a/core-java/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java
+++ b/core-java/src/main/java/com/baeldung/dirmonitoring/DirectoryMonitoringExample.java
@@ -1,14 +1,19 @@
package com.baeldung.dirmonitoring;
-import java.io.File;
-
import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
public class DirectoryMonitoringExample {
+ private static final Logger LOG = LoggerFactory.getLogger(DirectoryMonitoringExample.class);
+
+
public static final int POLL_INTERVAL = 500;
public static void main(String[] args) throws Exception {
@@ -17,17 +22,17 @@ public class DirectoryMonitoringExample {
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
@Override
public void onFileCreate(File file) {
- System.out.println("File: " + file.getName() + " created");
+ LOG.debug("File: " + file.getName() + " created");
}
@Override
public void onFileDelete(File file) {
- System.out.println("File: " + file.getName() + " deleted");
+ LOG.debug("File: " + file.getName() + " deleted");
}
@Override
public void onFileChange(File file) {
- System.out.println("File: " + file.getName() + " changed");
+ LOG.debug("File: " + file.getName() + " changed");
}
};
observer.addListener(listener);
diff --git a/core-java/src/main/java/com/baeldung/doublecolon/MacbookPro.java b/core-java/src/main/java/com/baeldung/doublecolon/MacbookPro.java
index 3fc459c681..f5c31e9653 100644
--- a/core-java/src/main/java/com/baeldung/doublecolon/MacbookPro.java
+++ b/core-java/src/main/java/com/baeldung/doublecolon/MacbookPro.java
@@ -1,9 +1,14 @@
package com.baeldung.doublecolon;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.function.Function;
public class MacbookPro extends Computer {
+ private static final Logger LOG = LoggerFactory.getLogger(MacbookPro.class);
+
public MacbookPro(int age, String color) {
super(age, color);
}
@@ -14,12 +19,12 @@ public class MacbookPro extends Computer {
@Override
public void turnOnPc() {
- System.out.println("MacbookPro turned on");
+ LOG.debug("MacbookPro turned on");
}
@Override
public void turnOffPc() {
- System.out.println("MacbookPro turned off");
+ LOG.debug("MacbookPro turned off");
}
@Override
@@ -27,7 +32,7 @@ public class MacbookPro extends Computer {
Function function = super::calculateValue;
final Double pcValue = function.apply(initialValue);
- System.out.println("First value is:" + pcValue);
+ LOG.debug("First value is:" + pcValue);
return pcValue + (initialValue / 10);
}
diff --git a/core-java/src/main/java/com/baeldung/java/map/MyKey.java b/core-java/src/main/java/com/baeldung/java/map/MyKey.java
index a2587c1dc1..ae3c3edc39 100644
--- a/core-java/src/main/java/com/baeldung/java/map/MyKey.java
+++ b/core-java/src/main/java/com/baeldung/java/map/MyKey.java
@@ -1,6 +1,11 @@
package com.baeldung.java.map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class MyKey {
+ private static final Logger LOG = LoggerFactory.getLogger(MyKey.class);
+
private String name;
private int id;
@@ -27,7 +32,7 @@ public class MyKey {
@Override
public int hashCode() {
- System.out.println("Calling hashCode()");
+ LOG.debug("Calling hashCode()");
return id;
}
@@ -38,7 +43,7 @@ public class MyKey {
@Override
public boolean equals(Object obj) {
- System.out.println("Calling equals() for key: " + obj);
+ LOG.debug("Calling equals() for key: " + obj);
if (this == obj)
return true;
if (obj == null)
diff --git a/core-java/src/main/java/com/baeldung/jmx/Game.java b/core-java/src/main/java/com/baeldung/jmx/Game.java
index f38db27601..79256c0659 100644
--- a/core-java/src/main/java/com/baeldung/jmx/Game.java
+++ b/core-java/src/main/java/com/baeldung/jmx/Game.java
@@ -1,23 +1,28 @@
package com.baeldung.jmx;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class Game implements GameMBean {
+ private static final Logger LOG = LoggerFactory.getLogger(Game.class);
+
private String playerName;
@Override
public void playFootball(String clubName) {
- System.out.println(this.playerName + " playing football for " + clubName);
+ LOG.debug(this.playerName + " playing football for " + clubName);
}
@Override
public String getPlayerName() {
- System.out.println("Return playerName " + this.playerName);
+ LOG.debug("Return playerName " + this.playerName);
return playerName;
}
@Override
public void setPlayerName(String playerName) {
- System.out.println("Set playerName to value " + playerName);
+ LOG.debug("Set playerName to value " + playerName);
this.playerName = playerName;
}
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 6f9c30ab50..220b9a8ec6 100644
--- a/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java
+++ b/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java
@@ -1,19 +1,20 @@
package com.baeldung.jmx;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
import java.lang.management.ManagementFactory;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
public class JMXTutorialMainlauncher {
+ private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class);
+
+
public static void main(String[] args) {
// TODO Auto-generated method stub
- System.out.println("This is basic JMX tutorial");
+ LOG.debug("This is basic JMX tutorial");
ObjectName objectName = null;
try {
objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
@@ -27,8 +28,8 @@ public class JMXTutorialMainlauncher {
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
e.printStackTrace();
}
- System.out.println("Registration for Game mbean with the platform server is successfull");
- System.out.println("Please open jconsole to access Game mbean");
+ LOG.debug("Registration for Game mbean with the platform server is successfull");
+ LOG.debug("Please open jconsole to access Game mbean");
while (true) {
// to ensure application does not terminate
}
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 570bd60b2d..cf5c253276 100644
--- a/core-java/src/main/java/com/baeldung/socket/EchoClient.java
+++ b/core-java/src/main/java/com/baeldung/socket/EchoClient.java
@@ -1,9 +1,16 @@
package com.baeldung.socket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.*;
import java.net.*;
public class EchoClient {
+
+
+ private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
+
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
@@ -14,7 +21,7 @@ public class EchoClient {
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e) {
- System.out.print(e);
+ LOG.debug("Error when initializing connection", e);
}
}
@@ -34,7 +41,7 @@ public class EchoClient {
out.close();
clientSocket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug("error when closing", e);
}
}
diff --git a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java
index b920967545..a9f055f8f4 100644
--- a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java
+++ b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java
@@ -1,9 +1,15 @@
package com.baeldung.socket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.*;
import java.io.*;
public class EchoMultiServer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EchoMultiServer.class);
+
private ServerSocket serverSocket;
public void start(int port) {
@@ -57,7 +63,7 @@ public class EchoMultiServer {
clientSocket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
}
diff --git a/core-java/src/main/java/com/baeldung/socket/EchoServer.java b/core-java/src/main/java/com/baeldung/socket/EchoServer.java
index dfd281d51c..a869e98966 100644
--- a/core-java/src/main/java/com/baeldung/socket/EchoServer.java
+++ b/core-java/src/main/java/com/baeldung/socket/EchoServer.java
@@ -1,9 +1,15 @@
package com.baeldung.socket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.*;
import java.io.*;
public class EchoServer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EchoServer.class);
+
private ServerSocket serverSocket;
private Socket clientSocket;
private PrintWriter out;
@@ -24,7 +30,7 @@ public class EchoServer {
out.println(inputLine);
}
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
@@ -36,7 +42,7 @@ public class EchoServer {
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
diff --git a/core-java/src/main/java/com/baeldung/socket/GreetClient.java b/core-java/src/main/java/com/baeldung/socket/GreetClient.java
index e6f14bb2b6..38ad016919 100644
--- a/core-java/src/main/java/com/baeldung/socket/GreetClient.java
+++ b/core-java/src/main/java/com/baeldung/socket/GreetClient.java
@@ -1,5 +1,8 @@
package com.baeldung.socket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -7,6 +10,9 @@ import java.io.PrintWriter;
import java.net.Socket;
public class GreetClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EchoMultiServer.class);
+
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
@@ -17,7 +23,7 @@ public class GreetClient {
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e) {
-
+ LOG.debug(e.getMessage());
}
}
@@ -37,7 +43,7 @@ public class GreetClient {
out.close();
clientSocket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
diff --git a/core-java/src/main/java/com/baeldung/socket/GreetServer.java b/core-java/src/main/java/com/baeldung/socket/GreetServer.java
index 05bc65a65e..f46db91959 100644
--- a/core-java/src/main/java/com/baeldung/socket/GreetServer.java
+++ b/core-java/src/main/java/com/baeldung/socket/GreetServer.java
@@ -1,9 +1,15 @@
package com.baeldung.socket;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.*;
import java.io.*;
public class GreetServer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GreetServer.class);
+
private ServerSocket serverSocket;
private Socket clientSocket;
private PrintWriter out;
@@ -21,7 +27,7 @@ public class GreetServer {
else
out.println("unrecognised greeting");
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
@@ -33,7 +39,7 @@ public class GreetServer {
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.debug(e.getMessage());
}
}
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 097b516f8c..ae00fc7cb4 100644
--- a/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java
+++ b/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java
@@ -1,9 +1,15 @@
package com.baeldung.stream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.stream.Stream;
public class InfiniteStreams {
+
+ private static final Logger LOG = LoggerFactory.getLogger(InfiniteStreams.class);
+
public static void main(String[] args) {
doWhileOldWay();
@@ -15,7 +21,7 @@ public class InfiniteStreams {
int i = 0;
while (i < 10) {
- System.out.println(i);
+ LOG.debug("{}", i);
i++;
}
}
diff --git a/core-java/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java b/core-java/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java
index 0d6a7e5572..de7e4a0369 100644
--- a/core-java/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java
+++ b/core-java/src/main/java/com/baeldung/threadlocal/ThreadLocalWithUserContext.java
@@ -1,7 +1,11 @@
package com.baeldung.threadlocal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ThreadLocalWithUserContext implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadLocalWithUserContext.class);
+
private static final ThreadLocal userContext = new ThreadLocal<>();
private final Integer userId;
private UserRepository userRepository = new UserRepository();
@@ -15,6 +19,6 @@ public class ThreadLocalWithUserContext implements Runnable {
public void run() {
String userName = userRepository.getUserNameForUserId(userId);
userContext.set(new Context(userName));
- System.out.println("thread context for given userId: " + userId + " is: " + userContext.get());
+ LOG.debug("thread context for given userId: " + userId + " is: " + userContext.get());
}
}
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 a498d08041..69d7ff2390 100644
--- a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java
+++ b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java
@@ -1,9 +1,15 @@
package com.baeldung.transferqueue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.concurrent.TransferQueue;
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;
@@ -19,10 +25,10 @@ public class Consumer implements Runnable {
public void run() {
for (int i = 0; i < numberOfMessagesToConsume; i++) {
try {
- System.out.println("Consumer: " + name + " is waiting to take element...");
+ LOG.debug("Consumer: " + name + " is waiting to take element...");
String element = transferQueue.take();
longProcessing(element);
- System.out.println("Consumer: " + name + " received element: " + element);
+ LOG.debug("Consumer: " + name + " received element: " + element);
} catch (InterruptedException e) {
e.printStackTrace();
}
diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Producer.java b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java
index c6edc99bb5..c7df7c410a 100644
--- a/core-java/src/main/java/com/baeldung/transferqueue/Producer.java
+++ b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java
@@ -1,10 +1,15 @@
package com.baeldung.transferqueue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class Producer implements Runnable {
+ private static final Logger LOG = LoggerFactory.getLogger(Producer.class);
+
private final TransferQueue transferQueue;
private final String name;
private final Integer numberOfMessagesToProduce;
@@ -20,13 +25,13 @@ public class Producer implements Runnable {
public void run() {
for (int i = 0; i < numberOfMessagesToProduce; i++) {
try {
- System.out.println("Producer: " + name + " is waiting to transfer...");
+ LOG.debug("Producer: " + name + " is waiting to transfer...");
boolean added = transferQueue.tryTransfer("A" + i, 4000, TimeUnit.MILLISECONDS);
if (added) {
numberOfProducedMessages.incrementAndGet();
- System.out.println("Producer: " + name + " transferred element: A" + i);
+ LOG.debug("Producer: " + name + " transferred element: A" + i);
} else {
- System.out.println("can not add an element due to the timeout");
+ LOG.debug("can not add an element due to the timeout");
}
} catch (InterruptedException e) {
e.printStackTrace();
diff --git a/core-java/src/test/java/com/baeldung/PrimitiveConversionsJUnitTest.java b/core-java/src/test/java/com/baeldung/PrimitiveConversionsJUnitTest.java
index 10ceaf85a4..69a6c18dfd 100644
--- a/core-java/src/test/java/com/baeldung/PrimitiveConversionsJUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/PrimitiveConversionsJUnitTest.java
@@ -1,13 +1,14 @@
package com.baeldung;
import org.junit.Test;
-import static org.junit.Assert.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
-/**
- *
- * @author paulo.motta
- */
public class PrimitiveConversionsJUnitTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PrimitiveConversionsJUnitTest.class);
@Test
public void givenDataWithLessBits_whenAttributingToLargerSizeVariable_thenNoSpecialNotation() {
@@ -60,36 +61,36 @@ public class PrimitiveConversionsJUnitTest {
@Test
public void givenByteValue_whenConvertingToChar_thenWidenAndNarrowTakesPlace(){
byte myLargeValueByte = (byte) 130; //0b10000010
- System.out.println(myLargeValueByte); //0b10000010 -126
+ LOG.debug("{}", myLargeValueByte); //0b10000010 -126
assertEquals( -126, myLargeValueByte);
int myLargeValueInt = myLargeValueByte;
- System.out.println(myLargeValueInt); //0b11111111 11111111 11111111 10000010 -126
+ LOG.debug("{}", myLargeValueInt); //0b11111111 11111111 11111111 10000010 -126
assertEquals( -126, myLargeValueInt);
char myLargeValueChar = (char) myLargeValueByte;
- System.out.println(myLargeValueChar);//0b11111111 10000010 unsigned 0xFF82
+ LOG.debug("{}", myLargeValueChar);//0b11111111 10000010 unsigned 0xFF82
assertEquals(0xFF82, myLargeValueChar);
myLargeValueInt = myLargeValueChar;
- System.out.println(myLargeValueInt); //0b11111111 10000010 65410
+ LOG.debug("{}", myLargeValueInt); //0b11111111 10000010 65410
assertEquals(65410, myLargeValueInt);
byte myOtherByte = (byte) myLargeValueInt;
- System.out.println(myOtherByte); //0b10000010 -126
+ LOG.debug("{}", myOtherByte); //0b10000010 -126
assertEquals( -126, myOtherByte);
char myLargeValueChar2 = 130; //This is an int not a byte!
- System.out.println(myLargeValueChar2);//0b00000000 10000010 unsigned 0x0082
+ LOG.debug("{}", myLargeValueChar2);//0b00000000 10000010 unsigned 0x0082
assertEquals(0x0082, myLargeValueChar2);
int myLargeValueInt2 = myLargeValueChar2;
- System.out.println(myLargeValueInt2); //0b00000000 10000010 130
+ LOG.debug("{}", myLargeValueInt2); //0b00000000 10000010 130
assertEquals(130, myLargeValueInt2);
byte myOtherByte2 = (byte) myLargeValueInt2;
- System.out.println(myOtherByte2); //0b10000010 -126
+ LOG.debug("{}", myOtherByte2); //0b10000010 -126
assertEquals( -126, myOtherByte2);
}
diff --git a/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureUnitTest.java b/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureUnitTest.java
index df12c3d79e..501cb1afa0 100644
--- a/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureUnitTest.java
@@ -1,20 +1,21 @@
package com.baeldung.completablefuture;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import org.junit.Test;
-
public class CompletableFutureUnitTest {
+ private static final Logger LOG = LoggerFactory.getLogger(CompletableFutureUnitTest.class);
+
+
@Test
public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
Future completableFuture = calculateAsync();
@@ -72,7 +73,7 @@ public class CompletableFutureUnitTest {
public void whenAddingThenAcceptToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
- CompletableFuture future = completableFuture.thenAccept(s -> System.out.println("Computation returned: " + s));
+ CompletableFuture future = completableFuture.thenAccept(s -> LOG.debug("Computation returned: " + s));
future.get();
}
@@ -81,7 +82,7 @@ public class CompletableFutureUnitTest {
public void whenAddingThenRunToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
- CompletableFuture future = completableFuture.thenRun(() -> System.out.println("Computation finished."));
+ CompletableFuture future = completableFuture.thenRun(() -> LOG.debug("Computation finished."));
future.get();
}
@@ -111,7 +112,7 @@ public class CompletableFutureUnitTest {
@Test
public void whenUsingThenAcceptBoth_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
- CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> System.out.println(s1 + s2));
+ CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> LOG.debug(s1 + s2));
}
@Test
diff --git a/core-java/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java b/core-java/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java
index bc63fbe6f7..84d7a55504 100644
--- a/core-java/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/concurrent/future/SquareCalculatorIntegrationTest.java
@@ -5,6 +5,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.concurrent.*;
@@ -13,6 +15,9 @@ import static org.junit.Assert.assertTrue;
public class SquareCalculatorIntegrationTest {
+ private static final Logger LOG = LoggerFactory.getLogger(SquareCalculatorIntegrationTest.class);
+
+
@Rule
public TestName name = new TestName();
@@ -28,7 +33,7 @@ public class SquareCalculatorIntegrationTest {
Future result2 = squareCalculator.calculate(1000);
while (!result1.isDone() || !result2.isDone()) {
- System.out.println(String.format("Task 1 is %s and Task 2 is %s.", result1.isDone() ? "done" : "not done", result2.isDone() ? "done" : "not done"));
+ LOG.debug(String.format("Task 1 is %s and Task 2 is %s.", result1.isDone() ? "done" : "not done", result2.isDone() ? "done" : "not done"));
Thread.sleep(300);
}
@@ -54,7 +59,7 @@ public class SquareCalculatorIntegrationTest {
Future result2 = squareCalculator.calculate(1000);
while (!result1.isDone() || !result2.isDone()) {
- System.out.println(String.format("Task 1 is %s and Task 2 is %s.", result1.isDone() ? "done" : "not done", result2.isDone() ? "done" : "not done"));
+ LOG.debug(String.format("Task 1 is %s and Task 2 is %s.", result1.isDone() ? "done" : "not done", result2.isDone() ? "done" : "not done"));
Thread.sleep(300);
}
@@ -84,6 +89,6 @@ public class SquareCalculatorIntegrationTest {
@After
public void end() {
- System.out.println(String.format("Test %s took %s ms \n", name.getMethodName(), System.currentTimeMillis() - start));
+ LOG.debug(String.format("Test %s took %s ms \n", name.getMethodName(), System.currentTimeMillis() - start));
}
}
diff --git a/core-java/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java b/core-java/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java
index 2a8eda896b..9f7b828a9c 100644
--- a/core-java/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/concurrent/priorityblockingqueue/PriorityBlockingQueueIntegrationTest.java
@@ -1,6 +1,8 @@
package com.baeldung.concurrent.priorityblockingqueue;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.concurrent.PriorityBlockingQueue;
@@ -11,6 +13,9 @@ import static org.assertj.core.util.Lists.newArrayList;
public class PriorityBlockingQueueIntegrationTest {
+ private static final Logger LOG = LoggerFactory.getLogger(PriorityBlockingQueueIntegrationTest.class);
+
+
@Test
public void givenUnorderedValues_whenPolling_thenShouldOrderQueue() throws InterruptedException {
PriorityBlockingQueue queue = new PriorityBlockingQueue<>();
@@ -32,11 +37,11 @@ public class PriorityBlockingQueueIntegrationTest {
PriorityBlockingQueue queue = new PriorityBlockingQueue<>();
final Thread thread = new Thread(() -> {
- System.out.println("Polling...");
+ LOG.debug("Polling...");
while (true) {
try {
Integer poll = queue.take();
- System.out.println("Polled: " + poll);
+ LOG.debug("Polled: " + poll);
} catch (InterruptedException e) {
}
}
@@ -44,7 +49,7 @@ public class PriorityBlockingQueueIntegrationTest {
thread.start();
Thread.sleep(TimeUnit.SECONDS.toMillis(5));
- System.out.println("Adding to queue");
+ LOG.debug("Adding to queue");
queue.addAll(newArrayList(1, 5, 6, 1, 2, 6, 7));
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
diff --git a/core-java/src/test/java/com/baeldung/dynamicproxy/DynamicProxyTest.java b/core-java/src/test/java/com/baeldung/dynamicproxy/DynamicProxyTest.java
index 4386b11797..dc7f9366ba 100644
--- a/core-java/src/test/java/com/baeldung/dynamicproxy/DynamicProxyTest.java
+++ b/core-java/src/test/java/com/baeldung/dynamicproxy/DynamicProxyTest.java
@@ -7,7 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
-import static org.testng.Assert.fail;
+import static org.junit.Assert.fail;
public class DynamicProxyTest {
diff --git a/core-java/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java b/core-java/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java
index 6f3384c8eb..1036df0bb8 100644
--- a/core-java/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/functionalinterface/FunctionalInterfaceUnitTest.java
@@ -1,8 +1,9 @@
package com.baeldung.functionalinterface;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import com.google.common.util.concurrent.Uninterruptibles;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
@@ -14,12 +15,13 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.junit.Test;
-
-import com.google.common.util.concurrent.Uninterruptibles;
+import static org.junit.Assert.*;
public class FunctionalInterfaceUnitTest {
+ private static final Logger LOG = LoggerFactory.getLogger(FunctionalInterfaceUnitTest.class);
+
+
@Test
public void whenPassingLambdaToComputeIfAbsent_thenTheValueGetsComputedAndPutIntoMap() {
Map nameMap = new HashMap<>();
@@ -65,7 +67,7 @@ public class FunctionalInterfaceUnitTest {
@Test
public void whenPassingLambdaToThreadConstructor_thenLambdaInferredToRunnable() {
- Thread thread = new Thread(() -> System.out.println("Hello From Another Thread"));
+ Thread thread = new Thread(() -> LOG.debug("Hello From Another Thread"));
thread.start();
}
@@ -93,7 +95,7 @@ public class FunctionalInterfaceUnitTest {
@Test
public void whenUsingConsumerInForEach_thenConsumerExecutesForEachListElement() {
List names = Arrays.asList("John", "Freddy", "Samuel");
- names.forEach(name -> System.out.println("Hello, " + name));
+ names.forEach(name -> LOG.debug("Hello, " + name));
}
@Test
@@ -103,7 +105,7 @@ public class FunctionalInterfaceUnitTest {
ages.put("Freddy", 24);
ages.put("Samuel", 30);
- ages.forEach((name, age) -> System.out.println(name + " is " + age + " years old"));
+ ages.forEach((name, age) -> LOG.debug(name + " is " + age + " years old"));
}
@Test
diff --git a/core-java/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionTest.java b/core-java/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionTest.java
index 100d25ab8d..d12f07286b 100644
--- a/core-java/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionTest.java
+++ b/core-java/src/test/java/com/baeldung/java/collections/ConcurrentModificationExceptionTest.java
@@ -6,9 +6,10 @@ import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import static java.util.Arrays.asList;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
public class ConcurrentModificationExceptionTest {
+
@Test
public void changingContentWithSetDoesNotThrowConcurrentModificationException() throws Exception {
ArrayList