Merge branch 'master' into JAVA-7244-Review_log_statements_for_projects
This commit is contained in:
@@ -26,13 +26,6 @@
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -45,9 +38,4 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -7,6 +7,6 @@ public class Building {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Building.class);
|
||||
|
||||
public void paint() {
|
||||
LOGGER.info("Painting Building");
|
||||
LOGGER.debug("Painting Building");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ public class House extends Building {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(House.class);
|
||||
|
||||
public void paint() {
|
||||
LOGGER.info("Painting House");
|
||||
LOGGER.debug("Painting House");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package com.baeldung.initializationguide;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class User implements Serializable, Cloneable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(User.class);
|
||||
private static final long serialVersionUID = 1L;
|
||||
static String forum;
|
||||
private String name;
|
||||
@@ -10,12 +15,12 @@ public class User implements Serializable, Cloneable {
|
||||
|
||||
{
|
||||
id = 0;
|
||||
System.out.println("Instance Initializer");
|
||||
LOGGER.debug("Instance Initializer");
|
||||
}
|
||||
|
||||
static {
|
||||
forum = "Java";
|
||||
System.out.println("Static Initializer");
|
||||
forum = "Java";
|
||||
LOGGER.debug("Static Initializer");
|
||||
}
|
||||
|
||||
public User(String name, int id) {
|
||||
@@ -25,7 +30,7 @@ public class User implements Serializable, Cloneable {
|
||||
}
|
||||
|
||||
public User() {
|
||||
System.out.println("Constructor");
|
||||
LOGGER.debug("Constructor");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.baeldung.loops;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoopsInJava {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoopsInJava.class);
|
||||
|
||||
public int[] simple_for_loop() {
|
||||
int[] arr = new int[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
arr[i] = i;
|
||||
System.out.println("Simple for loop: i - " + i);
|
||||
LOGGER.debug("Simple for loop: i - " + i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@@ -16,7 +21,7 @@ public class LoopsInJava {
|
||||
int[] arr = new int[5];
|
||||
for (int num : intArr) {
|
||||
arr[num] = num;
|
||||
System.out.println("Enhanced for-each loop: i - " + num);
|
||||
LOGGER.debug("Enhanced for-each loop: i - " + num);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@@ -26,7 +31,7 @@ public class LoopsInJava {
|
||||
int[] arr = new int[5];
|
||||
while (i < 5) {
|
||||
arr[i] = i;
|
||||
System.out.println("While loop: i - " + i++);
|
||||
LOGGER.debug("While loop: i - " + i++);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@@ -36,7 +41,7 @@ public class LoopsInJava {
|
||||
int[] arr = new int[5];
|
||||
do {
|
||||
arr[i] = i;
|
||||
System.out.println("Do-While loop: i - " + i++);
|
||||
LOGGER.debug("Do-While loop: i - " + i++);
|
||||
} while (i < 5);
|
||||
return arr;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.baeldung.switchstatement;
|
||||
|
||||
import com.baeldung.loops.LoopsInJava;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SwitchStatement {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SwitchStatement.class);
|
||||
|
||||
public String exampleOfIF(String animal) {
|
||||
|
||||
String result;
|
||||
@@ -42,11 +48,11 @@ public class SwitchStatement {
|
||||
switch (animal) {
|
||||
|
||||
case "DOG":
|
||||
System.out.println("domestic animal");
|
||||
LOGGER.debug("domestic animal");
|
||||
result = "domestic animal";
|
||||
|
||||
default:
|
||||
System.out.println("unknown animal");
|
||||
LOGGER.debug("unknown animal");
|
||||
result = "unknown animal";
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baeldung.initializationguide.User;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoopsUnitTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoopsUnitTest.class);
|
||||
private LoopsInJava loops = new LoopsInJava();
|
||||
private static List<String> list = new ArrayList<>();
|
||||
private static Set<String> set = new HashSet<>();
|
||||
@@ -65,41 +69,44 @@ public class LoopsUnitTest {
|
||||
@Test
|
||||
public void whenUsingSimpleFor_shouldIterateList() {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
System.out.println(list.get(i));
|
||||
LOGGER.debug(list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingEnhancedFor_shouldIterateList() {
|
||||
for (String item : list) {
|
||||
System.out.println(item);
|
||||
LOGGER.debug(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingEnhancedFor_shouldIterateSet() {
|
||||
for (String item : set) {
|
||||
System.out.println(item);
|
||||
LOGGER.debug(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingEnhancedFor_shouldIterateMap() {
|
||||
for (Entry<String, Integer> entry : map.entrySet()) {
|
||||
System.out.println("Key: " + entry.getKey() + " - " + "Value: " + entry.getValue());
|
||||
LOGGER.debug("Key: " + entry.getKey() + " - " + "Value: " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingSimpleFor_shouldRunLabelledLoop() {
|
||||
aa: for (int i = 1; i <= 3; i++) {
|
||||
if (i == 1)
|
||||
aa:
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
if (i == 1) {
|
||||
continue;
|
||||
bb: for (int j = 1; j <= 3; j++) {
|
||||
}
|
||||
bb:
|
||||
for (int j = 1; j <= 3; j++) {
|
||||
if (i == 2 && j == 2) {
|
||||
break aa;
|
||||
}
|
||||
System.out.println(i + " " + j);
|
||||
LOGGER.debug(i + " " + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user