Build optimization (#2253)
This commit is contained in:
parent
e5abeb4fd9
commit
84956990b6
|
@ -3,7 +3,6 @@ package com.baeldung.awaitility;
|
|||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
|
@ -19,14 +19,14 @@ public class BeanGeneratorIntegrationTest {
|
|||
beanGenerator.addProperty("name", String.class);
|
||||
Object myBean = beanGenerator.create();
|
||||
Method setter = myBean
|
||||
.getClass()
|
||||
.getMethod("setName", String.class);
|
||||
.getClass()
|
||||
.getMethod("setName", String.class);
|
||||
setter.invoke(myBean, "some string value set by a cglib");
|
||||
|
||||
//then
|
||||
Method getter = myBean
|
||||
.getClass()
|
||||
.getMethod("getName");
|
||||
.getClass()
|
||||
.getMethod("getName");
|
||||
assertEquals("some string value set by a cglib", getter.invoke(myBean));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.baeldung.cglib.proxy;
|
||||
|
||||
import com.baeldung.cglib.mixin.*;
|
||||
import com.baeldung.cglib.mixin.Class1;
|
||||
import com.baeldung.cglib.mixin.Class2;
|
||||
import com.baeldung.cglib.mixin.Interface1;
|
||||
import com.baeldung.cglib.mixin.Interface2;
|
||||
import com.baeldung.cglib.mixin.MixinInterface;
|
||||
import net.sf.cglib.proxy.Mixin;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -12,8 +16,8 @@ public class MixinUnitTest {
|
|||
public void givenTwoClasses_whenMixedIntoOne_thenMixinShouldHaveMethodsFromBothClasses() throws Exception {
|
||||
//when
|
||||
Mixin mixin = Mixin.create(
|
||||
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
|
||||
new Object[]{new Class1(), new Class2()}
|
||||
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
|
||||
new Object[]{new Class1(), new Class2()}
|
||||
);
|
||||
MixinInterface mixinDelegate = (MixinInterface) mixin;
|
||||
|
||||
|
|
|
@ -2,16 +2,12 @@ package com.baeldung.commons.collections;
|
|||
|
||||
import org.apache.commons.collections4.BidiMap;
|
||||
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
|
||||
import org.apache.commons.collections4.bidimap.DualLinkedHashBidiMap;
|
||||
import org.apache.commons.collections4.bidimap.DualTreeBidiMap;
|
||||
import org.apache.commons.collections4.bidimap.TreeBidiMap;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by smatt on 03/07/2017.
|
||||
*/
|
||||
public class BidiMapUnitTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,14 +3,17 @@ package com.baeldung.commons.collections;
|
|||
|
||||
import com.baeldung.commons.collectionutil.Address;
|
||||
import com.baeldung.commons.collectionutil.Customer;
|
||||
import org.apache.commons.collections4.Closure;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.Predicate;
|
||||
import org.apache.commons.collections4.Transformer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -36,13 +39,13 @@ public class CollectionUtilsGuideTest {
|
|||
|
||||
linkedList1 = new LinkedList<>(list1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenList_whenAddIgnoreNull_thenNoNullAdded() {
|
||||
CollectionUtils.addIgnoreNull(list1, null);
|
||||
assertFalse(list1.contains(null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoSortedLists_whenCollated_thenSorted() {
|
||||
List<Customer> sortedList = CollectionUtils.collate(list1, list2);
|
||||
|
@ -51,7 +54,7 @@ public class CollectionUtilsGuideTest {
|
|||
assertTrue(sortedList.get(0).getName().equals("Bob"));
|
||||
assertTrue(sortedList.get(2).getName().equals("Daniel"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomers_whenTransformed_thenListOfAddress() {
|
||||
Collection<Address> addressCol = CollectionUtils.collect(list1, new Transformer<Customer, Address>() {
|
||||
|
@ -59,61 +62,61 @@ public class CollectionUtilsGuideTest {
|
|||
return new Address(customer.getLocality(), customer.getCity(), customer.getZip());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
List<Address> addressList = new ArrayList<>(addressCol);
|
||||
assertTrue(addressList.size() == 3);
|
||||
assertTrue(addressList.get(0).getLocality().equals("locality1"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenCustomerList_whenFiltered_thenCorrectSize() {
|
||||
|
||||
boolean isModified = CollectionUtils.filter(linkedList1, new Predicate<Customer>() {
|
||||
public boolean evaluate(Customer customer) {
|
||||
return Arrays.asList("Daniel","Kyle").contains(customer.getName());
|
||||
return Arrays.asList("Daniel", "Kyle").contains(customer.getName());
|
||||
}
|
||||
});
|
||||
|
||||
//filterInverse does the opposite. It removes the element from the list if the Predicate returns true
|
||||
//select and selectRejected work the same way except that they do not remove elements from the given collection and return a new collection
|
||||
|
||||
|
||||
assertTrue(isModified && linkedList1.size() == 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenNonEmptyList_whenCheckedIsNotEmpty_thenTrue() {
|
||||
List<Customer> emptyList = new ArrayList<>();
|
||||
List<Customer> nullList = null;
|
||||
|
||||
|
||||
//Very handy at times where we want to check if a collection is not null and not empty too.
|
||||
//isNotEmpty does the opposite. Handy because using ! operator on isEmpty makes it missable while reading
|
||||
assertTrue(CollectionUtils.isNotEmpty(list1));
|
||||
assertTrue(CollectionUtils.isEmpty(nullList));
|
||||
assertTrue(CollectionUtils.isEmpty(emptyList));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenCustomerListAndASubcollection_whenChecked_thenTrue() {
|
||||
assertTrue(CollectionUtils.isSubCollection(list3, list1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenIntersected_thenCheckSize() {
|
||||
Collection<Customer> intersection = CollectionUtils.intersection(list1, list3);
|
||||
assertTrue(intersection.size() == 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenSubtracted_thenCheckElementNotPresentInA() {
|
||||
Collection<Customer> result = CollectionUtils.subtract(list1, list3);
|
||||
assertFalse(result.contains(customer1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUnioned_thenCheckElementPresentInResult() {
|
||||
Collection<Customer> union = CollectionUtils.union(list1, list2);
|
||||
assertTrue(union.contains(customer1));
|
||||
assertTrue(union.contains(customer4));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -16,33 +16,35 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.hamcrest.collection.IsMapContaining.hasEntry;
|
||||
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
|
||||
import static org.hamcrest.collection.IsMapWithSize.anEmptyMap;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MapUtilsTest {
|
||||
|
||||
private String[][] color2DArray = new String[][] {
|
||||
{"RED", "#FF0000"},
|
||||
{"GREEN", "#00FF00"},
|
||||
{"BLUE", "#0000FF"}
|
||||
private String[][] color2DArray = new String[][]{
|
||||
{"RED", "#FF0000"},
|
||||
{"GREEN", "#00FF00"},
|
||||
{"BLUE", "#0000FF"}
|
||||
};
|
||||
private String[] color1DArray = new String[] {
|
||||
"RED", "#FF0000",
|
||||
"GREEN", "#00FF00",
|
||||
"BLUE", "#0000FF"
|
||||
private String[] color1DArray = new String[]{
|
||||
"RED", "#FF0000",
|
||||
"GREEN", "#00FF00",
|
||||
"BLUE", "#0000FF"
|
||||
};
|
||||
private Map<String, String> colorMap;
|
||||
|
||||
|
||||
@Before
|
||||
public void createMap() {
|
||||
this.colorMap = MapUtils.putAll(new HashMap<String, String>(), this.color2DArray);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenCreateMapFrom2DArray_theMapIsCreated() {
|
||||
this.colorMap = MapUtils.putAll(new HashMap<String, String>(), this.color2DArray);
|
||||
|
||||
assertThat(this.colorMap, is(aMapWithSize(this.color2DArray.length)));
|
||||
|
||||
|
||||
assertThat(this.colorMap, hasEntry("RED", "#FF0000"));
|
||||
assertThat(this.colorMap, hasEntry("GREEN", "#00FF00"));
|
||||
assertThat(this.colorMap, hasEntry("BLUE", "#0000FF"));
|
||||
|
@ -51,26 +53,26 @@ public class MapUtilsTest {
|
|||
@Test
|
||||
public void whenCreateMapFrom1DArray_theMapIsCreated() {
|
||||
this.colorMap = MapUtils.putAll(new HashMap<String, String>(), this.color1DArray);
|
||||
|
||||
|
||||
assertThat(this.colorMap, is(aMapWithSize(this.color1DArray.length / 2)));
|
||||
|
||||
assertThat(this.colorMap, hasEntry("RED", "#FF0000"));
|
||||
assertThat(this.colorMap, hasEntry("GREEN", "#00FF00"));
|
||||
assertThat(this.colorMap, hasEntry("BLUE", "#0000FF"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenVerbosePrintMap_thenMustPrintFormattedMap() {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream outPrint = new PrintStream(out);
|
||||
|
||||
|
||||
outPrint.println("Optional Label = ");
|
||||
outPrint.println("{");
|
||||
outPrint.println(" RED = #FF0000");
|
||||
outPrint.println(" BLUE = #0000FF");
|
||||
outPrint.println(" GREEN = #00FF00");
|
||||
outPrint.println("}");
|
||||
|
||||
|
||||
out.reset();
|
||||
|
||||
MapUtils.verbosePrint(outPrint, "Optional Label", this.colorMap);
|
||||
|
@ -80,15 +82,15 @@ public class MapUtilsTest {
|
|||
public void whenGetKeyNotPresent_thenMustReturnDefaultValue() {
|
||||
String defaultColorStr = "COLOR_NOT_FOUND";
|
||||
String color = MapUtils.getString(this.colorMap, "BLACK", defaultColorStr);
|
||||
|
||||
|
||||
assertEquals(color, defaultColorStr);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenGetOnNullMap_thenMustReturnDefaultValue() {
|
||||
String defaultColorStr = "COLOR_NOT_FOUND";
|
||||
String color = MapUtils.getString(null, "RED", defaultColorStr);
|
||||
|
||||
|
||||
assertEquals(color, defaultColorStr);
|
||||
}
|
||||
|
||||
|
@ -96,49 +98,49 @@ public class MapUtilsTest {
|
|||
public void whenInvertMap_thenMustReturnInvertedMap() {
|
||||
Map<String, String> invColorMap = MapUtils.invertMap(this.colorMap);
|
||||
assertEquals(this.colorMap.size(), invColorMap.size());
|
||||
|
||||
MapIterator<String, String> itColorMap
|
||||
|
||||
MapIterator<String, String> itColorMap
|
||||
= MapUtils.iterableMap(this.colorMap).mapIterator();
|
||||
|
||||
|
||||
while (itColorMap.hasNext()) {
|
||||
String colorMapKey = itColorMap.next();
|
||||
String colorMapValue = itColorMap.getValue();
|
||||
|
||||
String invColorMapValue = MapUtils.getString(invColorMap, colorMapValue);
|
||||
|
||||
|
||||
assertTrue(invColorMapValue.equals(colorMapKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCreateFixedSizedMapAndAdd_thenMustThrowException() {
|
||||
Map<String, String> rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll(
|
||||
new HashMap<String, String>(),
|
||||
this.color1DArray));
|
||||
|
||||
new HashMap<String, String>(),
|
||||
this.color1DArray));
|
||||
|
||||
rgbMap.put("ORANGE", "#FFA500");
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddDuplicateToUniqueValuesPredicateMap_thenMustThrowException() {
|
||||
Map<String, String> uniqValuesMap
|
||||
Map<String, String> uniqValuesMap
|
||||
= MapUtils.predicatedMap(this.colorMap, null, PredicateUtils.uniquePredicate());
|
||||
|
||||
|
||||
uniqValuesMap.put("NEW_RED", "#FF0000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateLazyMap_theMapIsCreated() {
|
||||
Map<Integer, String> intStrMap = MapUtils.lazyMap(
|
||||
new HashMap<Integer, String>(),
|
||||
TransformerUtils.stringValueTransformer());
|
||||
|
||||
new HashMap<Integer, String>(),
|
||||
TransformerUtils.stringValueTransformer());
|
||||
|
||||
assertThat(intStrMap, is(anEmptyMap()));
|
||||
|
||||
|
||||
intStrMap.get(1);
|
||||
intStrMap.get(2);
|
||||
intStrMap.get(3);
|
||||
|
||||
|
||||
assertThat(intStrMap, is(aMapWithSize(3)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ 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)
|
||||
|
@ -27,33 +24,33 @@ public class SetUtilsUnitTest {
|
|||
|
||||
@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));
|
||||
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));
|
||||
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));
|
||||
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 );
|
||||
Set<Integer> a = SetUtils.transformedSet(new HashSet<>(), (e) -> e * 2);
|
||||
a.add(2);
|
||||
assertEquals(a.toArray()[0], 4);
|
||||
|
||||
|
@ -65,19 +62,19 @@ public class SetUtilsUnitTest {
|
|||
|
||||
@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));
|
||||
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));
|
||||
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));
|
||||
orderedSet.addAll(Arrays.asList(10, 1, 5));
|
||||
System.out.println("ordered set = " + orderedSet);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
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;
|
||||
|
@ -12,6 +7,11 @@ 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"};
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package com.baeldung.commons.dbutils;
|
||||
|
||||
import org.apache.commons.dbutils.AsyncQueryRunner;
|
||||
import org.apache.commons.dbutils.DbUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
import org.apache.commons.dbutils.handlers.MapListHandler;
|
||||
import org.apache.commons.dbutils.handlers.ScalarHandler;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
@ -9,16 +19,9 @@ import java.util.Map;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.dbutils.AsyncQueryRunner;
|
||||
import org.apache.commons.dbutils.DbUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
import org.apache.commons.dbutils.handlers.MapListHandler;
|
||||
import org.apache.commons.dbutils.handlers.ScalarHandler;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class DbUtilsUnitTest {
|
||||
|
||||
|
@ -45,9 +48,9 @@ public class DbUtilsUnitTest {
|
|||
|
||||
assertEquals(list.size(), 5);
|
||||
assertEquals(list.get(0)
|
||||
.get("firstname"), "John");
|
||||
.get("firstname"), "John");
|
||||
assertEquals(list.get(4)
|
||||
.get("firstname"), "Christian");
|
||||
.get("firstname"), "Christian");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,9 +62,9 @@ public class DbUtilsUnitTest {
|
|||
|
||||
assertEquals(employeeList.size(), 5);
|
||||
assertEquals(employeeList.get(0)
|
||||
.getFirstName(), "John");
|
||||
.getFirstName(), "John");
|
||||
assertEquals(employeeList.get(4)
|
||||
.getFirstName(), "Christian");
|
||||
.getFirstName(), "Christian");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,11 +86,11 @@ public class DbUtilsUnitTest {
|
|||
List<Employee> employees = runner.query(connection, "SELECT * FROM employee", employeeHandler);
|
||||
|
||||
assertEquals(employees.get(0)
|
||||
.getEmails()
|
||||
.size(), 2);
|
||||
.getEmails()
|
||||
.size(), 2);
|
||||
assertEquals(employees.get(2)
|
||||
.getEmails()
|
||||
.size(), 3);
|
||||
.getEmails()
|
||||
.size(), 3);
|
||||
assertNotNull(employees.get(0).getEmails().get(0).getEmployeeId());
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ package com.baeldung.commons.lang3;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StringUtilsUnitTest {
|
||||
@Test
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class HikariCPUnitTest {
|
||||
public class HikariCPIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenConnection_thenFetchDbData() {
|
|
@ -22,9 +22,9 @@ public class HLLUnitTest {
|
|||
|
||||
//when
|
||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
hll.addRaw(hashedValue);
|
||||
}
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
hll.addRaw(hashedValue);
|
||||
}
|
||||
);
|
||||
|
||||
//then
|
||||
|
@ -43,15 +43,15 @@ public class HLLUnitTest {
|
|||
|
||||
//when
|
||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
firstHll.addRaw(hashedValue);
|
||||
}
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
firstHll.addRaw(hashedValue);
|
||||
}
|
||||
);
|
||||
|
||||
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
secondHLL.addRaw(hashedValue);
|
||||
}
|
||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||
secondHLL.addRaw(hashedValue);
|
||||
}
|
||||
);
|
||||
|
||||
//then
|
||||
|
|
|
@ -8,7 +8,9 @@ import org.jasypt.util.text.BasicTextEncryptor;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotSame;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class JasyptUnitTest {
|
||||
|
@ -30,7 +32,7 @@ public class JasyptUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldBeSame(){
|
||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldBeSame() {
|
||||
String password = "secret-pass";
|
||||
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
||||
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
||||
|
@ -43,7 +45,7 @@ public class JasyptUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldNotBeSame(){
|
||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldNotBeSame() {
|
||||
String password = "secret-pass";
|
||||
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
||||
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
||||
|
@ -56,7 +58,6 @@ public class JasyptUnitTest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore("should have installed local_policy.jar")
|
||||
public void givenTextPrivateData_whenDecrypt_thenCompareToEncryptedWithCustomAlgorithm() {
|
||||
|
@ -77,7 +78,7 @@ public class JasyptUnitTest {
|
|||
|
||||
@Test
|
||||
@Ignore("should have installed local_policy.jar")
|
||||
public void givenTextPrivateData_whenDecryptOnHighPerformance_thenDecrypt(){
|
||||
public void givenTextPrivateData_whenDecryptOnHighPerformance_thenDecrypt() {
|
||||
//given
|
||||
String privateData = "secret-data";
|
||||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||
|
|
|
@ -8,7 +8,6 @@ import javax.jdo.PersistenceManager;
|
|||
import javax.jdo.PersistenceManagerFactory;
|
||||
import javax.jdo.Query;
|
||||
import javax.jdo.Transaction;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -8,7 +8,11 @@ import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
|
|||
import au.com.dius.pact.model.RequestResponsePact;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -20,7 +24,7 @@ public class PactConsumerDrivenContractUnitTest {
|
|||
|
||||
@Rule
|
||||
public PactProviderRuleMk2 mockProvider
|
||||
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
|
||||
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
|
||||
|
||||
@Pact(consumer = "test_consumer")
|
||||
public RequestResponsePact createPact(PactDslWithProvider builder) {
|
||||
|
@ -28,25 +32,25 @@ public class PactConsumerDrivenContractUnitTest {
|
|||
headers.put("Content-Type", "application/json");
|
||||
|
||||
return builder
|
||||
.given("test GET ")
|
||||
.uponReceiving("GET REQUEST")
|
||||
.path("/")
|
||||
.method("GET")
|
||||
.willRespondWith()
|
||||
.status(200)
|
||||
.headers(headers)
|
||||
.body("{\"condition\": true, \"name\": \"tom\"}")
|
||||
.given("test POST")
|
||||
.uponReceiving("POST REQUEST")
|
||||
.method("POST")
|
||||
.headers(headers)
|
||||
.body("{\"name\": \"Michael\"}")
|
||||
.path("/create")
|
||||
.willRespondWith()
|
||||
.status(201)
|
||||
.headers(headers)
|
||||
.body("")
|
||||
.toPact();
|
||||
.given("test GET ")
|
||||
.uponReceiving("GET REQUEST")
|
||||
.path("/")
|
||||
.method("GET")
|
||||
.willRespondWith()
|
||||
.status(200)
|
||||
.headers(headers)
|
||||
.body("{\"condition\": true, \"name\": \"tom\"}")
|
||||
.given("test POST")
|
||||
.uponReceiving("POST REQUEST")
|
||||
.method("POST")
|
||||
.headers(headers)
|
||||
.body("{\"name\": \"Michael\"}")
|
||||
.path("/create")
|
||||
.willRespondWith()
|
||||
.status(201)
|
||||
.headers(headers)
|
||||
.body("")
|
||||
.toPact();
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +59,7 @@ public class PactConsumerDrivenContractUnitTest {
|
|||
public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
|
||||
//when
|
||||
ResponseEntity<String> response
|
||||
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
|
||||
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
|
||||
|
||||
//then
|
||||
assertThat(response.getStatusCode().value()).isEqualTo(200);
|
||||
|
@ -69,10 +73,10 @@ public class PactConsumerDrivenContractUnitTest {
|
|||
|
||||
//when
|
||||
ResponseEntity<String> postResponse = new RestTemplate().exchange(
|
||||
mockProvider.getUrl() + "/create",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(jsonBody, httpHeaders),
|
||||
String.class
|
||||
mockProvider.getUrl() + "/create",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(jsonBody, httpHeaders),
|
||||
String.class
|
||||
);
|
||||
|
||||
//then
|
||||
|
|
|
@ -13,11 +13,11 @@ public class WordUtilsTest {
|
|||
|
||||
Assert.assertEquals("To Be Capitalized!", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenContainsWords_thenCorrect() {
|
||||
boolean containsWords = WordUtils.containsAllWords("String to search", "to", "search");
|
||||
|
||||
|
||||
Assert.assertTrue(containsWords);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.baeldung.vaadin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||
import com.vaadin.server.DefaultUIProvider;
|
||||
import com.vaadin.server.VaadinServlet;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
|
@ -15,9 +17,7 @@ import org.openqa.selenium.WebDriver;
|
|||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||
import com.vaadin.server.DefaultUIProvider;
|
||||
import com.vaadin.server.VaadinServlet;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class VaadinUITests {
|
||||
|
@ -26,56 +26,56 @@ public class VaadinUITests {
|
|||
private Server server;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception{
|
||||
public void setUp() throws Exception {
|
||||
startJettyServer();
|
||||
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45,true);
|
||||
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45, true);
|
||||
driver.get("http://localhost:8080");
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageLoadedThenShouldSeeURL(){
|
||||
|
||||
@Test
|
||||
public void whenPageLoadedThenShouldSeeURL() {
|
||||
String url = driver.getCurrentUrl();
|
||||
assertEquals("http://localhost:8080/", url);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenLabel_WhenGetValue_ThenValueMatch() {
|
||||
WebElement label = driver.findElement(By.id("Label"));
|
||||
assertEquals("Label Value", label.getText());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTextField_WhenGetValue_ThenValueMatch() {
|
||||
WebElement textField = driver.findElement(By.id("TextField"));
|
||||
assertEquals("TextField Value", textField.getAttribute("Value"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTextArea_WhenGetValue_ThenValueMatch() {
|
||||
WebElement textArea = driver.findElement(By.id("TextArea"));
|
||||
assertEquals("TextArea Value", textArea.getAttribute("Value"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenDateField_WhenGetValue_ThenValueMatch() {
|
||||
WebElement dateField = driver.findElement(By.id("DateField"));
|
||||
assertEquals("12/31/69", dateField.getText());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenPasswordField_WhenGetValue_ThenValueMatch() {
|
||||
WebElement passwordField = driver.findElement(By.id("PasswordField"));
|
||||
assertEquals("password", passwordField.getAttribute("Value"));
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void cleanUp() throws Exception{
|
||||
public void cleanUp() throws Exception {
|
||||
driver.close();
|
||||
server.stop();
|
||||
}
|
||||
|
||||
public void startJettyServer() throws Exception{
|
||||
public void startJettyServer() throws Exception {
|
||||
|
||||
int maxThreads = 100;
|
||||
int minThreads = 10;
|
||||
|
|
|
@ -5,8 +5,8 @@ import java.io.IOException;
|
|||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonUtil {
|
||||
public static byte[] toJson(Object object) throws IOException {
|
||||
class JsonUtil {
|
||||
static byte[] toJson(Object object) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
return mapper.writeValueAsBytes(object);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
<artifactId>spring-mvc-java</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>spring-mvc-java</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
|
Loading…
Reference in New Issue