diff --git a/asciidoctor/README.md b/asciidoctor/README.md
new file mode 100644
index 0000000000..164200d227
--- /dev/null
+++ b/asciidoctor/README.md
@@ -0,0 +1,3 @@
+### Relevant articles
+
+- [Introduction to Asciidoctor](http://www.baeldung.com/introduction-to-asciidoctor)
\ No newline at end of file
diff --git a/asciidoctor/log4j.properties b/asciidoctor/log4j.properties
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/asciidoctor/pom.xml b/asciidoctor/pom.xml
new file mode 100644
index 0000000000..989f6e5354
--- /dev/null
+++ b/asciidoctor/pom.xml
@@ -0,0 +1,56 @@
+
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ asciidoctor
+ asciidoctor
+
+
+
+ org.asciidoctor
+ asciidoctor-maven-plugin
+ 1.5.5
+
+
+ org.asciidoctor
+ asciidoctorj-pdf
+ 1.5.0-alpha.15
+
+
+
+
+ output-pdf
+ generate-resources
+
+ process-asciidoc
+
+
+
+
+ src/docs/asciidoc
+ target/docs/asciidoc
+ pdf
+
+
+
+
+
+
+
+ org.asciidoctor
+ asciidoctorj
+ 1.5.4
+
+
+ org.asciidoctor
+ asciidoctorj-pdf
+ 1.5.0-alpha.11
+
+
+
diff --git a/libraries/src/docs/asciidoc/test.adoc b/asciidoctor/src/docs/asciidoc/test.adoc
similarity index 100%
rename from libraries/src/docs/asciidoc/test.adoc
rename to asciidoctor/src/docs/asciidoc/test.adoc
diff --git a/libraries/src/main/java/com/baeldung/asciidoctor/AsciidoctorDemo.java b/asciidoctor/src/main/java/com/baeldung/asciidoctor/AsciidoctorDemo.java
similarity index 100%
rename from libraries/src/main/java/com/baeldung/asciidoctor/AsciidoctorDemo.java
rename to asciidoctor/src/main/java/com/baeldung/asciidoctor/AsciidoctorDemo.java
diff --git a/libraries/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoTest.java b/asciidoctor/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoTest.java
similarity index 100%
rename from libraries/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoTest.java
rename to asciidoctor/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoTest.java
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 2ad670fe5d..1b02e5d291 100644
--- a/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java
+++ b/core-java/src/test/java/com/baeldung/string/StringToCharStreamUnitTest.java
@@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public class StringToCharStreamUnitTest {
@@ -44,7 +43,6 @@ public class StringToCharStreamUnitTest {
.mapToObj(c -> (char) c);
Stream characterStream1 = testString.codePoints()
.mapToObj(c -> (char) c);
-
assertNotNull("IntStream returned by chars() did not map to Stream", characterStream);
assertNotNull("IntStream returned by codePoints() did not map to Stream", characterStream1);
}
diff --git a/libraries/pom.xml b/libraries/pom.xml
index de001ef622..23fec48075 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
parent-modules
com.baeldung
@@ -59,7 +59,7 @@
${basedir}/datanucleus.properties
${basedir}/log4j.properties
true
- false
+ false
@@ -70,32 +70,6 @@
-
- org.asciidoctor
- asciidoctor-maven-plugin
- 1.5.5
-
-
- org.asciidoctor
- asciidoctorj-pdf
- 1.5.0-alpha.15
-
-
-
-
- output-pdf
- generate-resources
-
- process-asciidoc
-
-
-
-
- src/docs/asciidoc
- target/docs/asciidoc
- pdf
-
-
@@ -107,15 +81,20 @@
${cglib.version}
- commons-beanutils
- commons-beanutils
- ${commons-beanutils.version}
-
+ commons-beanutils
+ commons-beanutils
+ ${commons-beanutils.version}
+
org.apache.commons
commons-lang3
${commons-lang.version}
+
+ org.apache.commons
+ commons-collections4
+ ${commons.collections.version}
+
org.jasypt
jasypt
@@ -211,12 +190,6 @@
serenity-core
${serenity.version}
test
-
-
- org.asciidoctor
- asciidoctor-java-integration
-
-
net.serenity-bdd
@@ -272,7 +245,7 @@
org.datanucleus
datanucleus-maven-plugin
5.0.2
-
+
org.datanucleus
datanucleus-xml
@@ -324,11 +297,11 @@
1.4.195
- pl.pragmatists
- JUnitParams
- ${jUnitParams.version}
- test
-
+ pl.pragmatists
+ JUnitParams
+ ${jUnitParams.version}
+ test
+
org.quartz-scheduler
quartz
@@ -360,22 +333,18 @@
netty-all
${netty.version}
-
- org.asciidoctor
- asciidoctorj
- 1.5.4
-
-
- org.asciidoctor
- asciidoctorj-pdf
- 1.5.0-alpha.11
-
-
+
org.apache.opennlp
opennlp-tools
1.8.0
+
+ junit
+ junit
+ ${junit.version}
+ test
+
info.debatty
java-lsh
@@ -392,14 +361,12 @@
groovy-all
2.4.10
-
-
0.7.0
3.2.4
3.5
- 1.9.3
+ 1.9.3
1.9.2
1.2
3.21.0-GA
@@ -420,6 +387,8 @@
1.4.0
1.1.0
4.1.10.Final
+ 4.1
+ 4.12
0.10
3.5.0
diff --git a/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java
new file mode 100644
index 0000000000..4d264e3aea
--- /dev/null
+++ b/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java
@@ -0,0 +1,83 @@
+package com.baeldung.commons.collections;
+
+import org.apache.commons.collections4.SetUtils;
+import org.apache.commons.collections4.set.TransformedSet;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by smatt on 21/06/2017.
+ */
+public class SetUtilsUnitTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void givenSetAndPredicate_whenPredicatedSet_thenValidateSet_and_throw_IllegalArgumentException() {
+ Set sourceSet = new HashSet<>();
+ sourceSet.addAll(Arrays.asList("London", "Lagos", "Err Source1"));
+ Set validatingSet
+ = SetUtils.predicatedSet(sourceSet, (s) -> s.startsWith("L"));
+ validatingSet.add("Err Source2");
+ }
+
+ @Test
+ public void givenTwoSets_whenDifference_thenSetView() {
+ Set a = new HashSet<>(Arrays.asList(1,2,5));
+ Set b = new HashSet<>(Arrays.asList(1,2));
+ SetUtils.SetView result = SetUtils.difference(a, b);
+ assertTrue(result.size() == 1 && result.contains(5));
+ }
+
+ @Test
+ public void givenTwoSets_whenUnion_thenUnionResult() {
+ Set a = new HashSet<>(Arrays.asList(1,2,5));
+ Set b = new HashSet<>(Arrays.asList(1,2));
+ Set expected = new HashSet<>(Arrays.asList(1,2,5));
+ SetUtils.SetView union = SetUtils.union(a, b);
+ assertTrue(SetUtils.isEqualSet(expected, union));
+ }
+
+ @Test
+ public void givenTwoSets_whenIntersection_thenIntersectionResult() {
+ Set a = new HashSet<>(Arrays.asList(1,2,5));
+ Set b = new HashSet<>(Arrays.asList(1,2));
+ Set expected = new HashSet<>(Arrays.asList(1,2));
+ SetUtils.SetView intersect = SetUtils.intersection(a, b);
+ assertTrue(SetUtils.isEqualSet(expected, intersect));
+ }
+
+ @Test
+ public void givenSet_whenTransformedSet_thenTransformedResult() {
+ Set a = SetUtils.transformedSet(new HashSet<>(), (e) -> e * 2 );
+ a.add(2);
+ assertEquals(a.toArray()[0], 4);
+
+ Set source = new HashSet<>(Arrays.asList(1));
+ Set newSet = TransformedSet.transformedSet(source, (e) -> e * 2);
+ assertEquals(newSet.toArray()[0], 2);
+ assertEquals(source.toArray()[0], 2);
+ }
+
+ @Test
+ public void givenTwoSet_whenDisjunction_thenDisjunctionSet() {
+ Set a = new HashSet<>(Arrays.asList(1,2,5));
+ Set b = new HashSet<>(Arrays.asList(1,2,3));
+ SetUtils.SetView result = SetUtils.disjunction(a, b);
+ assertTrue(result.toSet().contains(5) && result.toSet().contains(3));
+ }
+
+ @Test
+ public void givenSet_when_OrderedSet_thenMaintainElementOrder() {
+ Set set = new HashSet<>(Arrays.asList(10,1,5));
+ System.out.println("unordered set: " + set);
+
+ Set orderedSet = SetUtils.orderedSet(new HashSet<>());
+ orderedSet.addAll(Arrays.asList(10,1,5));
+ System.out.println("ordered set = " + orderedSet);
+ }
+}
\ No newline at end of file
diff --git a/libraries/src/test/java/com/baeldung/commons/collections/orderedmap/OrderedMapUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/orderedmap/OrderedMapUnitTest.java
index 5392daea3b..6b2777c289 100644
--- a/libraries/src/test/java/com/baeldung/commons/collections/orderedmap/OrderedMapUnitTest.java
+++ b/libraries/src/test/java/com/baeldung/commons/collections/orderedmap/OrderedMapUnitTest.java
@@ -1,5 +1,10 @@
package com.baeldung.commons.collections.orderedmap;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.collections4.OrderedMap;
import org.apache.commons.collections4.OrderedMapIterator;
import org.apache.commons.collections4.map.LinkedMap;
@@ -7,11 +12,6 @@ import org.apache.commons.collections4.map.ListOrderedMap;
import org.junit.Before;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
public class OrderedMapUnitTest {
private String[] names = {"Emily", "Mathew", "Rose", "John", "Anna"};
@@ -45,11 +45,12 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages:
OrderedMapIterator runnersIterator = this.runnersLinkedMap.mapIterator();
- for (int i = 0; runnersIterator.hasNext(); i++) {
+ int i = 0;
+ while (runnersIterator.hasNext()) {
runnersIterator.next();
-
assertEquals(runnersIterator.getKey(), this.names[i]);
assertEquals(runnersIterator.getValue(), this.ages[i]);
+ i++;
}
}
@@ -59,11 +60,12 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages:
OrderedMapIterator runnersIterator = this.runnersListOrderedMap.mapIterator();
- for (int i = 0; runnersIterator.hasNext(); i++) {
+ int i = 0;
+ while (runnersIterator.hasNext()) {
runnersIterator.next();
-
assertEquals(runnersIterator.getKey(), this.names[i]);
assertEquals(runnersIterator.getValue(), this.ages[i]);
+ i++;
}
}
@@ -73,9 +75,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages
String name = this.runnersLinkedMap.firstKey();
- for (int i = 0; name != null; i++) {
+ int i = 0;
+ while (name != null) {
assertEquals(name, this.names[i]);
name = this.runnersLinkedMap.nextKey(name);
+ i++;
}
}
@@ -85,9 +89,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages
String name = this.runnersListOrderedMap.firstKey();
- for (int i = 0; name != null; i++) {
+ int i = 0;
+ while (name != null) {
assertEquals(name, this.names[i]);
name = this.runnersListOrderedMap.nextKey(name);
+ i++;
}
}
@@ -97,9 +103,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages
String name = this.runnersLinkedMap.lastKey();
- for (int i = RUNNERS_COUNT - 1; name != null; i--) {
+ int i = RUNNERS_COUNT - 1;
+ while (name != null) {
assertEquals(name, this.names[i]);
name = this.runnersLinkedMap.previousKey(name);
+ i--;
}
}
@@ -109,9 +117,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages
String name = this.runnersListOrderedMap.lastKey();
- for (int i = RUNNERS_COUNT - 1; name != null; i--) {
+ int i = RUNNERS_COUNT - 1;
+ while (name != null) {
assertEquals(name, this.names[i]);
name = this.runnersListOrderedMap.previousKey(name);
+ i--;
}
}
diff --git a/libraries/src/test/java/com/baeldung/serenity/spring/AdderClassDirtiesContextIntegrationTest.java b/libraries/src/test/java/com/baeldung/serenity/spring/AdderClassDirtiesContextIntegrationTest.java
index bb25186cee..82dbad0f11 100644
--- a/libraries/src/test/java/com/baeldung/serenity/spring/AdderClassDirtiesContextIntegrationTest.java
+++ b/libraries/src/test/java/com/baeldung/serenity/spring/AdderClassDirtiesContextIntegrationTest.java
@@ -14,23 +14,21 @@ import org.springframework.test.context.ContextConfiguration;
import static com.baeldung.serenity.spring.RandomNumberUtil.randomInt;
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS;
-/**
- * @author aiet
- */
-
@RunWith(Suite.class)
@Suite.SuiteClasses({
- AdderClassDirtiesContextIntegrationTest.DirtiesContextTest.class, AdderClassDirtiesContextIntegrationTest.AnotherDirtiesContextTest.class
- })
+ AdderClassDirtiesContextIntegrationTest.DirtiesContextTest.class, AdderClassDirtiesContextIntegrationTest.AnotherDirtiesContextTest.class
+})
public class AdderClassDirtiesContextIntegrationTest {
@RunWith(SerenityRunner.class)
@ContextConfiguration(classes = AdderService.class)
public static abstract class Base {
- @Steps AdderServiceSteps adderServiceSteps;
+ @Steps
+ AdderServiceSteps adderServiceSteps;
- @ClassRule public static SpringIntegrationClassRule springIntegrationClassRule = new SpringIntegrationClassRule();
+ @ClassRule
+ public static SpringIntegrationClassRule springIntegrationClassRule = new SpringIntegrationClassRule();
void whenAccumulate_thenSummedUp() {
adderServiceSteps.whenAccumulate();
diff --git a/libraries/src/test/java/com/baeldung/serenity/spring/AdderTest.java b/libraries/src/test/java/com/baeldung/serenity/spring/AdderTest.java
index a57b924211..771f389cb1 100644
--- a/libraries/src/test/java/com/baeldung/serenity/spring/AdderTest.java
+++ b/libraries/src/test/java/com/baeldung/serenity/spring/AdderTest.java
@@ -6,13 +6,11 @@ import org.jbehave.core.annotations.BeforeStory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-/**
- * @author aiet
- */
-@ContextConfiguration(classes = { AdderController.class, AdderService.class })
+@ContextConfiguration(classes = {AdderController.class, AdderService.class})
public class AdderTest extends SerenityStory {
- @Autowired private AdderService adderService;
+ @Autowired
+ private AdderService adderService;
@BeforeStory
public void init() {
diff --git a/metrics/src/test/java/com/baeldung/metrics/servo/MetricTypeTest.java b/metrics/src/test/java/com/baeldung/metrics/servo/MetricTypeTest.java
index 9f7b6bb6f3..68ba23244d 100644
--- a/metrics/src/test/java/com/baeldung/metrics/servo/MetricTypeTest.java
+++ b/metrics/src/test/java/com/baeldung/metrics/servo/MetricTypeTest.java
@@ -5,10 +5,10 @@ import com.netflix.servo.stats.StatsConfig;
import org.junit.Ignore;
import org.junit.Test;
-import java.util.HashMap;
import java.util.Map;
import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -123,15 +123,14 @@ public class MetricTypeTest {
.getTotalTime()
.intValue());
- final Map metricMap = new HashMap<>(3);
- timer
+ final Map metricMap = timer
.getMonitors()
.stream()
.filter(monitor -> monitor
.getConfig()
.getTags()
.containsKey("servo.bucket"))
- .forEach(monitor -> metricMap.put(getMonitorTagValue(monitor, "servo.bucket"), (Long) monitor.getValue()));
+ .collect(toMap(monior -> getMonitorTagValue(monior, "servo.bucket"), monitor -> (Long) monitor.getValue()));
assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L)));
}
@@ -177,10 +176,10 @@ public class MetricTypeTest {
.getValue()
.intValue());
- final Map metricMap = new HashMap<>(10);
- timer
+ final Map metricMap = timer
.getMonitors()
- .forEach(monitor -> metricMap.put(getMonitorTagValue(monitor, "statistic"), (Number) monitor.getValue()));
+ .stream()
+ .collect(toMap(monitor -> getMonitorTagValue(monitor, "statistic"), monitor -> (Number) monitor.getValue()));
assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90"));
}