Add java 11 (#1048)

This commit is contained in:
Leon Mak
2019-10-28 04:05:10 +08:00
committed by Ilkka Seppälä
parent b50189e283
commit 63fb8dc318
11 changed files with 119 additions and 145 deletions

View File

@ -23,17 +23,15 @@
package com.iluwatar.collectionpipeline;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests that Collection Pipeline methods work as expected.
*/
@ -44,27 +42,27 @@ public class AppTest {
@Test
public void testGetModelsAfter2000UsingFor() {
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
var models = ImperativeProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}
@Test
public void testGetModelsAfter2000UsingPipeline() {
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
var models = FunctionalProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}
@Test
public void testGetGroupingOfCarsByCategory() {
Map<Category, List<Car>> modelsExpected = new HashMap<>();
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN)));
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
var modelsExpected = Map.of(
Category.CONVERTIBLE, List.of(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)),
Category.SEDAN, List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN)),
Category.JEEP, List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
var modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
var modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
LOGGER.info("Category " + modelsFunctional);
assertEquals(modelsExpected, modelsFunctional);
assertEquals(modelsExpected, modelsImperative);
@ -72,11 +70,11 @@ public class AppTest {
@Test
public void testGetSedanCarsOwnedSortedByDate() {
Person john = new Person(cars);
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
var john = new Person(cars);
var modelsExpected = List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN));
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
var modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
var modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
assertEquals(modelsExpected, modelsFunctional);
assertEquals(modelsExpected, modelsImperative);
}