java-streams-8-api - adding slf4j fixing indentation
This commit is contained in:
parent
f5ecf03890
commit
a5bde90d40
|
@ -41,6 +41,12 @@
|
|||
<version>3.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -2,44 +2,35 @@ package com.baeldung.java8;
|
|||
|
||||
import com.baeldung.streamApi.Product;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Created by Alex Vengr
|
||||
*/
|
||||
public class Java8StreamApiTest {
|
||||
|
||||
private long counter;
|
||||
|
||||
private static Logger log = Logger.getAnonymousLogger();
|
||||
private static Logger log = LoggerFactory.getLogger(Java8StreamApiTest.class);
|
||||
|
||||
private List<Product> productList;
|
||||
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
productList = Arrays.asList(new Product(23, "potatoes"),
|
||||
new Product(14, "orange"), new Product(13, "lemon"),
|
||||
new Product(23, "bread"), new Product(13, "sugar"));
|
||||
productList = Arrays.asList(
|
||||
new Product(23, "potatoes"), new Product(14, "orange"),
|
||||
new Product(13, "lemon"), new Product(23, "bread"),
|
||||
new Product(13, "sugar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,7 +108,7 @@ public class Java8StreamApiTest {
|
|||
try {
|
||||
streamOfStrings = Files.lines(path, Charset.forName("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Error creating streams from paths {}", path, e.getMessage(), e);
|
||||
}
|
||||
assertEquals("a", streamOfStrings.findFirst().get());
|
||||
|
||||
|
@ -215,7 +206,10 @@ public class Java8StreamApiTest {
|
|||
public void customCollector_whenResultContainsAllElementsFrSource_thenCorrect() {
|
||||
Collector<Product, ?, LinkedList<Product>> toLinkedList =
|
||||
Collector.of(LinkedList::new, LinkedList::add,
|
||||
(first, second) -> { first.addAll(second); return first; });
|
||||
(first, second) -> {
|
||||
first.addAll(second);
|
||||
return first;
|
||||
});
|
||||
|
||||
LinkedList<Product> linkedListOfPersons = productList.stream().collect(toLinkedList);
|
||||
assertTrue(linkedListOfPersons.containsAll(productList));
|
||||
|
@ -252,13 +246,13 @@ public class Java8StreamApiTest {
|
|||
try {
|
||||
path = Files.createTempFile(null, ".txt");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
|
||||
writer.write("a\nb\nc");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue