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
13 changed files with 207 additions and 93 deletions
@@ -1,13 +0,0 @@
package com.baeldung.asciidoctor;
import org.junit.Assert;
import org.junit.Test;
public class AsciidoctorDemoTest {
@Test
public void givenString_whenConverting_thenResultingHTMLCode() {
final AsciidoctorDemo asciidoctorDemo = new AsciidoctorDemo();
Assert.assertEquals(asciidoctorDemo.generateHTMLFromString("Hello _Baeldung_!"), "<div class=\"paragraph\">\n<p>Hello <em>Baeldung</em>!</p>\n</div>");
}
}
@@ -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);
}
}
@@ -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<String, Integer> 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<String, Integer> 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--;
}
}
@@ -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();
@@ -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() {