Merge branch 'master' into BAEL-981_pact

This commit is contained in:
Carsten Gräf 2017-06-28 07:18:26 +02:00 committed by GitHub
commit cc554188d8
13 changed files with 207 additions and 93 deletions

3
asciidoctor/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant articles
- [Introduction to Asciidoctor](http://www.baeldung.com/introduction-to-asciidoctor)

View File

56
asciidoctor/pom.xml Normal file
View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>asciidoctor</artifactId>
<name>asciidoctor</name>
<build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.5</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.15</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>output-pdf</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<outputDirectory>target/docs/asciidoc</outputDirectory>
<backend>pdf</backend>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.11</version>
</dependency>
</dependencies>
</project>

View File

@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class StringToCharStreamUnitTest { public class StringToCharStreamUnitTest {
@ -44,7 +43,6 @@ public class StringToCharStreamUnitTest {
.mapToObj(c -> (char) c); .mapToObj(c -> (char) c);
Stream<Character> characterStream1 = testString.codePoints() Stream<Character> characterStream1 = testString.codePoints()
.mapToObj(c -> (char) c); .mapToObj(c -> (char) c);
assertNotNull("IntStream returned by chars() did not map to Stream<Character>", characterStream); assertNotNull("IntStream returned by chars() did not map to Stream<Character>", characterStream);
assertNotNull("IntStream returned by codePoints() did not map to Stream<Character>", characterStream1); assertNotNull("IntStream returned by codePoints() did not map to Stream<Character>", characterStream1);
} }

View File

@ -70,32 +70,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.5</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.15</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>output-pdf</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<outputDirectory>target/docs/asciidoc</outputDirectory>
<backend>pdf</backend>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -116,6 +90,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version> <version>${commons-lang.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons.collections.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jasypt</groupId> <groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId> <artifactId>jasypt</artifactId>
@ -211,12 +190,6 @@
<artifactId>serenity-core</artifactId> <artifactId>serenity-core</artifactId>
<version>${serenity.version}</version> <version>${serenity.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-java-integration</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.serenity-bdd</groupId> <groupId>net.serenity-bdd</groupId>
@ -360,22 +333,18 @@
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>
<version>${netty.version}</version> <version>${netty.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.11</version>
</dependency>
<!-- OpenNLP --> <!-- OpenNLP -->
<dependency> <dependency>
<groupId>org.apache.opennlp</groupId> <groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId> <artifactId>opennlp-tools</artifactId>
<version>1.8.0</version> <version>1.8.0</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>info.debatty</groupId> <groupId>info.debatty</groupId>
<artifactId>java-lsh</artifactId> <artifactId>java-lsh</artifactId>
@ -392,8 +361,6 @@
<artifactId>groovy-all</artifactId> <artifactId>groovy-all</artifactId>
<version>2.4.10</version> <version>2.4.10</version>
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<multiverse.version>0.7.0</multiverse.version> <multiverse.version>0.7.0</multiverse.version>
@ -420,6 +387,8 @@
<serenity.plugin.version>1.4.0</serenity.plugin.version> <serenity.plugin.version>1.4.0</serenity.plugin.version>
<jUnitParams.version>1.1.0</jUnitParams.version> <jUnitParams.version>1.1.0</jUnitParams.version>
<netty.version>4.1.10.Final</netty.version> <netty.version>4.1.10.Final</netty.version>
<commons.collections.version>4.1</commons.collections.version>
<junit.version>4.12</junit.version>
<java-lsh.version>0.10</java-lsh.version> <java-lsh.version>0.10</java-lsh.version>
<pact.version>3.5.0</pact.version> <pact.version>3.5.0</pact.version>
</properties> </properties>

View File

@ -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<String> sourceSet = new HashSet<>();
sourceSet.addAll(Arrays.asList("London", "Lagos", "Err Source1"));
Set<String> validatingSet
= SetUtils.predicatedSet(sourceSet, (s) -> s.startsWith("L"));
validatingSet.add("Err Source2");
}
@Test
public void givenTwoSets_whenDifference_thenSetView() {
Set<Integer> a = new HashSet<>(Arrays.asList(1,2,5));
Set<Integer> b = new HashSet<>(Arrays.asList(1,2));
SetUtils.SetView<Integer> result = SetUtils.difference(a, b);
assertTrue(result.size() == 1 && result.contains(5));
}
@Test
public void givenTwoSets_whenUnion_thenUnionResult() {
Set<Integer> a = new HashSet<>(Arrays.asList(1,2,5));
Set<Integer> b = new HashSet<>(Arrays.asList(1,2));
Set<Integer> expected = new HashSet<>(Arrays.asList(1,2,5));
SetUtils.SetView<Integer> union = SetUtils.union(a, b);
assertTrue(SetUtils.isEqualSet(expected, union));
}
@Test
public void givenTwoSets_whenIntersection_thenIntersectionResult() {
Set<Integer> a = new HashSet<>(Arrays.asList(1,2,5));
Set<Integer> b = new HashSet<>(Arrays.asList(1,2));
Set<Integer> expected = new HashSet<>(Arrays.asList(1,2));
SetUtils.SetView<Integer> intersect = SetUtils.intersection(a, b);
assertTrue(SetUtils.isEqualSet(expected, intersect));
}
@Test
public void givenSet_whenTransformedSet_thenTransformedResult() {
Set<Integer> a = SetUtils.transformedSet(new HashSet<>(), (e) -> e * 2 );
a.add(2);
assertEquals(a.toArray()[0], 4);
Set<Integer> source = new HashSet<>(Arrays.asList(1));
Set<Integer> newSet = TransformedSet.transformedSet(source, (e) -> e * 2);
assertEquals(newSet.toArray()[0], 2);
assertEquals(source.toArray()[0], 2);
}
@Test
public void givenTwoSet_whenDisjunction_thenDisjunctionSet() {
Set<Integer> a = new HashSet<>(Arrays.asList(1,2,5));
Set<Integer> b = new HashSet<>(Arrays.asList(1,2,3));
SetUtils.SetView<Integer> result = SetUtils.disjunction(a, b);
assertTrue(result.toSet().contains(5) && result.toSet().contains(3));
}
@Test
public void givenSet_when_OrderedSet_thenMaintainElementOrder() {
Set<Integer> set = new HashSet<>(Arrays.asList(10,1,5));
System.out.println("unordered set: " + set);
Set<Integer> orderedSet = SetUtils.orderedSet(new HashSet<>());
orderedSet.addAll(Arrays.asList(10,1,5));
System.out.println("ordered set = " + orderedSet);
}
}

View File

@ -1,5 +1,10 @@
package com.baeldung.commons.collections.orderedmap; 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.OrderedMap;
import org.apache.commons.collections4.OrderedMapIterator; import org.apache.commons.collections4.OrderedMapIterator;
import org.apache.commons.collections4.map.LinkedMap; 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.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class OrderedMapUnitTest { public class OrderedMapUnitTest {
private String[] names = {"Emily", "Mathew", "Rose", "John", "Anna"}; 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: // as defined in the constant arrays of names and ages:
OrderedMapIterator<String, Integer> runnersIterator = this.runnersLinkedMap.mapIterator(); OrderedMapIterator<String, Integer> runnersIterator = this.runnersLinkedMap.mapIterator();
for (int i = 0; runnersIterator.hasNext(); i++) { int i = 0;
while (runnersIterator.hasNext()) {
runnersIterator.next(); runnersIterator.next();
assertEquals(runnersIterator.getKey(), this.names[i]); assertEquals(runnersIterator.getKey(), this.names[i]);
assertEquals(runnersIterator.getValue(), this.ages[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: // as defined in the constant arrays of names and ages:
OrderedMapIterator<String, Integer> runnersIterator = this.runnersListOrderedMap.mapIterator(); OrderedMapIterator<String, Integer> runnersIterator = this.runnersListOrderedMap.mapIterator();
for (int i = 0; runnersIterator.hasNext(); i++) { int i = 0;
while (runnersIterator.hasNext()) {
runnersIterator.next(); runnersIterator.next();
assertEquals(runnersIterator.getKey(), this.names[i]); assertEquals(runnersIterator.getKey(), this.names[i]);
assertEquals(runnersIterator.getValue(), this.ages[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 // as defined in the constant arrays of names and ages
String name = this.runnersLinkedMap.firstKey(); String name = this.runnersLinkedMap.firstKey();
for (int i = 0; name != null; i++) { int i = 0;
while (name != null) {
assertEquals(name, this.names[i]); assertEquals(name, this.names[i]);
name = this.runnersLinkedMap.nextKey(name); name = this.runnersLinkedMap.nextKey(name);
i++;
} }
} }
@ -85,9 +89,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages // as defined in the constant arrays of names and ages
String name = this.runnersListOrderedMap.firstKey(); String name = this.runnersListOrderedMap.firstKey();
for (int i = 0; name != null; i++) { int i = 0;
while (name != null) {
assertEquals(name, this.names[i]); assertEquals(name, this.names[i]);
name = this.runnersListOrderedMap.nextKey(name); name = this.runnersListOrderedMap.nextKey(name);
i++;
} }
} }
@ -97,9 +103,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages // as defined in the constant arrays of names and ages
String name = this.runnersLinkedMap.lastKey(); 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]); assertEquals(name, this.names[i]);
name = this.runnersLinkedMap.previousKey(name); name = this.runnersLinkedMap.previousKey(name);
i--;
} }
} }
@ -109,9 +117,11 @@ public class OrderedMapUnitTest {
// as defined in the constant arrays of names and ages // as defined in the constant arrays of names and ages
String name = this.runnersListOrderedMap.lastKey(); 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]); assertEquals(name, this.names[i]);
name = this.runnersListOrderedMap.previousKey(name); name = this.runnersListOrderedMap.previousKey(name);
i--;
} }
} }

