From c8a481bb77ddfb725ae138110ad6e5cd301a5291 Mon Sep 17 00:00:00 2001 From: Leon Mak Date: Tue, 29 Oct 2019 14:37:40 +0800 Subject: [PATCH] Add java 11 support for #987 (o-t) (#1051) * Use java 11 * Use .of - Replace Arrays.asList with List.of - Replace HashSet<>(List.of()) with Set.of * Formatting --- .../AbstractDocumentTest.java | 1 - .../iluwatar/abstractdocument/DomainTest.java | 3 +- .../com/iluwatar/collectionpipeline/App.java | 13 ++++---- .../collectionpipeline/CarFactory.java | 3 +- .../java/com/iluwatar/commander/Service.java | 2 +- .../com/iluwatar/commander/RetryTest.java | 4 +-- .../com/iluwatar/fluentinterface/app/App.java | 15 ++++----- .../fluentiterable/FluentIterableTest.java | 31 +++++++----------- .../hexagonal/domain/LotteryNumbersTest.java | 22 ++++--------- .../hexagonal/domain/LotteryTest.java | 4 +-- .../hexagonal/domain/LotteryTicketTest.java | 2 -- .../hexagonal/test/LotteryTestUtils.java | 6 ++-- .../main/java/com/iluwatar/layers/App.java | 12 ++++--- .../layers/CakeBakingServiceImplTest.java | 15 +++------ .../iluwatar/mediator/PartyMemberTest.java | 3 +- .../scenarios/RecreateSimpleObjects.java | 15 ++++----- .../object/pool/OliphauntPoolTest.java | 9 ++---- .../com/iluwatar/observer/HobbitsTest.java | 12 +++---- .../java/com/iluwatar/observer/OrcsTest.java | 12 +++---- .../observer/generic/GHobbitsTest.java | 13 ++++---- .../iluwatar/observer/generic/OrcsTest.java | 13 ++++---- .../com/iluwatar/partialresponse/App.java | 12 ++++--- .../partialresponse/VideoResourceTest.java | 12 ++++--- .../com/iluwatar/prototype/PrototypeTest.java | 9 ++---- .../AnnotationBasedRepositoryTest.java | 19 ++++------- .../iluwatar/repository/RepositoryTest.java | 19 ++++------- .../java/com/iluwatar/retry/FindCustomer.java | 4 +-- .../main/java/com/iluwatar/servant/App.java | 5 +-- .../com/iluwatar/servant/ServantTest.java | 11 ++----- .../magic/MagicServiceImplTest.java | 18 +++++------ .../com/iluwatar/specification/app/App.java | 18 +++-------- .../specification/creature/CreatureTest.java | 10 +++--- .../strategy/DragonSlayingStrategyTest.java | 27 ++++++++-------- .../java/com/iluwatar/threadpool/App.java | 32 +++++++++---------- .../iluwatar/tls/DateFormatCallableTest.java | 9 +++--- ...FormatCallableTestIncorrectDateFormat.java | 9 +++--- .../DateFormatCallableTestMultiThread.java | 9 +++--- 37 files changed, 176 insertions(+), 257 deletions(-) diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java index 0514c750aa77..da576539102a 100644 --- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java +++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java b/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java index 663071f6a0a7..eed4ad9bb94e 100644 --- a/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java +++ b/abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java @@ -28,7 +28,6 @@ import com.iluwatar.abstractdocument.domain.enums.Property; import org.junit.jupiter.api.Test; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -64,7 +63,7 @@ public void shouldConstructCar() { Map carProperties = Map.of( Property.MODEL.toString(), TEST_CAR_MODEL, Property.PRICE.toString(), TEST_CAR_PRICE, - Property.PARTS.toString(), List.of(new HashMap<>(), new HashMap<>())); + Property.PARTS.toString(), List.of(Map.of(), Map.of())); Car car = new Car(carProperties); assertEquals(TEST_CAR_MODEL, car.getModel().get()); diff --git a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/App.java b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/App.java index 3a811f0e0806..de19a3b15508 100644 --- a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/App.java +++ b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/App.java @@ -23,13 +23,12 @@ package com.iluwatar.collectionpipeline; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.Map; + /** * In imperative-style programming, it is common to use for and while loops for * most kinds of data processing. Function composition is a simple technique @@ -67,11 +66,11 @@ public static void main(String[] args) { LOGGER.info(groupingByCategoryFunctional.toString()); Person john = new Person(cars); - - List sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john)); + + List sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john)); LOGGER.info(sedansOwnedImperative.toString()); - List sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john)); + List sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john)); LOGGER.info(sedansOwnedFunctional.toString()); } } diff --git a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/CarFactory.java b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/CarFactory.java index 6e4531f5fb0a..aee1e21932df 100644 --- a/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/CarFactory.java +++ b/collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/CarFactory.java @@ -23,7 +23,6 @@ package com.iluwatar.collectionpipeline; -import java.util.Arrays; import java.util.List; /** @@ -38,7 +37,7 @@ private CarFactory() { * @return {@link List} of {@link Car} */ public static List createCars() { - return Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP), + return List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP), new Car("Jeep", "Comanche", 1990, Category.JEEP), new Car("Dodge", "Avenger", 2010, Category.SEDAN), new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE), diff --git a/commander/src/main/java/com/iluwatar/commander/Service.java b/commander/src/main/java/com/iluwatar/commander/Service.java index 2e293520b87b..64af79053459 100644 --- a/commander/src/main/java/com/iluwatar/commander/Service.java +++ b/commander/src/main/java/com/iluwatar/commander/Service.java @@ -43,7 +43,7 @@ public abstract class Service { public ArrayList exceptionsList; private static final Random RANDOM = new Random(); private static final String ALL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - private static final Hashtable USED_IDS = new Hashtable(); + private static final Hashtable USED_IDS = new Hashtable<>(); protected Service(Database db, Exception...exc) { this.database = db; diff --git a/commander/src/test/java/com/iluwatar/commander/RetryTest.java b/commander/src/test/java/com/iluwatar/commander/RetryTest.java index c4ee5caf7964..749b2619cbac 100644 --- a/commander/src/test/java/com/iluwatar/commander/RetryTest.java +++ b/commander/src/test/java/com/iluwatar/commander/RetryTest.java @@ -45,9 +45,9 @@ void performTest() { Retry.HandleErrorIssue handleError = (o,e) -> { return; }; - Retry r1 = new Retry(op, handleError, 3, 30000, + Retry r1 = new Retry<>(op, handleError, 3, 30000, e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass())); - Retry r2 = new Retry(op, handleError, 3, 30000, + Retry r2 = new Retry<>(op, handleError, 3, 30000, e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass())); User user = new User("Jim", "ABCD"); Order order = new Order(user, "book", 10f); diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java index 597f9d928f75..36766a568003 100644 --- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java +++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java @@ -23,21 +23,20 @@ package com.iluwatar.fluentinterface.app; -import static java.lang.String.valueOf; +import com.iluwatar.fluentinterface.fluentiterable.FluentIterable; +import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable; +import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.StringJoiner; import java.util.function.Function; import java.util.function.Predicate; -import com.iluwatar.fluentinterface.fluentiterable.FluentIterable; -import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable; -import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.lang.String.valueOf; /** * The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API. @@ -61,7 +60,7 @@ public class App { public static void main(String[] args) { List integerList = new ArrayList<>(); - integerList.addAll(Arrays.asList(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2, + integerList.addAll(List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2, -68, 45)); prettyPrint("The initial list contains: ", integerList); diff --git a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java index cfe52be7f1e5..4ee30d3e5734 100644 --- a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java +++ b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java @@ -25,21 +25,14 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Spliterator; import java.util.function.Consumer; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; /** * Date: 12/12/15 - 7:00 PM @@ -58,7 +51,7 @@ public abstract class FluentIterableTest { @Test public void testFirst() throws Exception { - final List integers = Arrays.asList(1, 2, 3, 10, 9, 8); + final List integers = List.of(1, 2, 3, 10, 9, 8); final Optional first = createFluentIterable(integers).first(); assertNotNull(first); assertTrue(first.isPresent()); @@ -75,7 +68,7 @@ public void testFirstEmptyCollection() throws Exception { @Test public void testFirstCount() throws Exception { - final List integers = Arrays.asList(1, 2, 3, 10, 9, 8); + final List integers = List.of(1, 2, 3, 10, 9, 8); final List first4 = createFluentIterable(integers) .first(4) .asList(); @@ -91,7 +84,7 @@ public void testFirstCount() throws Exception { @Test public void testFirstCountLessItems() throws Exception { - final List integers = Arrays.asList(1, 2, 3); + final List integers = List.of(1, 2, 3); final List first4 = createFluentIterable(integers) .first(4) .asList(); @@ -106,7 +99,7 @@ public void testFirstCountLessItems() throws Exception { @Test public void testLast() throws Exception { - final List integers = Arrays.asList(1, 2, 3, 10, 9, 8); + final List integers = List.of(1, 2, 3, 10, 9, 8); final Optional last = createFluentIterable(integers).last(); assertNotNull(last); assertTrue(last.isPresent()); @@ -123,7 +116,7 @@ public void testLastEmptyCollection() throws Exception { @Test public void testLastCount() throws Exception { - final List integers = Arrays.asList(1, 2, 3, 10, 9, 8); + final List integers = List.of(1, 2, 3, 10, 9, 8); final List last4 = createFluentIterable(integers) .last(4) .asList(); @@ -138,7 +131,7 @@ public void testLastCount() throws Exception { @Test public void testLastCountLessItems() throws Exception { - final List integers = Arrays.asList(1, 2, 3); + final List integers = List.of(1, 2, 3); final List last4 = createFluentIterable(integers) .last(4) .asList(); @@ -153,7 +146,7 @@ public void testLastCountLessItems() throws Exception { @Test public void testFilter() throws Exception { - final List integers = Arrays.asList(1, 2, 3, 10, 9, 8); + final List integers = List.of(1, 2, 3, 10, 9, 8); final List evenItems = createFluentIterable(integers) .filter(i -> i % 2 == 0) .asList(); @@ -167,7 +160,7 @@ public void testFilter() throws Exception { @Test public void testMap() throws Exception { - final List integers = Arrays.asList(1, 2, 3); + final List integers = List.of(1, 2, 3); final List longs = createFluentIterable(integers) .map(Integer::longValue) .asList(); @@ -181,7 +174,7 @@ public void testMap() throws Exception { @Test public void testForEach() { - final List integers = Arrays.asList(1, 2, 3); + final List integers = List.of(1, 2, 3); final Consumer consumer = mock(Consumer.class); createFluentIterable(integers).forEach(consumer); @@ -195,7 +188,7 @@ public void testForEach() { @Test public void testSpliterator() throws Exception { - final List integers = Arrays.asList(1, 2, 3); + final List integers = List.of(1, 2, 3); final Spliterator split = createFluentIterable(integers).spliterator(); assertNotNull(split); } diff --git a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryNumbersTest.java b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryNumbersTest.java index 1812263899b7..c17c5c1fdc39 100644 --- a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryNumbersTest.java +++ b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryNumbersTest.java @@ -25,14 +25,9 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.HashSet; import java.util.Set; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @@ -43,8 +38,7 @@ class LotteryNumbersTest { @Test void testGivenNumbers() { - LotteryNumbers numbers = LotteryNumbers.create( - Set.of(1, 2, 3, 4)); + LotteryNumbers numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4)); assertEquals(numbers.getNumbers().size(), 4); assertTrue(numbers.getNumbers().contains(1)); assertTrue(numbers.getNumbers().contains(2)); @@ -54,8 +48,7 @@ void testGivenNumbers() { @Test void testNumbersCantBeModified() { - LotteryNumbers numbers = LotteryNumbers.create( - Set.of(1, 2, 3, 4)); + LotteryNumbers numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4)); assertThrows(UnsupportedOperationException.class, () -> numbers.getNumbers().add(5)); } @@ -67,13 +60,10 @@ void testRandomNumbers() { @Test void testEquals() { - LotteryNumbers numbers1 = LotteryNumbers.create( - Set.of(1, 2, 3, 4)); - LotteryNumbers numbers2 = LotteryNumbers.create( - Set.of(1, 2, 3, 4)); + LotteryNumbers numbers1 = LotteryNumbers.create(Set.of(1, 2, 3, 4)); + LotteryNumbers numbers2 = LotteryNumbers.create(Set.of(1, 2, 3, 4)); assertEquals(numbers1, numbers2); - LotteryNumbers numbers3 = LotteryNumbers.create( - Set.of(11, 12, 13, 14)); + LotteryNumbers numbers3 = LotteryNumbers.create(Set.of(11, 12, 13, 14)); assertNotEquals(numbers1, numbers3); } } diff --git a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTest.java b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTest.java index a62adaff870a..927e2fcd19a9 100644 --- a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTest.java +++ b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTest.java @@ -35,9 +35,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * diff --git a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTicketTest.java b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTicketTest.java index 0e81a163b844..6d2e371c4bd0 100644 --- a/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTicketTest.java +++ b/hexagonal/src/test/java/com/iluwatar/hexagonal/domain/LotteryTicketTest.java @@ -25,8 +25,6 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.HashSet; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/hexagonal/src/test/java/com/iluwatar/hexagonal/test/LotteryTestUtils.java b/hexagonal/src/test/java/com/iluwatar/hexagonal/test/LotteryTestUtils.java index 4646aa2ff69d..2f02ca34e9f2 100644 --- a/hexagonal/src/test/java/com/iluwatar/hexagonal/test/LotteryTestUtils.java +++ b/hexagonal/src/test/java/com/iluwatar/hexagonal/test/LotteryTestUtils.java @@ -23,15 +23,13 @@ package com.iluwatar.hexagonal.test; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - import com.iluwatar.hexagonal.domain.LotteryNumbers; import com.iluwatar.hexagonal.domain.LotteryTicket; import com.iluwatar.hexagonal.domain.LotteryTicketId; import com.iluwatar.hexagonal.domain.PlayerDetails; +import java.util.Set; + /** * * Utilities for lottery tests diff --git a/layers/src/main/java/com/iluwatar/layers/App.java b/layers/src/main/java/com/iluwatar/layers/App.java index 744c82768212..a4e0a4ab20fe 100644 --- a/layers/src/main/java/com/iluwatar/layers/App.java +++ b/layers/src/main/java/com/iluwatar/layers/App.java @@ -23,7 +23,7 @@ package com.iluwatar.layers; -import java.util.Arrays; +import java.util.List; /** * @@ -99,16 +99,18 @@ private static void initializeData(CakeBakingService cakeBakingService) { cakeBakingService.saveNewTopping(new CakeToppingInfo("cherry", 350)); CakeInfo cake1 = - new CakeInfo(new CakeToppingInfo("candies", 0), Arrays.asList(new CakeLayerInfo( - "chocolate", 0), new CakeLayerInfo("banana", 0), new CakeLayerInfo("strawberry", 0))); + new CakeInfo(new CakeToppingInfo("candies", 0), List.of( + new CakeLayerInfo("chocolate", 0), + new CakeLayerInfo("banana", 0), + new CakeLayerInfo("strawberry", 0))); try { cakeBakingService.bakeNewCake(cake1); } catch (CakeBakingException e) { e.printStackTrace(); } CakeInfo cake2 = - new CakeInfo(new CakeToppingInfo("cherry", 0), Arrays.asList( - new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo( + new CakeInfo(new CakeToppingInfo("cherry", 0), List.of( + new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo( "strawberry", 0))); try { cakeBakingService.bakeNewCake(cake2); diff --git a/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java b/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java index 681b37e05870..21f3623298fb 100644 --- a/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java +++ b/layers/src/test/java/com/iluwatar/layers/CakeBakingServiceImplTest.java @@ -25,15 +25,10 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Date: 12/15/15 - 9:55 PM @@ -108,7 +103,7 @@ public void testBakeCakes() throws CakeBakingException { service.saveNewLayer(layer2); service.saveNewLayer(layer3); - service.bakeNewCake(new CakeInfo(topping1, Arrays.asList(layer1, layer2))); + service.bakeNewCake(new CakeInfo(topping1, List.of(layer1, layer2))); service.bakeNewCake(new CakeInfo(topping2, Collections.singletonList(layer3))); final List allCakes = service.getAllCakes(); @@ -136,7 +131,7 @@ public void testBakeCakeMissingTopping() { final CakeToppingInfo missingTopping = new CakeToppingInfo("Topping1", 1000); assertThrows(CakeBakingException.class, () -> { - service.bakeNewCake(new CakeInfo(missingTopping, Arrays.asList(layer1, layer2))); + service.bakeNewCake(new CakeInfo(missingTopping, List.of(layer1, layer2))); }); } @@ -156,7 +151,7 @@ public void testBakeCakeMissingLayer() { final CakeLayerInfo missingLayer = new CakeLayerInfo("Layer2", 2000); assertThrows(CakeBakingException.class, () -> { - service.bakeNewCake(new CakeInfo(topping1, Arrays.asList(layer1, missingLayer))); + service.bakeNewCake(new CakeInfo(topping1, List.of(layer1, missingLayer))); }); } @@ -178,7 +173,7 @@ public void testBakeCakesUsedLayer() throws CakeBakingException { service.saveNewLayer(layer1); service.saveNewLayer(layer2); - service.bakeNewCake(new CakeInfo(topping1, Arrays.asList(layer1, layer2))); + service.bakeNewCake(new CakeInfo(topping1, List.of(layer1, layer2))); assertThrows(CakeBakingException.class, () -> { service.bakeNewCake(new CakeInfo(topping2, Collections.singletonList(layer2))); }); diff --git a/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java b/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java index b7092347b840..951f8e166c89 100644 --- a/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java +++ b/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java @@ -32,7 +32,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.LoggerFactory; -import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -50,7 +49,7 @@ public class PartyMemberTest { static Collection[]> dataProvider() { - return Arrays.asList( + return List.of( new Supplier[]{Hobbit::new}, new Supplier[]{Hunter::new}, new Supplier[]{Rogue::new}, diff --git a/naked-objects/fixture/src/main/java/domainapp/fixture/scenarios/RecreateSimpleObjects.java b/naked-objects/fixture/src/main/java/domainapp/fixture/scenarios/RecreateSimpleObjects.java index 2c201ead22e6..303dfda4fa13 100644 --- a/naked-objects/fixture/src/main/java/domainapp/fixture/scenarios/RecreateSimpleObjects.java +++ b/naked-objects/fixture/src/main/java/domainapp/fixture/scenarios/RecreateSimpleObjects.java @@ -23,17 +23,14 @@ package domainapp.fixture.scenarios; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import com.google.common.collect.Lists; - -import org.apache.isis.applib.fixturescripts.FixtureScript; - import domainapp.dom.modules.simple.SimpleObject; import domainapp.fixture.modules.simple.SimpleObjectCreate; import domainapp.fixture.modules.simple.SimpleObjectsTearDown; +import org.apache.isis.applib.fixturescripts.FixtureScript; + +import java.util.Collections; +import java.util.List; /** @@ -41,8 +38,8 @@ */ public class RecreateSimpleObjects extends FixtureScript { - public final List names = Collections.unmodifiableList(Arrays.asList("Foo", "Bar", "Baz", - "Frodo", "Froyo", "Fizz", "Bip", "Bop", "Bang", "Boo")); + public final List names = Collections.unmodifiableList(List.of("Foo", "Bar", "Baz", + "Frodo", "Froyo", "Fizz", "Bip", "Bop", "Bang", "Boo")); // region > number (optional input) private Integer number; diff --git a/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java b/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java index b946f80981d7..d4ca42948b81 100644 --- a/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java +++ b/object-pool/src/test/java/com/iluwatar/object/pool/OliphauntPoolTest.java @@ -25,15 +25,10 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.List; import static java.time.Duration.ofMillis; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTimeout; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Date: 12/27/15 - 1:05 AM @@ -115,7 +110,7 @@ public void testConcurrentCheckinCheckout() { // The order of the returned instances is not determined, so just put them in a list // and verify if both expected instances are in there. - final List oliphaunts = Arrays.asList(pool.checkOut(), pool.checkOut()); + final List oliphaunts = List.of(pool.checkOut(), pool.checkOut()); assertEquals(pool.toString(), "Pool available=0 inUse=2"); assertTrue(oliphaunts.contains(firstOliphaunt)); assertTrue(oliphaunts.contains(secondOliphaunt)); diff --git a/observer/src/test/java/com/iluwatar/observer/HobbitsTest.java b/observer/src/test/java/com/iluwatar/observer/HobbitsTest.java index c43c592da611..66ec45fdb62e 100644 --- a/observer/src/test/java/com/iluwatar/observer/HobbitsTest.java +++ b/observer/src/test/java/com/iluwatar/observer/HobbitsTest.java @@ -23,7 +23,6 @@ package com.iluwatar.observer; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -36,12 +35,11 @@ public class HobbitsTest extends WeatherObserverTest { @Override public Collection dataProvider() { - final List testData = new ArrayList<>(); - testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."}); - testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."}); - testData.add(new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."}); - testData.add(new Object[]{WeatherType.COLD, "The hobbits are shivering in the cold weather."}); - return testData; + return List.of( + new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."}, + new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."}, + new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."}, + new Object[]{WeatherType.COLD, "The hobbits are shivering in the cold weather."}); } /** diff --git a/observer/src/test/java/com/iluwatar/observer/OrcsTest.java b/observer/src/test/java/com/iluwatar/observer/OrcsTest.java index b2c0fcbaca10..ff615df3c94e 100644 --- a/observer/src/test/java/com/iluwatar/observer/OrcsTest.java +++ b/observer/src/test/java/com/iluwatar/observer/OrcsTest.java @@ -23,7 +23,6 @@ package com.iluwatar.observer; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -36,12 +35,11 @@ public class OrcsTest extends WeatherObserverTest { @Override public Collection dataProvider() { - final List testData = new ArrayList<>(); - testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."}); - testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."}); - testData.add(new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."}); - testData.add(new Object[]{WeatherType.COLD, "The orcs are freezing cold."}); - return testData; + return List.of( + new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."}, + new Object[]{WeatherType.RAINY, "The orcs are dripping wet."}, + new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."}, + new Object[]{WeatherType.COLD, "The orcs are freezing cold."}); } /** diff --git a/observer/src/test/java/com/iluwatar/observer/generic/GHobbitsTest.java b/observer/src/test/java/com/iluwatar/observer/generic/GHobbitsTest.java index 93e68a9f1ac1..dd0e6d6bf5f4 100644 --- a/observer/src/test/java/com/iluwatar/observer/generic/GHobbitsTest.java +++ b/observer/src/test/java/com/iluwatar/observer/generic/GHobbitsTest.java @@ -25,7 +25,6 @@ import com.iluwatar.observer.WeatherType; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -38,12 +37,12 @@ public class GHobbitsTest extends ObserverTest { @Override public Collection dataProvider() { - final List testData = new ArrayList<>(); - testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."}); - testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."}); - testData.add(new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."}); - testData.add(new Object[]{WeatherType.COLD, "The hobbits are shivering in the cold weather."}); - return testData; + return List.of( + new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."}, + new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."}, + new Object[]{WeatherType.WINDY, "The hobbits hold their hats tightly in the windy weather."}, + new Object[]{WeatherType.COLD, "The hobbits are shivering in the cold weather."} + ); } /** diff --git a/observer/src/test/java/com/iluwatar/observer/generic/OrcsTest.java b/observer/src/test/java/com/iluwatar/observer/generic/OrcsTest.java index b73b105199cc..396de445669f 100644 --- a/observer/src/test/java/com/iluwatar/observer/generic/OrcsTest.java +++ b/observer/src/test/java/com/iluwatar/observer/generic/OrcsTest.java @@ -25,7 +25,6 @@ import com.iluwatar.observer.WeatherType; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -38,12 +37,12 @@ public class OrcsTest extends ObserverTest { @Override public Collection dataProvider() { - final List testData = new ArrayList<>(); - testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."}); - testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."}); - testData.add(new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."}); - testData.add(new Object[]{WeatherType.COLD, "The orcs are freezing cold."}); - return testData; + return List.of( + new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."}, + new Object[]{WeatherType.RAINY, "The orcs are dripping wet."}, + new Object[]{WeatherType.WINDY, "The orc smell almost vanishes in the wind."}, + new Object[]{WeatherType.COLD, "The orcs are freezing cold."} + ); } /** diff --git a/partial-response/src/main/java/com/iluwatar/partialresponse/App.java b/partial-response/src/main/java/com/iluwatar/partialresponse/App.java index 05aa660880c1..314846a3dbe5 100644 --- a/partial-response/src/main/java/com/iluwatar/partialresponse/App.java +++ b/partial-response/src/main/java/com/iluwatar/partialresponse/App.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; import java.util.Map; /** @@ -47,10 +46,13 @@ public class App { * @param args program argument. */ public static void main(String[] args) throws Exception { - Map videos = new HashMap<>(); - videos.put(1, new Video(1, "Avatar", 178, "epic science fiction film", "James Cameron", "English")); - videos.put(2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", "Hideaki Anno", "Japanese")); - videos.put(3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English")); + Map videos = Map.of( + 1, new Video(1, "Avatar", 178, "epic science fiction film", + "James Cameron", "English"), + 2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", + "Hideaki Anno", "Japanese"), + 3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", + "Christopher Nolan", "English")); VideoResource videoResource = new VideoResource(new FieldJsonMapper(), videos); diff --git a/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java b/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java index c28613f4a8c7..85f240fa03db 100644 --- a/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java +++ b/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java @@ -29,7 +29,6 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -49,10 +48,13 @@ public class VideoResourceTest { @Before public void setUp() { - Map videos = new HashMap<>(); - videos.put(1, new Video(1, "Avatar", 178, "epic science fiction film", "James Cameron", "English")); - videos.put(2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", "Hideaki Anno", "Japanese")); - videos.put(3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English")); + Map videos = Map.of( + 1, new Video(1, "Avatar", 178, "epic science fiction film", + "James Cameron", "English"), + 2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", + "Hideaki Anno", "Japanese"), + 3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", + "Christopher Nolan", "English")); resource = new VideoResource(fieldJsonMapper, videos); } diff --git a/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java b/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java index 8fbd80294b4c..e4dd0658a0d8 100644 --- a/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java +++ b/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java @@ -26,13 +26,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import java.util.Arrays; import java.util.Collection; +import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.*; /** * Date: 12/28/15 - 8:45 PM @@ -41,7 +38,7 @@ */ public class PrototypeTest

