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.Awaitility;
|
||||||
import org.awaitility.Duration;
|
import org.awaitility.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
|
@ -19,14 +19,14 @@ public class BeanGeneratorIntegrationTest {
|
||||||
beanGenerator.addProperty("name", String.class);
|
beanGenerator.addProperty("name", String.class);
|
||||||
Object myBean = beanGenerator.create();
|
Object myBean = beanGenerator.create();
|
||||||
Method setter = myBean
|
Method setter = myBean
|
||||||
.getClass()
|
.getClass()
|
||||||
.getMethod("setName", String.class);
|
.getMethod("setName", String.class);
|
||||||
setter.invoke(myBean, "some string value set by a cglib");
|
setter.invoke(myBean, "some string value set by a cglib");
|
||||||
|
|
||||||
//then
|
//then
|
||||||
Method getter = myBean
|
Method getter = myBean
|
||||||
.getClass()
|
.getClass()
|
||||||
.getMethod("getName");
|
.getMethod("getName");
|
||||||
assertEquals("some string value set by a cglib", getter.invoke(myBean));
|
assertEquals("some string value set by a cglib", getter.invoke(myBean));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package com.baeldung.cglib.proxy;
|
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 net.sf.cglib.proxy.Mixin;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -12,8 +16,8 @@ public class MixinUnitTest {
|
||||||
public void givenTwoClasses_whenMixedIntoOne_thenMixinShouldHaveMethodsFromBothClasses() throws Exception {
|
public void givenTwoClasses_whenMixedIntoOne_thenMixinShouldHaveMethodsFromBothClasses() throws Exception {
|
||||||
//when
|
//when
|
||||||
Mixin mixin = Mixin.create(
|
Mixin mixin = Mixin.create(
|
||||||
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
|
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
|
||||||
new Object[]{new Class1(), new Class2()}
|
new Object[]{new Class1(), new Class2()}
|
||||||
);
|
);
|
||||||
MixinInterface mixinDelegate = (MixinInterface) mixin;
|
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;
|
||||||
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
|
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 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 {
|
public class BidiMapUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -3,14 +3,17 @@ package com.baeldung.commons.collections;
|
||||||
|
|
||||||
import com.baeldung.commons.collectionutil.Address;
|
import com.baeldung.commons.collectionutil.Address;
|
||||||
import com.baeldung.commons.collectionutil.Customer;
|
import com.baeldung.commons.collectionutil.Customer;
|
||||||
import org.apache.commons.collections4.Closure;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.Predicate;
|
import org.apache.commons.collections4.Predicate;
|
||||||
import org.apache.commons.collections4.Transformer;
|
import org.apache.commons.collections4.Transformer;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -70,7 +73,7 @@ public class CollectionUtilsGuideTest {
|
||||||
|
|
||||||
boolean isModified = CollectionUtils.filter(linkedList1, new Predicate<Customer>() {
|
boolean isModified = CollectionUtils.filter(linkedList1, new Predicate<Customer>() {
|
||||||
public boolean evaluate(Customer customer) {
|
public boolean evaluate(Customer customer) {
|
||||||
return Arrays.asList("Daniel","Kyle").contains(customer.getName());
|
return Arrays.asList("Daniel", "Kyle").contains(customer.getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,21 @@ import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.collection.IsMapContaining.hasEntry;
|
import static org.hamcrest.collection.IsMapContaining.hasEntry;
|
||||||
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
|
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
|
||||||
import static org.hamcrest.collection.IsMapWithSize.anEmptyMap;
|
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 {
|
public class MapUtilsTest {
|
||||||
|
|
||||||
private String[][] color2DArray = new String[][] {
|
private String[][] color2DArray = new String[][]{
|
||||||
{"RED", "#FF0000"},
|
{"RED", "#FF0000"},
|
||||||
{"GREEN", "#00FF00"},
|
{"GREEN", "#00FF00"},
|
||||||
{"BLUE", "#0000FF"}
|
{"BLUE", "#0000FF"}
|
||||||
};
|
};
|
||||||
private String[] color1DArray = new String[] {
|
private String[] color1DArray = new String[]{
|
||||||
"RED", "#FF0000",
|
"RED", "#FF0000",
|
||||||
"GREEN", "#00FF00",
|
"GREEN", "#00FF00",
|
||||||
"BLUE", "#0000FF"
|
"BLUE", "#0000FF"
|
||||||
};
|
};
|
||||||
private Map<String, String> colorMap;
|
private Map<String, String> colorMap;
|
||||||
|
|
||||||
|
@ -113,8 +115,8 @@ public class MapUtilsTest {
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void whenCreateFixedSizedMapAndAdd_thenMustThrowException() {
|
public void whenCreateFixedSizedMapAndAdd_thenMustThrowException() {
|
||||||
Map<String, String> rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll(
|
Map<String, String> rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll(
|
||||||
new HashMap<String, String>(),
|
new HashMap<String, String>(),
|
||||||
this.color1DArray));
|
this.color1DArray));
|
||||||
|
|
||||||
rgbMap.put("ORANGE", "#FFA500");
|
rgbMap.put("ORANGE", "#FFA500");
|
||||||
}
|
}
|
||||||
|
@ -130,8 +132,8 @@ public class MapUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenCreateLazyMap_theMapIsCreated() {
|
public void whenCreateLazyMap_theMapIsCreated() {
|
||||||
Map<Integer, String> intStrMap = MapUtils.lazyMap(
|
Map<Integer, String> intStrMap = MapUtils.lazyMap(
|
||||||
new HashMap<Integer, String>(),
|
new HashMap<Integer, String>(),
|
||||||
TransformerUtils.stringValueTransformer());
|
TransformerUtils.stringValueTransformer());
|
||||||
|
|
||||||
assertThat(intStrMap, is(anEmptyMap()));
|
assertThat(intStrMap, is(anEmptyMap()));
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,6 @@ import java.util.Set;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by smatt on 21/06/2017.
|
|
||||||
*/
|
|
||||||
public class SetUtilsUnitTest {
|
public class SetUtilsUnitTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
@ -27,33 +24,33 @@ public class SetUtilsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoSets_whenDifference_thenSetView() {
|
public void givenTwoSets_whenDifference_thenSetView() {
|
||||||
Set<Integer> a = 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> b = new HashSet<>(Arrays.asList(1, 2));
|
||||||
SetUtils.SetView<Integer> result = SetUtils.difference(a, b);
|
SetUtils.SetView<Integer> result = SetUtils.difference(a, b);
|
||||||
assertTrue(result.size() == 1 && result.contains(5));
|
assertTrue(result.size() == 1 && result.contains(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoSets_whenUnion_thenUnionResult() {
|
public void givenTwoSets_whenUnion_thenUnionResult() {
|
||||||
Set<Integer> a = 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> b = new HashSet<>(Arrays.asList(1, 2));
|
||||||
Set<Integer> expected = new HashSet<>(Arrays.asList(1,2,5));
|
Set<Integer> expected = new HashSet<>(Arrays.asList(1, 2, 5));
|
||||||
SetUtils.SetView<Integer> union = SetUtils.union(a, b);
|
SetUtils.SetView<Integer> union = SetUtils.union(a, b);
|
||||||
assertTrue(SetUtils.isEqualSet(expected, union));
|
assertTrue(SetUtils.isEqualSet(expected, union));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoSets_whenIntersection_thenIntersectionResult() {
|
public void givenTwoSets_whenIntersection_thenIntersectionResult() {
|
||||||
Set<Integer> a = 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> b = new HashSet<>(Arrays.asList(1, 2));
|
||||||
Set<Integer> expected = new HashSet<>(Arrays.asList(1,2));
|
Set<Integer> expected = new HashSet<>(Arrays.asList(1, 2));
|
||||||
SetUtils.SetView<Integer> intersect = SetUtils.intersection(a, b);
|
SetUtils.SetView<Integer> intersect = SetUtils.intersection(a, b);
|
||||||
assertTrue(SetUtils.isEqualSet(expected, intersect));
|
assertTrue(SetUtils.isEqualSet(expected, intersect));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSet_whenTransformedSet_thenTransformedResult() {
|
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);
|
a.add(2);
|
||||||
assertEquals(a.toArray()[0], 4);
|
assertEquals(a.toArray()[0], 4);
|
||||||
|
|
||||||
|
@ -65,19 +62,19 @@ public class SetUtilsUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTwoSet_whenDisjunction_thenDisjunctionSet() {
|
public void givenTwoSet_whenDisjunction_thenDisjunctionSet() {
|
||||||
Set<Integer> a = 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,3));
|
Set<Integer> b = new HashSet<>(Arrays.asList(1, 2, 3));
|
||||||
SetUtils.SetView<Integer> result = SetUtils.disjunction(a, b);
|
SetUtils.SetView<Integer> result = SetUtils.disjunction(a, b);
|
||||||
assertTrue(result.toSet().contains(5) && result.toSet().contains(3));
|
assertTrue(result.toSet().contains(5) && result.toSet().contains(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSet_when_OrderedSet_thenMaintainElementOrder() {
|
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);
|
System.out.println("unordered set: " + set);
|
||||||
|
|
||||||
Set<Integer> orderedSet = SetUtils.orderedSet(new HashSet<>());
|
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);
|
System.out.println("ordered set = " + orderedSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,5 @@
|
||||||
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;
|
||||||
|
@ -12,6 +7,11 @@ 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"};
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package com.baeldung.commons.dbutils;
|
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.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -9,16 +19,9 @@ import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.apache.commons.dbutils.AsyncQueryRunner;
|
|
||||||
import org.apache.commons.dbutils.DbUtils;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.apache.commons.dbutils.QueryRunner;
|
import static org.junit.Assert.assertNotNull;
|
||||||
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;
|
|
||||||
|
|
||||||
public class DbUtilsUnitTest {
|
public class DbUtilsUnitTest {
|
||||||
|
|
||||||
|
@ -45,9 +48,9 @@ public class DbUtilsUnitTest {
|
||||||
|
|
||||||
assertEquals(list.size(), 5);
|
assertEquals(list.size(), 5);
|
||||||
assertEquals(list.get(0)
|
assertEquals(list.get(0)
|
||||||
.get("firstname"), "John");
|
.get("firstname"), "John");
|
||||||
assertEquals(list.get(4)
|
assertEquals(list.get(4)
|
||||||
.get("firstname"), "Christian");
|
.get("firstname"), "Christian");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,9 +62,9 @@ public class DbUtilsUnitTest {
|
||||||
|
|
||||||
assertEquals(employeeList.size(), 5);
|
assertEquals(employeeList.size(), 5);
|
||||||
assertEquals(employeeList.get(0)
|
assertEquals(employeeList.get(0)
|
||||||
.getFirstName(), "John");
|
.getFirstName(), "John");
|
||||||
assertEquals(employeeList.get(4)
|
assertEquals(employeeList.get(4)
|
||||||
.getFirstName(), "Christian");
|
.getFirstName(), "Christian");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,11 +86,11 @@ public class DbUtilsUnitTest {
|
||||||
List<Employee> employees = runner.query(connection, "SELECT * FROM employee", employeeHandler);
|
List<Employee> employees = runner.query(connection, "SELECT * FROM employee", employeeHandler);
|
||||||
|
|
||||||
assertEquals(employees.get(0)
|
assertEquals(employees.get(0)
|
||||||
.getEmails()
|
.getEmails()
|
||||||
.size(), 2);
|
.size(), 2);
|
||||||
assertEquals(employees.get(2)
|
assertEquals(employees.get(2)
|
||||||
.getEmails()
|
.getEmails()
|
||||||
.size(), 3);
|
.size(), 3);
|
||||||
assertNotNull(employees.get(0).getEmails().get(0).getEmployeeId());
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class StringUtilsUnitTest {
|
public class StringUtilsUnitTest {
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class HikariCPUnitTest {
|
public class HikariCPIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenConnection_thenFetchDbData() {
|
public void givenConnection_thenFetchDbData() {
|
|
@ -22,9 +22,9 @@ public class HLLUnitTest {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
hll.addRaw(hashedValue);
|
hll.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
|
@ -43,15 +43,15 @@ public class HLLUnitTest {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
firstHll.addRaw(hashedValue);
|
firstHll.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
|
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
secondHLL.addRaw(hashedValue);
|
secondHLL.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
|
|
|
@ -8,7 +8,9 @@ import org.jasypt.util.text.BasicTextEncryptor;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
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;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
public class JasyptUnitTest {
|
public class JasyptUnitTest {
|
||||||
|
@ -30,7 +32,7 @@ public class JasyptUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldBeSame(){
|
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldBeSame() {
|
||||||
String password = "secret-pass";
|
String password = "secret-pass";
|
||||||
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
||||||
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
||||||
|
@ -43,7 +45,7 @@ public class JasyptUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldNotBeSame(){
|
public void givenTextPassword_whenOneWayEncryption_thenCompareEncryptedPasswordsShouldNotBeSame() {
|
||||||
String password = "secret-pass";
|
String password = "secret-pass";
|
||||||
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
|
||||||
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
String encryptedPassword = passwordEncryptor.encryptPassword(password);
|
||||||
|
@ -56,7 +58,6 @@ public class JasyptUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("should have installed local_policy.jar")
|
@Ignore("should have installed local_policy.jar")
|
||||||
public void givenTextPrivateData_whenDecrypt_thenCompareToEncryptedWithCustomAlgorithm() {
|
public void givenTextPrivateData_whenDecrypt_thenCompareToEncryptedWithCustomAlgorithm() {
|
||||||
|
@ -77,7 +78,7 @@ public class JasyptUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("should have installed local_policy.jar")
|
@Ignore("should have installed local_policy.jar")
|
||||||
public void givenTextPrivateData_whenDecryptOnHighPerformance_thenDecrypt(){
|
public void givenTextPrivateData_whenDecryptOnHighPerformance_thenDecrypt() {
|
||||||
//given
|
//given
|
||||||
String privateData = "secret-data";
|
String privateData = "secret-data";
|
||||||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||||
|
|
|
@ -8,7 +8,6 @@ import javax.jdo.PersistenceManager;
|
||||||
import javax.jdo.PersistenceManagerFactory;
|
import javax.jdo.PersistenceManagerFactory;
|
||||||
import javax.jdo.Query;
|
import javax.jdo.Query;
|
||||||
import javax.jdo.Transaction;
|
import javax.jdo.Transaction;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
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 au.com.dius.pact.model.RequestResponsePact;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
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 org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -20,7 +24,7 @@ public class PactConsumerDrivenContractUnitTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public PactProviderRuleMk2 mockProvider
|
public PactProviderRuleMk2 mockProvider
|
||||||
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
|
= new PactProviderRuleMk2("test_provider", "localhost", 8080, this);
|
||||||
|
|
||||||
@Pact(consumer = "test_consumer")
|
@Pact(consumer = "test_consumer")
|
||||||
public RequestResponsePact createPact(PactDslWithProvider builder) {
|
public RequestResponsePact createPact(PactDslWithProvider builder) {
|
||||||
|
@ -28,25 +32,25 @@ public class PactConsumerDrivenContractUnitTest {
|
||||||
headers.put("Content-Type", "application/json");
|
headers.put("Content-Type", "application/json");
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.given("test GET ")
|
.given("test GET ")
|
||||||
.uponReceiving("GET REQUEST")
|
.uponReceiving("GET REQUEST")
|
||||||
.path("/")
|
.path("/")
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.willRespondWith()
|
.willRespondWith()
|
||||||
.status(200)
|
.status(200)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body("{\"condition\": true, \"name\": \"tom\"}")
|
.body("{\"condition\": true, \"name\": \"tom\"}")
|
||||||
.given("test POST")
|
.given("test POST")
|
||||||
.uponReceiving("POST REQUEST")
|
.uponReceiving("POST REQUEST")
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body("{\"name\": \"Michael\"}")
|
.body("{\"name\": \"Michael\"}")
|
||||||
.path("/create")
|
.path("/create")
|
||||||
.willRespondWith()
|
.willRespondWith()
|
||||||
.status(201)
|
.status(201)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body("")
|
.body("")
|
||||||
.toPact();
|
.toPact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ public class PactConsumerDrivenContractUnitTest {
|
||||||
public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
|
public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() {
|
||||||
//when
|
//when
|
||||||
ResponseEntity<String> response
|
ResponseEntity<String> response
|
||||||
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
|
= new RestTemplate().getForEntity(mockProvider.getUrl(), String.class);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
assertThat(response.getStatusCode().value()).isEqualTo(200);
|
assertThat(response.getStatusCode().value()).isEqualTo(200);
|
||||||
|
@ -69,10 +73,10 @@ public class PactConsumerDrivenContractUnitTest {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
ResponseEntity<String> postResponse = new RestTemplate().exchange(
|
ResponseEntity<String> postResponse = new RestTemplate().exchange(
|
||||||
mockProvider.getUrl() + "/create",
|
mockProvider.getUrl() + "/create",
|
||||||
HttpMethod.POST,
|
HttpMethod.POST,
|
||||||
new HttpEntity<>(jsonBody, httpHeaders),
|
new HttpEntity<>(jsonBody, httpHeaders),
|
||||||
String.class
|
String.class
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.baeldung.vaadin;
|
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.Connector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
|
@ -15,9 +17,7 @@ import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.vaadin.server.DefaultUIProvider;
|
|
||||||
import com.vaadin.server.VaadinServlet;
|
|
||||||
|
|
||||||
|
|
||||||
public class VaadinUITests {
|
public class VaadinUITests {
|
||||||
|
@ -26,15 +26,15 @@ public class VaadinUITests {
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception{
|
public void setUp() throws Exception {
|
||||||
startJettyServer();
|
startJettyServer();
|
||||||
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45,true);
|
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45, true);
|
||||||
driver.get("http://localhost:8080");
|
driver.get("http://localhost:8080");
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPageLoadedThenShouldSeeURL(){
|
public void whenPageLoadedThenShouldSeeURL() {
|
||||||
String url = driver.getCurrentUrl();
|
String url = driver.getCurrentUrl();
|
||||||
assertEquals("http://localhost:8080/", url);
|
assertEquals("http://localhost:8080/", url);
|
||||||
}
|
}
|
||||||
|
@ -70,12 +70,12 @@ public class VaadinUITests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUp() throws Exception{
|
public void cleanUp() throws Exception {
|
||||||
driver.close();
|
driver.close();
|
||||||
server.stop();
|
server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startJettyServer() throws Exception{
|
public void startJettyServer() throws Exception {
|
||||||
|
|
||||||
int maxThreads = 100;
|
int maxThreads = 100;
|
||||||
int minThreads = 10;
|
int minThreads = 10;
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.io.IOException;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
public class JsonUtil {
|
class JsonUtil {
|
||||||
public static byte[] toJson(Object object) throws IOException {
|
static byte[] toJson(Object object) throws IOException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
return mapper.writeValueAsBytes(object);
|
return mapper.writeValueAsBytes(object);
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<artifactId>spring-mvc-java</artifactId>
|
<artifactId>spring-mvc-java</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
<name>spring-mvc-java</name>
|
<name>spring-mvc-java</name>
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
|
|
Loading…
Reference in New Issue