View File

@ -14,10 +14,6 @@ import org.springframework.test.context.ContextConfiguration;
import static com.baeldung.serenity.spring.RandomNumberUtil.randomInt; import static com.baeldung.serenity.spring.RandomNumberUtil.randomInt;
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS;
/**
* @author aiet
*/
@RunWith(Suite.class) @RunWith(Suite.class)
@Suite.SuiteClasses({ @Suite.SuiteClasses({
AdderClassDirtiesContextIntegrationTest.DirtiesContextTest.class, AdderClassDirtiesContextIntegrationTest.AnotherDirtiesContextTest.class AdderClassDirtiesContextIntegrationTest.DirtiesContextTest.class, AdderClassDirtiesContextIntegrationTest.AnotherDirtiesContextTest.class
@ -28,9 +24,11 @@ public class AdderClassDirtiesContextIntegrationTest {
@ContextConfiguration(classes = AdderService.class) @ContextConfiguration(classes = AdderService.class)
public static abstract class Base { 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() { void whenAccumulate_thenSummedUp() {
adderServiceSteps.whenAccumulate(); adderServiceSteps.whenAccumulate();

View File

@ -6,13 +6,11 @@ import org.jbehave.core.annotations.BeforeStory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; 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 { public class AdderTest extends SerenityStory {
@Autowired private AdderService adderService; @Autowired
private AdderService adderService;
@BeforeStory @BeforeStory
public void init() { public void init() {

View File

@ -5,10 +5,10 @@ import com.netflix.servo.stats.StatsConfig;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@ -123,15 +123,14 @@ public class MetricTypeTest {
.getTotalTime() .getTotalTime()
.intValue()); .intValue());
final Map<String, Long> metricMap = new HashMap<>(3); final Map<String, Long> metricMap = timer
timer
.getMonitors() .getMonitors()
.stream() .stream()
.filter(monitor -> monitor .filter(monitor -> monitor
.getConfig() .getConfig()
.getTags() .getTags()
.containsKey("servo.bucket")) .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))); assertThat(metricMap, allOf(hasEntry("bucket=2s", 0L), hasEntry("bucket=5s", 1L), hasEntry("bucket=overflow", 1L)));
} }
@ -177,10 +176,10 @@ public class MetricTypeTest {
.getValue() .getValue()
.intValue()); .intValue());
final Map<String, Number> metricMap = new HashMap<>(10); final Map<String, Number> metricMap = timer
timer
.getMonitors() .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")); assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90"));
} }