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
This commit is contained in:
Leon Mak 2019-10-29 14:37:40 +08:00 committed by Ilkka Seppälä
parent dd971d8c19
commit c8a481bb77
37 changed files with 176 additions and 257 deletions

View File

@ -25,7 +25,6 @@ package com.iluwatar.abstractdocument;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

View File

@ -28,7 +28,6 @@ import com.iluwatar.abstractdocument.domain.Part;
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 class DomainTest {
Map<String, Object> 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());

View File

@ -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
@ -68,10 +67,10 @@ public class App {
Person john = new Person(cars);
List<Car> sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
List<Car> sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
LOGGER.info(sedansOwnedImperative.toString());
List<Car> sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
List<Car> sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
LOGGER.info(sedansOwnedFunctional.toString());
}
}

View File

@ -23,7 +23,6 @@
package com.iluwatar.collectionpipeline;
import java.util.Arrays;
import java.util.List;
/**
@ -38,7 +37,7 @@ public class CarFactory {
* @return {@link List} of {@link Car}
*/
public static List<Car> 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),

View File

@ -43,7 +43,7 @@ public abstract class Service {
public ArrayList<Exception> exceptionsList;
private static final Random RANDOM = new Random();
private static final String ALL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
private static final Hashtable<String, Boolean> USED_IDS = new Hashtable<String, Boolean>();
private static final Hashtable<String, Boolean> USED_IDS = new Hashtable<>();
protected Service(Database db, Exception...exc) {
this.database = db;

View File

@ -45,9 +45,9 @@ class RetryTest {
Retry.HandleErrorIssue<Order> handleError = (o,e) -> {
return;
};
Retry<Order> r1 = new Retry<Order>(op, handleError, 3, 30000,
Retry<Order> r1 = new Retry<>(op, handleError, 3, 30000,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
Retry<Order> r2 = new Retry<Order>(op, handleError, 3, 30000,
Retry<Order> 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);

View File

@ -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<Integer> 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);

View File

@ -25,21 +25,14 @@ package com.iluwatar.fluentinterface.fluentiterable;
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<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final Optional<Integer> first = createFluentIterable(integers).first();
assertNotNull(first);
assertTrue(first.isPresent());
@ -75,7 +68,7 @@ public abstract class FluentIterableTest {
@Test
public void testFirstCount() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> first4 = createFluentIterable(integers)
.first(4)
.asList();
@ -91,7 +84,7 @@ public abstract class FluentIterableTest {
@Test
public void testFirstCountLessItems() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Integer> first4 = createFluentIterable(integers)
.first(4)
.asList();
@ -106,7 +99,7 @@ public abstract class FluentIterableTest {
@Test
public void testLast() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final Optional<Integer> last = createFluentIterable(integers).last();
assertNotNull(last);
assertTrue(last.isPresent());
@ -123,7 +116,7 @@ public abstract class FluentIterableTest {
@Test
public void testLastCount() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> last4 = createFluentIterable(integers)
.last(4)
.asList();
@ -138,7 +131,7 @@ public abstract class FluentIterableTest {
@Test
public void testLastCountLessItems() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Integer> last4 = createFluentIterable(integers)
.last(4)
.asList();
@ -153,7 +146,7 @@ public abstract class FluentIterableTest {
@Test
public void testFilter() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> evenItems = createFluentIterable(integers)
.filter(i -> i % 2 == 0)
.asList();
@ -167,7 +160,7 @@ public abstract class FluentIterableTest {
@Test
public void testMap() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Long> longs = createFluentIterable(integers)
.map(Integer::longValue)
.asList();
@ -181,7 +174,7 @@ public abstract class FluentIterableTest {
@Test
public void testForEach() {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final Consumer<Integer> consumer = mock(Consumer.class);
createFluentIterable(integers).forEach(consumer);
@ -195,7 +188,7 @@ public abstract class FluentIterableTest {
@Test
public void testSpliterator() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final Spliterator<Integer> split = createFluentIterable(integers).spliterator();
assertNotNull(split);
}

View File

@ -25,14 +25,9 @@ package com.iluwatar.hexagonal.domain;
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 @@ class LotteryNumbersTest {
@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 @@ class LotteryNumbersTest {
@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);
}
}

View File

@ -35,9 +35,7 @@ import org.junit.jupiter.api.Test;
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.*;
/**
*

View File

@ -25,8 +25,6 @@ package com.iluwatar.hexagonal.domain;
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;

View File

@ -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

View File

@ -23,7 +23,7 @@
package com.iluwatar.layers;
import java.util.Arrays;
import java.util.List;
/**
*
@ -99,15 +99,17 @@ public class App {
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 CakeInfo(new CakeToppingInfo("cherry", 0), List.of(
new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo(
"strawberry", 0)));
try {

View File

@ -25,15 +25,10 @@ package com.iluwatar.layers;
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 class CakeBakingServiceImplTest {
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<CakeInfo> allCakes = service.getAllCakes();
@ -136,7 +131,7 @@ public class CakeBakingServiceImplTest {
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 class CakeBakingServiceImplTest {
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 class CakeBakingServiceImplTest {
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)));
});

View File

@ -32,7 +32,6 @@ import org.junit.jupiter.params.ParameterizedTest;
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 @@ import static org.mockito.Mockito.verify;
public class PartyMemberTest {
static Collection<Supplier<PartyMember>[]> dataProvider() {
return Arrays.asList(
return List.of(
new Supplier[]{Hobbit::new},
new Supplier[]{Hunter::new},
new Supplier[]{Rogue::new},

View File

@ -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,7 +38,7 @@ import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
*/
public class RecreateSimpleObjects extends FixtureScript {
public final List<String> names = Collections.unmodifiableList(Arrays.asList("Foo", "Bar", "Baz",
public final List<String> names = Collections.unmodifiableList(List.of("Foo", "Bar", "Baz",
"Frodo", "Froyo", "Fizz", "Bip", "Bop", "Bang", "Boo"));
// region > number (optional input)

View File

@ -25,15 +25,10 @@ package com.iluwatar.object.pool;
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 class OliphauntPoolTest {
// 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<Oliphaunt> oliphaunts = Arrays.asList(pool.checkOut(), pool.checkOut());
final List<Oliphaunt> oliphaunts = List.of(pool.checkOut(), pool.checkOut());
assertEquals(pool.toString(), "Pool available=0 inUse=2");
assertTrue(oliphaunts.contains(firstOliphaunt));
assertTrue(oliphaunts.contains(secondOliphaunt));

View File

@ -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<Hobbits> {
@Override
public Collection<Object[]> dataProvider() {
final List<Object[]> 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."});
}
/**

View File

@ -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<Orcs> {
@Override
public Collection<Object[]> dataProvider() {
final List<Object[]> 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."});
}
/**

View File

@ -25,7 +25,6 @@ package com.iluwatar.observer.generic;
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<GHobbits> {
@Override
public Collection<Object[]> dataProvider() {
final List<Object[]> 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."}
);
}
/**

View File

@ -25,7 +25,6 @@ package com.iluwatar.observer.generic;
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<GOrcs> {
@Override
public Collection<Object[]> dataProvider() {
final List<Object[]> 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."}
);
}
/**

View File

@ -26,7 +26,6 @@ package com.iluwatar.partialresponse;
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<Integer, Video> 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<Integer, Video> 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);

View File

@ -29,7 +29,6 @@ import org.junit.runner.RunWith;
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<Integer, Video> 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<Integer, Video> 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);
}

View File

@ -26,13 +26,10 @@ package com.iluwatar.prototype;
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 @@ import static org.junit.jupiter.api.Assertions.assertSame;
*/
public class PrototypeTest<P extends Prototype> {
static Collection<Object[]> 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"},

View File

@ -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.junit.jupiter.api.extension.ExtendWith;
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<Person> persons = Arrays.asList(peter, nasta, john, terry);
List<Person> persons = List.of(peter, nasta, john, terry);
/**
* Prepare data for test

View File

@ -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.junit.jupiter.api.extension.ExtendWith;
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<Person> persons = Arrays.asList(peter, nasta, john, terry);
List<Person> persons = List.of(peter, nasta, john, terry);
/**
* Prepare data for test

View File

@ -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<String> {
*/
public FindCustomer(String customerId, BusinessException... errors) {
this.customerId = customerId;
this.errors = new ArrayDeque<>(Arrays.asList(errors));
this.errors = new ArrayDeque<>(List.of(errors));
}
@Override

View File

@ -26,7 +26,6 @@ package com.iluwatar.servant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@ -60,9 +59,7 @@ public class App {
King k = new King();
Queen q = new Queen();
List<Royalty> guests = new ArrayList<>();
guests.add(k);
guests.add(q);
List<Royalty> guests = List.of(k, q);
// feed
servant.feed(k);

View File

@ -25,7 +25,6 @@ package com.iluwatar.servant;
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 class ServantTest {
final Royalty badMoodRoyalty = mock(Royalty.class);
when(badMoodRoyalty.getMood()).thenReturn(true);
final List<Royalty> goodCompany = new ArrayList<>();
goodCompany.add(goodMoodRoyalty);
goodCompany.add(goodMoodRoyalty);
goodCompany.add(goodMoodRoyalty);
final List<Royalty> goodCompany = List.of(goodMoodRoyalty, goodMoodRoyalty, goodMoodRoyalty);
final List<Royalty> badCompany = new ArrayList<>();
goodCompany.add(goodMoodRoyalty);
goodCompany.add(goodMoodRoyalty);
goodCompany.add(badMoodRoyalty);
final List<Royalty> badCompany = List.of(goodMoodRoyalty, goodMoodRoyalty, badMoodRoyalty);
assertTrue(new Servant("test").checkIfYouWillBeHanged(goodCompany));
assertTrue(new Servant("test").checkIfYouWillBeHanged(badCompany));

View File

@ -97,11 +97,10 @@ public class MagicServiceImplTest {
public void testFindWizardsWithSpellbook() throws Exception {
final String bookname = "bookname";
final Spellbook spellbook = mock(Spellbook.class);
final Set<Wizard> wizards = new HashSet<>();
wizards.add(mock(Wizard.class));
wizards.add(mock(Wizard.class));
wizards.add(mock(Wizard.class));
final Set<Wizard> 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 class MagicServiceImplTest {
@Test
public void testFindWizardsWithSpell() throws Exception {
final Set<Wizard> wizards = new HashSet<>();
wizards.add(mock(Wizard.class));
wizards.add(mock(Wizard.class));
wizards.add(mock(Wizard.class));
final Set<Wizard> wizards = Set.of(
mock(Wizard.class),
mock(Wizard.class),
mock(Wizard.class));
final Spellbook spellbook = mock(Spellbook.class);
when(spellbook.getWizards()).thenReturn(wizards);

View File

@ -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 com.iluwatar.specification.selector.MovementSelector;
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<Creature> 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<Creature> walkingCreatures =

View File

@ -29,8 +29,8 @@ import com.iluwatar.specification.property.Size;
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<Object[]> 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 class CreatureTest {
@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(

View File

@ -32,7 +32,6 @@ import org.junit.jupiter.params.ParameterizedTest;
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 DragonSlayingStrategyTest {
* @return The test parameters for each cycle
*/
static Collection<Object[]> dataProvider() {
return Arrays.asList(
return List.of(
new Object[]{
new MeleeStrategy(),
"With your Excalibur you sever the dragon's head!"

View File

@ -60,22 +60,22 @@ public class App {
LOGGER.info("Program started");
// Create a list of tasks to be executed
List<Task> 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<Task> 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

View File

@ -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.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;
@ -82,7 +81,7 @@ public class DateFormatCallableTest {
/**
* Expected content of the list containing the date values created by the run of DateFormatRunnalbe
*/
List<String> expectedDateValues = Arrays.asList("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015");
List<String> 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

View File

@ -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<String> expectedExceptions = Arrays.asList("class java.text.ParseException: Unparseable date: \"15.12.2015\"",
List<String> 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\"",

View File

@ -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.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;
@ -86,7 +85,7 @@ public class DateFormatCallableTestMultiThread {
/**
* Expected content of the list containing the date values created by each thread
*/
List<String> expectedDateValues = Arrays.asList("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015");
List<String> 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