{ static Collection dataProvider() { - return Arrays.asList( + return List.of( new Object[]{new OrcBeast("axe"), "Orcish wolf attacks with axe"}, new Object[]{new OrcMage("sword"), "Orcish mage attacks with sword"}, new Object[]{new OrcWarlord("laser"), "Orcish warlord attacks with laser"}, diff --git a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java index 6e53713233a1..3b0bff608327 100644 --- a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java +++ b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java @@ -23,16 +23,7 @@ package com.iluwatar.repository; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import javax.annotation.Resource; - +import com.google.common.collect.Lists; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +31,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; -import com.google.common.collect.Lists; +import javax.annotation.Resource; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; /** * Test case to test the functions of {@link PersonRepository}, beside the CRUD functions, the query @@ -59,7 +54,7 @@ public class AnnotationBasedRepositoryTest { Person john = new Person("John", "lawrence", 35); Person terry = new Person("Terry", "Law", 36); - List persons = Arrays.asList(peter, nasta, john, terry); + List persons = List.of(peter, nasta, john, terry); /** * Prepare data for test diff --git a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java index 9f7615aa57de..614f18dba1af 100644 --- a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java +++ b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java @@ -23,16 +23,7 @@ package com.iluwatar.repository; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import javax.annotation.Resource; - +import com.google.common.collect.Lists; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +31,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; -import com.google.common.collect.Lists; +import javax.annotation.Resource; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; /** * Test case to test the functions of {@link PersonRepository}, beside the CRUD functions, the query @@ -58,7 +53,7 @@ public class RepositoryTest { Person john = new Person("John", "lawrence", 35); Person terry = new Person("Terry", "Law", 36); - List persons = Arrays.asList(peter, nasta, john, terry); + List persons = List.of(peter, nasta, john, terry); /** * Prepare data for test diff --git a/retry/src/main/java/com/iluwatar/retry/FindCustomer.java b/retry/src/main/java/com/iluwatar/retry/FindCustomer.java index 11c2b40d6e03..e5013f50e925 100644 --- a/retry/src/main/java/com/iluwatar/retry/FindCustomer.java +++ b/retry/src/main/java/com/iluwatar/retry/FindCustomer.java @@ -24,8 +24,8 @@ package com.iluwatar.retry; import java.util.ArrayDeque; -import java.util.Arrays; import java.util.Deque; +import java.util.List; /** * Finds a customer, returning its ID from our records. @@ -48,7 +48,7 @@ public final class FindCustomer implements BusinessOperation { */ public FindCustomer(String customerId, BusinessException... errors) { this.customerId = customerId; - this.errors = new ArrayDeque<>(Arrays.asList(errors)); + this.errors = new ArrayDeque<>(List.of(errors)); } @Override diff --git a/servant/src/main/java/com/iluwatar/servant/App.java b/servant/src/main/java/com/iluwatar/servant/App.java index a629856d5173..35a26dbcc955 100644 --- a/servant/src/main/java/com/iluwatar/servant/App.java +++ b/servant/src/main/java/com/iluwatar/servant/App.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.List; @@ -60,9 +59,7 @@ public static void scenario(Servant servant, int compliment) { King k = new King(); Queen q = new Queen(); - List guests = new ArrayList<>(); - guests.add(k); - guests.add(q); + List guests = List.of(k, q); // feed servant.feed(k); diff --git a/servant/src/test/java/com/iluwatar/servant/ServantTest.java b/servant/src/test/java/com/iluwatar/servant/ServantTest.java index 4431f6d60837..02b69559e624 100644 --- a/servant/src/test/java/com/iluwatar/servant/ServantTest.java +++ b/servant/src/test/java/com/iluwatar/servant/ServantTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -76,15 +75,9 @@ public void testCheckIfYouWillBeHanged() { final Royalty badMoodRoyalty = mock(Royalty.class); when(badMoodRoyalty.getMood()).thenReturn(true); - final List goodCompany = new ArrayList<>(); - goodCompany.add(goodMoodRoyalty); - goodCompany.add(goodMoodRoyalty); - goodCompany.add(goodMoodRoyalty); + final List goodCompany = List.of(goodMoodRoyalty, goodMoodRoyalty, goodMoodRoyalty); - final List badCompany = new ArrayList<>(); - goodCompany.add(goodMoodRoyalty); - goodCompany.add(goodMoodRoyalty); - goodCompany.add(badMoodRoyalty); + final List badCompany = List.of(goodMoodRoyalty, goodMoodRoyalty, badMoodRoyalty); assertTrue(new Servant("test").checkIfYouWillBeHanged(goodCompany)); assertTrue(new Servant("test").checkIfYouWillBeHanged(badCompany)); diff --git a/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java b/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java index 03284ab6ddd8..b4b3c5714ca3 100644 --- a/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java +++ b/service-layer/src/test/java/com/iluwatar/servicelayer/magic/MagicServiceImplTest.java @@ -97,11 +97,10 @@ public void testFindAllSpells() throws Exception { public void testFindWizardsWithSpellbook() throws Exception { final String bookname = "bookname"; final Spellbook spellbook = mock(Spellbook.class); - final Set wizards = new HashSet<>(); - wizards.add(mock(Wizard.class)); - wizards.add(mock(Wizard.class)); - wizards.add(mock(Wizard.class)); - + final Set wizards = Set.of( + mock(Wizard.class), + mock(Wizard.class), + mock(Wizard.class)); when(spellbook.getWizards()).thenReturn(wizards); final SpellbookDao spellbookDao = mock(SpellbookDao.class); @@ -126,11 +125,10 @@ public void testFindWizardsWithSpellbook() throws Exception { @Test public void testFindWizardsWithSpell() throws Exception { - final Set wizards = new HashSet<>(); - wizards.add(mock(Wizard.class)); - wizards.add(mock(Wizard.class)); - wizards.add(mock(Wizard.class)); - + final Set wizards = Set.of( + mock(Wizard.class), + mock(Wizard.class), + mock(Wizard.class)); final Spellbook spellbook = mock(Spellbook.class); when(spellbook.getWizards()).thenReturn(wizards); diff --git a/specification/src/main/java/com/iluwatar/specification/app/App.java b/specification/src/main/java/com/iluwatar/specification/app/App.java index df80f855f1f5..00b37181438c 100644 --- a/specification/src/main/java/com/iluwatar/specification/app/App.java +++ b/specification/src/main/java/com/iluwatar/specification/app/App.java @@ -23,17 +23,7 @@ package com.iluwatar.specification.app; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import com.iluwatar.specification.creature.Creature; -import com.iluwatar.specification.creature.Dragon; -import com.iluwatar.specification.creature.Goblin; -import com.iluwatar.specification.creature.KillerBee; -import com.iluwatar.specification.creature.Octopus; -import com.iluwatar.specification.creature.Shark; -import com.iluwatar.specification.creature.Troll; +import com.iluwatar.specification.creature.*; import com.iluwatar.specification.property.Color; import com.iluwatar.specification.property.Movement; import com.iluwatar.specification.selector.ColorSelector; @@ -41,6 +31,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.stream.Collectors; + /** * * The central idea of the Specification pattern is to separate the statement of how to match a @@ -64,8 +57,7 @@ public class App { public static void main(String[] args) { // initialize creatures list List creatures = - Arrays.asList(new Goblin(), new Octopus(), new Dragon(), new Shark(), new Troll(), - new KillerBee()); + List.of(new Goblin(), new Octopus(), new Dragon(), new Shark(), new Troll(), new KillerBee()); // find all walking creatures LOGGER.info("Find all walking creatures"); List walkingCreatures = diff --git a/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java b/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java index 022475c24238..26ff4c1ab877 100644 --- a/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java +++ b/specification/src/test/java/com/iluwatar/specification/creature/CreatureTest.java @@ -29,8 +29,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -46,7 +46,7 @@ public class CreatureTest { * @return The tested {@link Creature} instance and its expected specs */ public static Collection dataProvider() { - return Arrays.asList( + return List.of( new Object[]{new Dragon(), "Dragon", Size.LARGE, Movement.FLYING, Color.RED}, new Object[]{new Goblin(), "Goblin", Size.SMALL, Movement.WALKING, Color.GREEN}, new Object[]{new KillerBee(), "KillerBee", Size.SMALL, Movement.FLYING, Color.LIGHT}, @@ -76,15 +76,13 @@ public void testGetMovement(Creature testedCreature, String name, Size size, Mov @ParameterizedTest @MethodSource("dataProvider") - public void testGetColor(Creature testedCreature, String name, Size size, Movement movement, - Color color) { + public void testGetColor(Creature testedCreature, String name, Size size, Movement movement, Color color) { assertEquals(color, testedCreature.getColor()); } @ParameterizedTest @MethodSource("dataProvider") - public void testToString(Creature testedCreature, String name, Size size, Movement movement, - Color color) { + public void testToString(Creature testedCreature, String name, Size size, Movement movement, Color color) { final String toString = testedCreature.toString(); assertNotNull(toString); assertEquals( diff --git a/strategy/src/test/java/com/iluwatar/strategy/DragonSlayingStrategyTest.java b/strategy/src/test/java/com/iluwatar/strategy/DragonSlayingStrategyTest.java index b97cf499fbf8..67e4b92cc643 100644 --- a/strategy/src/test/java/com/iluwatar/strategy/DragonSlayingStrategyTest.java +++ b/strategy/src/test/java/com/iluwatar/strategy/DragonSlayingStrategyTest.java @@ -32,7 +32,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.LoggerFactory; -import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -50,19 +49,19 @@ public class DragonSlayingStrategyTest { * @return The test parameters for each cycle */ static Collection dataProvider() { - return Arrays.asList( - new Object[]{ - new MeleeStrategy(), - "With your Excalibur you sever the dragon's head!" - }, - new Object[]{ - new ProjectileStrategy(), - "You shoot the dragon with the magical crossbow and it falls dead on the ground!" - }, - new Object[]{ - new SpellStrategy(), - "You cast the spell of disintegration and the dragon vaporizes in a pile of dust!" - } + return List.of( + new Object[]{ + new MeleeStrategy(), + "With your Excalibur you sever the dragon's head!" + }, + new Object[]{ + new ProjectileStrategy(), + "You shoot the dragon with the magical crossbow and it falls dead on the ground!" + }, + new Object[]{ + new SpellStrategy(), + "You cast the spell of disintegration and the dragon vaporizes in a pile of dust!" + } ); } diff --git a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java b/thread-pool/src/main/java/com/iluwatar/threadpool/App.java index 9fe16d36ac2a..b21f8cc4a1d3 100644 --- a/thread-pool/src/main/java/com/iluwatar/threadpool/App.java +++ b/thread-pool/src/main/java/com/iluwatar/threadpool/App.java @@ -60,22 +60,22 @@ public static void main(String[] args) { LOGGER.info("Program started"); // Create a list of tasks to be executed - List tasks = new ArrayList<>(); - tasks.add(new PotatoPeelingTask(3)); - tasks.add(new PotatoPeelingTask(6)); - tasks.add(new CoffeeMakingTask(2)); - tasks.add(new CoffeeMakingTask(6)); - tasks.add(new PotatoPeelingTask(4)); - tasks.add(new CoffeeMakingTask(2)); - tasks.add(new PotatoPeelingTask(4)); - tasks.add(new CoffeeMakingTask(9)); - tasks.add(new PotatoPeelingTask(3)); - tasks.add(new CoffeeMakingTask(2)); - tasks.add(new PotatoPeelingTask(4)); - tasks.add(new CoffeeMakingTask(2)); - tasks.add(new CoffeeMakingTask(7)); - tasks.add(new PotatoPeelingTask(4)); - tasks.add(new PotatoPeelingTask(5)); + List tasks = List.of( + new PotatoPeelingTask(3), + new PotatoPeelingTask(6), + new CoffeeMakingTask(2), + new CoffeeMakingTask(6), + new PotatoPeelingTask(4), + new CoffeeMakingTask(2), + new PotatoPeelingTask(4), + new CoffeeMakingTask(9), + new PotatoPeelingTask(3), + new CoffeeMakingTask(2), + new PotatoPeelingTask(4), + new CoffeeMakingTask(2), + new CoffeeMakingTask(7), + new PotatoPeelingTask(4), + new PotatoPeelingTask(5)); // Creates a thread pool that reuses a fixed number of threads operating off a shared // unbounded queue. At any point, at most nThreads threads will be active processing diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java index 04ca5ffcce4f..2e69e2c7f2e9 100644 --- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java +++ b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java @@ -23,8 +23,10 @@ package com.iluwatar.tls; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -32,9 +34,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -82,7 +81,7 @@ public class DateFormatCallableTest { /** * Expected content of the list containing the date values created by the run of DateFormatRunnalbe */ - List expectedDateValues = Arrays.asList("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015"); + List expectedDateValues = List.of("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015"); /** * Run Callable and prepare results for usage in the test methods diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java index 2c88fc13d9e0..df2ab2a93419 100644 --- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java +++ b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java @@ -23,16 +23,15 @@ package com.iluwatar.tls; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -76,7 +75,7 @@ public class DateFormatCallableTestIncorrectDateFormat { /** * Expected content of the list containing the exceptions created by the run of DateFormatRunnalbe */ - List expectedExceptions = Arrays.asList("class java.text.ParseException: Unparseable date: \"15.12.2015\"", + List expectedExceptions = List.of("class java.text.ParseException: Unparseable date: \"15.12.2015\"", "class java.text.ParseException: Unparseable date: \"15.12.2015\"", "class java.text.ParseException: Unparseable date: \"15.12.2015\"", "class java.text.ParseException: Unparseable date: \"15.12.2015\"", diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java index 11e8eef5bc2a..1001e1bdf59b 100644 --- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java +++ b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java @@ -23,8 +23,10 @@ package com.iluwatar.tls; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -32,9 +34,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -86,7 +85,7 @@ static class StringArrayList extends ArrayList { /** * Expected content of the list containing the date values created by each thread */ - List expectedDateValues = Arrays.asList("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015"); + List expectedDateValues = List.of("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015"); /** * Run Callable and prepare results for usage in the test methods