Java 11 migrate 7 remaining f (#1115)
* Moves facade to Java 11 * Moves factory-kit to Java 11 * Moves factory-method to Java 11 * Moves feature-toggle to Java 11 * Moves fluentinterface to Java 11 * Moves flux to Java 11 * Moves flyweight to Java 11 * Moves front-controller to Java 11 * Uses stream properly * Resolves issues with ci
This commit is contained in:
committed by
Ilkka Seppälä
parent
f835d3d516
commit
670c4e43f3
@ -47,7 +47,7 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
FrontController controller = new FrontController();
|
||||
var controller = new FrontController();
|
||||
controller.handleRequest("Archer");
|
||||
controller.handleRequest("Catapult");
|
||||
controller.handleRequest("foobar");
|
||||
|
@ -30,12 +30,12 @@ package com.iluwatar.front.controller;
|
||||
public class FrontController {
|
||||
|
||||
public void handleRequest(String request) {
|
||||
Command command = getCommand(request);
|
||||
var command = getCommand(request);
|
||||
command.process();
|
||||
}
|
||||
|
||||
private Command getCommand(String request) {
|
||||
Class<?> commandClass = getCommandClass(request);
|
||||
var commandClass = getCommandClass(request);
|
||||
try {
|
||||
return (Command) commandClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
@ -44,12 +44,10 @@ public class FrontController {
|
||||
}
|
||||
|
||||
private static Class<?> getCommandClass(String request) {
|
||||
Class<?> result;
|
||||
try {
|
||||
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
|
||||
return Class.forName("com.iluwatar.front.controller." + request + "Command");
|
||||
} catch (ClassNotFoundException e) {
|
||||
result = UnknownCommand.class;
|
||||
return UnknownCommand.class;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -26,15 +26,12 @@ package com.iluwatar.front.controller;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class ApplicationExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testCause() {
|
||||
final Exception cause = new Exception();
|
||||
final var cause = new Exception();
|
||||
assertSame(cause, new ApplicationException(cause).getCause());
|
||||
}
|
||||
|
||||
|
@ -23,17 +23,15 @@
|
||||
|
||||
package com.iluwatar.front.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.front.controller.utils.InMemoryAppender;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/13/15 - 1:39 PM
|
||||
*
|
||||
@ -54,11 +52,11 @@ public class CommandTest {
|
||||
}
|
||||
|
||||
static List<Object[]> dataProvider() {
|
||||
final List<Object[]> parameters = new ArrayList<>();
|
||||
parameters.add(new Object[]{"Archer", "Displaying archers"});
|
||||
parameters.add(new Object[]{"Catapult", "Displaying catapults"});
|
||||
parameters.add(new Object[]{"NonExistentCommand", "Error 500"});
|
||||
return parameters;
|
||||
return List.of(
|
||||
new Object[]{"Archer", "Displaying archers"},
|
||||
new Object[]{"Catapult", "Displaying catapults"},
|
||||
new Object[]{"NonExistentCommand", "Error 500"}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +66,7 @@ public class CommandTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource("dataProvider")
|
||||
public void testDisplay(String request, String displayMessage) {
|
||||
final FrontController frontController = new FrontController();
|
||||
final var frontController = new FrontController();
|
||||
assertEquals(0, appender.getLogSize());
|
||||
frontController.handleRequest(request);
|
||||
assertEquals(displayMessage, appender.getLastMessage());
|
||||
|
@ -23,17 +23,15 @@
|
||||
|
||||
package com.iluwatar.front.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.front.controller.utils.InMemoryAppender;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/13/15 - 1:39 PM
|
||||
*
|
||||
@ -54,11 +52,11 @@ public class FrontControllerTest {
|
||||
}
|
||||
|
||||
static List<Object[]> dataProvider() {
|
||||
final List<Object[]> parameters = new ArrayList<>();
|
||||
parameters.add(new Object[]{new ArcherCommand(), "Displaying archers"});
|
||||
parameters.add(new Object[]{new CatapultCommand(), "Displaying catapults"});
|
||||
parameters.add(new Object[]{new UnknownCommand(), "Error 500"});
|
||||
return parameters;
|
||||
return List.of(
|
||||
new Object[]{new ArcherCommand(), "Displaying archers"},
|
||||
new Object[]{new CatapultCommand(), "Displaying catapults"},
|
||||
new Object[]{new UnknownCommand(), "Error 500"}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,17 +23,15 @@
|
||||
|
||||
package com.iluwatar.front.controller;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.front.controller.utils.InMemoryAppender;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/13/15 - 1:39 PM
|
||||
*
|
||||
@ -54,11 +52,11 @@ public class ViewTest {
|
||||
}
|
||||
|
||||
static List<Object[]> dataProvider() {
|
||||
final List<Object[]> parameters = new ArrayList<>();
|
||||
parameters.add(new Object[]{new ArcherView(), "Displaying archers"});
|
||||
parameters.add(new Object[]{new CatapultView(), "Displaying catapults"});
|
||||
parameters.add(new Object[]{new ErrorView(), "Error 500"});
|
||||
return parameters;
|
||||
return List.of(
|
||||
new Object[]{new ArcherView(), "Displaying archers"},
|
||||
new Object[]{new CatapultView(), "Displaying catapults"},
|
||||
new Object[]{new ErrorView(), "Error 500"}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user