From 84956990b647400c872a8dccf074c3721587a974 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 12 Jul 2017 19:28:47 +0200 Subject: [PATCH] Build optimization (#2253) --- .../awaitility/AsyncServiceUnitTest.java | 1 - .../proxy/BeanGeneratorIntegrationTest.java | 8 +-- .../baeldung/cglib/proxy/MixinUnitTest.java | 10 ++- .../commons/collections/BidiMapUnitTest.java | 10 +-- .../collections/CollectionUtilsGuideTest.java | 35 ++++----- .../commons/collections/MapUtilsTest.java | 72 ++++++++++--------- .../commons/collections/SetUtilsUnitTest.java | 29 ++++---- .../orderedmap/OrderedMapUnitTest.java | 10 +-- .../commons/dbutils/DbUtilsUnitTest.java | 39 +++++----- .../commons/lang3/StringUtilsUnitTest.java | 3 +- ...Test.java => HikariCPIntegrationTest.java} | 2 +- .../java/com/baeldung/hll/HLLUnitTest.java | 18 ++--- .../com/baeldung/jasypt/JasyptUnitTest.java | 11 +-- .../jdo/GuideToJDOIntegrationTest.java | 1 - .../PactConsumerDrivenContractUnitTest.java | 56 ++++++++------- .../java/com/baeldung/text/WordUtilsTest.java | 4 +- .../com/baeldung/vaadin/VaadinUITests.java | 34 ++++----- .../org/baeldung/boot/boottest/JsonUtil.java | 4 +- spring-mvc-java/pom.xml | 1 - 19 files changed, 178 insertions(+), 170 deletions(-) rename libraries/src/test/java/com/baeldung/hikaricp/{HikariCPUnitTest.java => HikariCPIntegrationTest.java} (88%) diff --git a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java index 677d989fba..43537965f8 100644 --- a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java +++ b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java @@ -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; diff --git a/libraries/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorIntegrationTest.java b/libraries/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorIntegrationTest.java index 033cc47c74..1224d73724 100644 --- a/libraries/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorIntegrationTest.java +++ b/libraries/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorIntegrationTest.java @@ -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)); } } diff --git a/libraries/src/test/java/com/baeldung/cglib/proxy/MixinUnitTest.java b/libraries/src/test/java/com/baeldung/cglib/proxy/MixinUnitTest.java index a89d9fe2c3..93b34bf92b 100644 --- a/libraries/src/test/java/com/baeldung/cglib/proxy/MixinUnitTest.java +++ b/libraries/src/test/java/com/baeldung/cglib/proxy/MixinUnitTest.java @@ -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; diff --git a/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java index 64a3932fb3..e46d8654a2 100644 --- a/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java +++ b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java @@ -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 diff --git a/libraries/src/test/java/com/baeldung/commons/collections/CollectionUtilsGuideTest.java b/libraries/src/test/java/com/baeldung/commons/collections/CollectionUtilsGuideTest.java index 90e30b01dc..aa8b799c9d 100644 --- a/libraries/src/test/java/com/baeldung/commons/collections/CollectionUtilsGuideTest.java +++ b/libraries/src/test/java/com/baeldung/commons/collections/CollectionUtilsGuideTest.java @@ -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 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
addressCol = CollectionUtils.collect(list1, new Transformer() { @@ -59,61 +62,61 @@ public class CollectionUtilsGuideTest { return new Address(customer.getLocality(), customer.getCity(), customer.getZip()); } }); - + List
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() { 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 emptyList = new ArrayList<>(); List 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 intersection = CollectionUtils.intersection(list1, list3); assertTrue(intersection.size() == 2); } - + @Test public void givenTwoLists_whenSubtracted_thenCheckElementNotPresentInA() { Collection result = CollectionUtils.subtract(list1, list3); assertFalse(result.contains(customer1)); } - + @Test public void givenTwoLists_whenUnioned_thenCheckElementPresentInResult() { Collection union = CollectionUtils.union(list1, list2); assertTrue(union.contains(customer1)); assertTrue(union.contains(customer4)); } - + } \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/commons/collections/MapUtilsTest.java b/libraries/src/test/java/com/baeldung/commons/collections/MapUtilsTest.java index 84ca2d1281..470eb46cb0 100644 --- a/libraries/src/test/java/com/baeldung/commons/collections/MapUtilsTest.java +++ b/libraries/src/test/java/com/baeldung/commons/collections/MapUtilsTest.java @@ -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 colorMap; - + @Before public void createMap() { this.colorMap = MapUtils.putAll(new HashMap(), this.color2DArray); } - + @Test public void whenCreateMapFrom2DArray_theMapIsCreated() { this.colorMap = MapUtils.putAll(new HashMap(), 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(), 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 invColorMap = MapUtils.invertMap(this.colorMap); assertEquals(this.colorMap.size(), invColorMap.size()); - - MapIterator itColorMap + + MapIterator 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 rgbMap = MapUtils.fixedSizeMap(MapUtils.putAll( - new HashMap(), - this.color1DArray)); - + new HashMap(), + this.color1DArray)); + rgbMap.put("ORANGE", "#FFA500"); } - + @Test(expected = IllegalArgumentException.class) public void whenAddDuplicateToUniqueValuesPredicateMap_thenMustThrowException() { - Map uniqValuesMap + Map uniqValuesMap = MapUtils.predicatedMap(this.colorMap, null, PredicateUtils.uniquePredicate()); - + uniqValuesMap.put("NEW_RED", "#FF0000"); } @Test public void whenCreateLazyMap_theMapIsCreated() { Map intStrMap = MapUtils.lazyMap( - new HashMap(), - TransformerUtils.stringValueTransformer()); - + new HashMap(), + TransformerUtils.stringValueTransformer()); + assertThat(intStrMap, is(anEmptyMap())); - + intStrMap.get(1); intStrMap.get(2); intStrMap.get(3); - + assertThat(intStrMap, is(aMapWithSize(3))); } } diff --git a/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java index 4d264e3aea..7d214bc5c5 100644 --- a/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java +++ b/libraries/src/test/java/com/baeldung/commons/collections/SetUtilsUnitTest.java @@ -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 a = new HashSet<>(Arrays.asList(1,2,5)); - Set b = new HashSet<>(Arrays.asList(1,2)); + 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)); + 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)); + 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 ); + Set 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 a = new HashSet<>(Arrays.asList(1,2,5)); - Set b = new HashSet<>(Arrays.asList(1,2,3)); + 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)); + 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)); + 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 6b2777c289..7a05228e51 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,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"}; diff --git a/libraries/src/test/java/com/baeldung/commons/dbutils/DbUtilsUnitTest.java b/libraries/src/test/java/com/baeldung/commons/dbutils/DbUtilsUnitTest.java index 8eb2fd1350..bc7623589c 100644 --- a/libraries/src/test/java/com/baeldung/commons/dbutils/DbUtilsUnitTest.java +++ b/libraries/src/test/java/com/baeldung/commons/dbutils/DbUtilsUnitTest.java @@ -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 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()); } diff --git a/libraries/src/test/java/com/baeldung/commons/lang3/StringUtilsUnitTest.java b/libraries/src/test/java/com/baeldung/commons/lang3/StringUtilsUnitTest.java index 15620455aa..191387d088 100644 --- a/libraries/src/test/java/com/baeldung/commons/lang3/StringUtilsUnitTest.java +++ b/libraries/src/test/java/com/baeldung/commons/lang3/StringUtilsUnitTest.java @@ -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 diff --git a/libraries/src/test/java/com/baeldung/hikaricp/HikariCPUnitTest.java b/libraries/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java similarity index 88% rename from libraries/src/test/java/com/baeldung/hikaricp/HikariCPUnitTest.java rename to libraries/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java index 1a1c5ef868..80588ecc03 100644 --- a/libraries/src/test/java/com/baeldung/hikaricp/HikariCPUnitTest.java +++ b/libraries/src/test/java/com/baeldung/hikaricp/HikariCPIntegrationTest.java @@ -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() { diff --git a/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java b/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java index 1d318b7e4e..42af5d0f0b 100644 --- a/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java +++ b/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java @@ -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 diff --git a/libraries/src/test/java/com/baeldung/jasypt/JasyptUnitTest.java b/libraries/src/test/java/com/baeldung/jasypt/JasyptUnitTest.java index 39d54085e2..5e65c585aa 100644 --- a/libraries/src/test/java/com/baeldung/jasypt/JasyptUnitTest.java +++ b/libraries/src/test/java/com/baeldung/jasypt/JasyptUnitTest.java @@ -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(); diff --git a/libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java b/libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java index 578f9ff902..e916a229f7 100644 --- a/libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java +++ b/libraries/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java @@ -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; diff --git a/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java b/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java index 2952938cd9..b152b22964 100644 --- a/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java +++ b/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java @@ -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 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 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 diff --git a/libraries/src/test/java/com/baeldung/text/WordUtilsTest.java b/libraries/src/test/java/com/baeldung/text/WordUtilsTest.java index b9268d67b3..fafba2fbb5 100644 --- a/libraries/src/test/java/com/baeldung/text/WordUtilsTest.java +++ b/libraries/src/test/java/com/baeldung/text/WordUtilsTest.java @@ -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); } } diff --git a/libraries/src/test/java/com/baeldung/vaadin/VaadinUITests.java b/libraries/src/test/java/com/baeldung/vaadin/VaadinUITests.java index 1b7a35d865..228b91de34 100644 --- a/libraries/src/test/java/com/baeldung/vaadin/VaadinUITests.java +++ b/libraries/src/test/java/com/baeldung/vaadin/VaadinUITests.java @@ -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; diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java index 3d532ce54a..8c7e5576ce 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java @@ -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); diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index eb8e1455a7..b939f0496d 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -5,7 +5,6 @@ spring-mvc-java 0.1-SNAPSHOT spring-mvc-java - war com.baeldung