diff --git a/core-java/src/main/java/com/baeldung/string/StringToCharStream.java b/core-java/src/main/java/com/baeldung/string/StringToCharStream.java index cbe4deb9a0..883807da5d 100644 --- a/core-java/src/main/java/com/baeldung/string/StringToCharStream.java +++ b/core-java/src/main/java/com/baeldung/string/StringToCharStream.java @@ -1,57 +1,34 @@ package com.baeldung.string; -import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; -/** - * Created by smatt on 26/05/2017. - */ public class StringToCharStream { - public StringToCharStream() { - - //let's use the Stream API to manipulate a string - //this will count the occurrence of each character in the test string - + private StringToCharStream() { String testString = "tests"; - //first get an IntStream IntStream intStream = testString.chars(); IntStream intStream1 = testString.codePoints(); - //now let's map them Stream characterStream = intStream.mapToObj(c -> (char) c); Stream characterStream1 = intStream1.mapToObj(c -> (char) c); System.out.println("Counting Occurrence of Letter"); - testString = "Noww"; - //we don't want to use foreach, so . . . - - Map map = new HashMap<>(); - - testString.codePoints() - .mapToObj(c -> (char) c) - .filter(c -> Character.isLetter(c)) - .forEach(c -> { - if(map.containsKey(c)) { - map.put(c, map.get(c) + 1); - } else { - map.put(c, 1); - } - }); + Map map = "Noww".codePoints() + .mapToObj(c -> (char) c) + .filter(Character::isLetter) + .collect(Collectors.toMap(c -> c, c -> 1, Integer::sum)); //printing out the result here System.out.println(map.toString()); } - - public static void main(String [] args) { + public static void main(String[] args) { new StringToCharStream(); } - - } diff --git a/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java b/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java index 9332ae814c..52e38ff898 100644 --- a/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java +++ b/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java @@ -10,12 +10,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -/** - * Created by smatt on 09/06/2017. - */ public class StringToCharStreamUnitTest { - String testString = "Tests"; + private String testString = "Tests"; @Test public void givenTestString_whenChars_thenReturnIntStream() { @@ -37,9 +34,9 @@ public class StringToCharStreamUnitTest { } @Test - public void givenIntStream_whenMapToObj_thenReturnStringStream(){ + public void givenIntStream_whenMapToObj_thenReturnStringStream() { Stream stringStream - = testString.codePoints().mapToObj(c -> String.valueOf((char) c)); + = testString.codePoints().mapToObj(c -> String.valueOf((char) c)); assertNotNull(stringStream); } diff --git a/spring-vertx/pom.xml b/spring-vertx/pom.xml index 4ff744247b..9fbfda5d62 100644 --- a/spring-vertx/pom.xml +++ b/spring-vertx/pom.xml @@ -41,11 +41,6 @@ - - io.vertx - vertx-core - ${vertx.version} - io.vertx vertx-web @@ -70,6 +65,23 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + true + + diff --git a/spring-vertx/src/test/java/com/baeldung/vertxspring/VertxSpringApplicationIntegrationTest.java b/spring-vertx/src/test/java/com/baeldung/vertxspring/VertxSpringApplicationIntegrationTest.java index 1d4c8e16f0..bfb902e5d4 100644 --- a/spring-vertx/src/test/java/com/baeldung/vertxspring/VertxSpringApplicationIntegrationTest.java +++ b/spring-vertx/src/test/java/com/baeldung/vertxspring/VertxSpringApplicationIntegrationTest.java @@ -16,8 +16,9 @@ public class VertxSpringApplicationIntegrationTest { private TestRestTemplate restTemplate = new TestRestTemplate(); @Test - public void givenUrl_whenReceivedArticles_thenSuccess() { + public void givenUrl_whenReceivedArticles_thenSuccess() throws InterruptedException { ResponseEntity responseEntity = restTemplate.getForEntity("http://localhost:8080/api/baeldung/articles", String.class); + assertEquals(200, responseEntity.getStatusCodeValue()); }