* See if the workers are doing what's expected from them on each step.
*/
@Test
public void testFullWorkDay() {
- final DwarvenGoldmineFacade goldMine = new DwarvenGoldmineFacade();
+ final var goldMine = new DwarvenGoldmineFacade();
goldMine.startNewDay();
// On the start of a day, all workers should wake up ...
@@ -128,7 +127,9 @@ public int getLogSize() {
}
public boolean logContains(String message) {
- return log.stream().anyMatch(event -> event.getFormattedMessage().equals(message));
+ return log.stream()
+ .map(ILoggingEvent::getFormattedMessage)
+ .anyMatch(message::equals);
}
}
diff --git a/factory-kit/pom.xml b/factory-kit/pom.xml
index 194f94d5d926..87f27b341bc4 100644
--- a/factory-kit/pom.xml
+++ b/factory-kit/pom.xml
@@ -40,4 +40,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.factorykit.App
+
+
+
+
+
+
+
+
diff --git a/factory-kit/src/main/java/com/iluwatar/factorykit/App.java b/factory-kit/src/main/java/com/iluwatar/factorykit/App.java
index f767fb689359..a47ee38226cc 100644
--- a/factory-kit/src/main/java/com/iluwatar/factorykit/App.java
+++ b/factory-kit/src/main/java/com/iluwatar/factorykit/App.java
@@ -48,13 +48,13 @@ public class App {
* @param args command line args
*/
public static void main(String[] args) {
- WeaponFactory factory = WeaponFactory.factory(builder -> {
+ var factory = WeaponFactory.factory(builder -> {
builder.add(WeaponType.SWORD, Sword::new);
builder.add(WeaponType.AXE, Axe::new);
builder.add(WeaponType.SPEAR, Spear::new);
builder.add(WeaponType.BOW, Bow::new);
});
- Weapon axe = factory.create(WeaponType.AXE);
+ var axe = factory.create(WeaponType.AXE);
LOGGER.info(axe.toString());
}
}
diff --git a/factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java b/factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java
index 2bdde87f7545..cf520dc0563b 100644
--- a/factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java
+++ b/factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java
@@ -24,7 +24,6 @@
package com.iluwatar.factorykit;
import java.util.HashMap;
-import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -52,7 +51,7 @@ public interface WeaponFactory {
* @return factory with specified {@link Builder}s
*/
static WeaponFactory factory(Consumer consumer) {
- Map> map = new HashMap<>();
+ var map = new HashMap>();
consumer.accept(map::put);
return name -> map.get(name).get();
}
diff --git a/factory-kit/src/test/java/com/iluwatar/factorykit/app/AppTest.java b/factory-kit/src/test/java/com/iluwatar/factorykit/app/AppTest.java
index 2d3481c4884d..f1d3c65a2f52 100644
--- a/factory-kit/src/test/java/com/iluwatar/factorykit/app/AppTest.java
+++ b/factory-kit/src/test/java/com/iluwatar/factorykit/app/AppTest.java
@@ -33,8 +33,7 @@ public class AppTest {
@Test
public void test() {
- String[] args = {};
- App.main(args);
+ App.main(new String[]{});
}
}
diff --git a/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java b/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java
index 9892e8497409..fd8241efe262 100644
--- a/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java
+++ b/factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java
@@ -23,6 +23,8 @@
package com.iluwatar.factorykit.factorykit;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import com.iluwatar.factorykit.Axe;
import com.iluwatar.factorykit.Spear;
import com.iluwatar.factorykit.Sword;
@@ -32,10 +34,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
- /**
- * Test Factory Kit Pattern
+/**
+ * Test Factory Kit Pattern
*/
public class FactoryKitTest {
@@ -51,30 +51,33 @@ public void init() {
}
/**
- * Testing {@link WeaponFactory} to produce a SPEAR asserting that the Weapon is an instance of {@link Spear}
+ * Testing {@link WeaponFactory} to produce a SPEAR asserting that the Weapon is an instance of
+ * {@link Spear}
*/
@Test
public void testSpearWeapon() {
- Weapon weapon = factory.create(WeaponType.SPEAR);
+ var weapon = factory.create(WeaponType.SPEAR);
verifyWeapon(weapon, Spear.class);
}
/**
- * Testing {@link WeaponFactory} to produce a AXE asserting that the Weapon is an instance of {@link Axe}
+ * Testing {@link WeaponFactory} to produce a AXE asserting that the Weapon is an instance of
+ * {@link Axe}
*/
@Test
public void testAxeWeapon() {
- Weapon weapon = factory.create(WeaponType.AXE);
+ var weapon = factory.create(WeaponType.AXE);
verifyWeapon(weapon, Axe.class);
}
/**
- * Testing {@link WeaponFactory} to produce a SWORD asserting that the Weapon is an instance of {@link Sword}
+ * Testing {@link WeaponFactory} to produce a SWORD asserting that the Weapon is an instance of
+ * {@link Sword}
*/
@Test
public void testWeapon() {
- Weapon weapon = factory.create(WeaponType.SWORD);
+ var weapon = factory.create(WeaponType.SWORD);
verifyWeapon(weapon, Sword.class);
}
diff --git a/factory-method/README.md b/factory-method/README.md
index 18cbba2e4a35..48ba6649cbcd 100644
--- a/factory-method/README.md
+++ b/factory-method/README.md
@@ -55,7 +55,7 @@ public class OrcBlacksmith implements Blacksmith {
Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured
```java
-Blacksmith blacksmith = new ElfBlacksmith();
+var blacksmith = new ElfBlacksmith();
blacksmith.manufactureWeapon(WeaponType.SPEAR);
blacksmith.manufactureWeapon(WeaponType.AXE);
// Elvish weapons are created
diff --git a/factory-method/pom.xml b/factory-method/pom.xml
index 5b3b6c9cc5b1..5f0358d4dcc1 100644
--- a/factory-method/pom.xml
+++ b/factory-method/pom.xml
@@ -39,4 +39,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.factory.method.App
+
+
+
+
+
+
+
+
diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/App.java b/factory-method/src/main/java/com/iluwatar/factory/method/App.java
index 8ebf54b03965..1bfd824578eb 100644
--- a/factory-method/src/main/java/com/iluwatar/factory/method/App.java
+++ b/factory-method/src/main/java/com/iluwatar/factory/method/App.java
@@ -64,7 +64,7 @@ public App(Blacksmith blacksmith) {
*/
public static void main(String[] args) {
// Lets go to war with Orc weapons
- App app = new App(new OrcBlacksmith());
+ var app = new App(new OrcBlacksmith());
app.manufactureWeapons();
// Lets go to war with Elf weapons
@@ -73,8 +73,7 @@ public static void main(String[] args) {
}
private void manufactureWeapons() {
- Weapon weapon;
- weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
+ var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
LOGGER.info(weapon.toString());
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
LOGGER.info(weapon.toString());
diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java b/factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java
index 0da783a34352..b6f29e43a937 100644
--- a/factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java
+++ b/factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java
@@ -23,6 +23,7 @@
package com.iluwatar.factory.method;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -35,14 +36,12 @@ public class ElfBlacksmith implements Blacksmith {
static {
ELFARSENAL = new HashMap<>(WeaponType.values().length);
- for (WeaponType type : WeaponType.values()) {
- ELFARSENAL.put(type, new ElfWeapon(type));
- }
+ Arrays.stream(WeaponType.values()).forEach(type -> ELFARSENAL.put(type, new ElfWeapon(type)));
}
-
+
@Override
public Weapon manufactureWeapon(WeaponType weaponType) {
return ELFARSENAL.get(weaponType);
}
-
+
}
diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java b/factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java
index 376b2ec34283..b048300855df 100644
--- a/factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java
+++ b/factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java
@@ -23,6 +23,7 @@
package com.iluwatar.factory.method;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -35,9 +36,7 @@ public class OrcBlacksmith implements Blacksmith {
static {
ORCARSENAL = new HashMap<>(WeaponType.values().length);
- for (WeaponType type : WeaponType.values()) {
- ORCARSENAL.put(type, new OrcWeapon(type));
- }
+ Arrays.stream(WeaponType.values()).forEach(type -> ORCARSENAL.put(type, new OrcWeapon(type)));
}
@Override
diff --git a/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java b/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java
index eb71fb167249..c23295d9a0ff 100644
--- a/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java
+++ b/factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java
@@ -25,15 +25,12 @@
import org.junit.jupiter.api.Test;
-import java.io.IOException;
-
/**
* Tests that Factory Method example runs without errors.
*/
public class AppTest {
@Test
- public void test() throws IOException {
- String[] args = {};
- App.main(args);
+ public void test() {
+ App.main(new String[]{});
}
}
diff --git a/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java b/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java
index eab890002f24..68960204a2b3 100644
--- a/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java
+++ b/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java
@@ -23,79 +23,80 @@
package com.iluwatar.factory.method;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
/**
* The Factory Method is a creational design pattern which uses factory methods to deal with the
* problem of creating objects without specifying the exact class of object that will be created.
* This is done by creating objects via calling a factory method either specified in an interface
* and implemented by child classes, or implemented in a base class and optionally overridden by
* derived classes—rather than by calling a constructor.
- *
- *
Factory produces the object of its liking.
- * The weapon {@link Weapon} manufactured by the
- * blacksmith depends on the kind of factory implementation it is referring to.
+ *
+ *
Factory produces the object of its liking.
+ * The weapon {@link Weapon} manufactured by the blacksmith depends on the kind of factory
+ * implementation it is referring to.
*
*/
public class FactoryMethodTest {
/**
- * Testing {@link OrcBlacksmith} to produce a SPEAR asserting that the Weapon is an instance
- * of {@link OrcWeapon}.
+ * Testing {@link OrcBlacksmith} to produce a SPEAR asserting that the Weapon is an instance of
+ * {@link OrcWeapon}.
*/
@Test
public void testOrcBlacksmithWithSpear() {
- Blacksmith blacksmith = new OrcBlacksmith();
- Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
+ var blacksmith = new OrcBlacksmith();
+ var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
verifyWeapon(weapon, WeaponType.SPEAR, OrcWeapon.class);
}
/**
- * Testing {@link OrcBlacksmith} to produce an AXE asserting that the Weapon is an instance
- * of {@link OrcWeapon}.
+ * Testing {@link OrcBlacksmith} to produce an AXE asserting that the Weapon is an instance of
+ * {@link OrcWeapon}.
*/
@Test
public void testOrcBlacksmithWithAxe() {
- Blacksmith blacksmith = new OrcBlacksmith();
- Weapon weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
+ var blacksmith = new OrcBlacksmith();
+ var weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
verifyWeapon(weapon, WeaponType.AXE, OrcWeapon.class);
}
/**
- * Testing {@link ElfBlacksmith} to produce a SHORT_SWORD asserting that the Weapon is an
- * instance of {@link ElfWeapon}.
+ * Testing {@link ElfBlacksmith} to produce a SHORT_SWORD asserting that the Weapon is an instance
+ * of {@link ElfWeapon}.
*/
@Test
public void testElfBlacksmithWithShortSword() {
- Blacksmith blacksmith = new ElfBlacksmith();
- Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
+ var blacksmith = new ElfBlacksmith();
+ var weapon = blacksmith.manufactureWeapon(WeaponType.SHORT_SWORD);
verifyWeapon(weapon, WeaponType.SHORT_SWORD, ElfWeapon.class);
}
/**
- * Testing {@link ElfBlacksmith} to produce a SPEAR asserting that the Weapon is an instance
- * of {@link ElfWeapon}.
+ * Testing {@link ElfBlacksmith} to produce a SPEAR asserting that the Weapon is an instance of
+ * {@link ElfWeapon}.
*/
@Test
public void testElfBlacksmithWithSpear() {
- Blacksmith blacksmith = new ElfBlacksmith();
- Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
+ var blacksmith = new ElfBlacksmith();
+ var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
verifyWeapon(weapon, WeaponType.SPEAR, ElfWeapon.class);
}
/**
* This method asserts that the weapon object that is passed is an instance of the clazz and the
* weapon is of type expectedWeaponType.
- *
- * @param weapon weapon object which is to be verified
+ *
+ * @param weapon weapon object which is to be verified
* @param expectedWeaponType expected WeaponType of the weapon
- * @param clazz expected class of the weapon
+ * @param clazz expected class of the weapon
*/
private void verifyWeapon(Weapon weapon, WeaponType expectedWeaponType, Class> clazz) {
assertTrue(clazz.isInstance(weapon), "Weapon must be an object of: " + clazz.getName());
- assertEquals(expectedWeaponType, weapon.getWeaponType(), "Weapon must be of weaponType: " + expectedWeaponType);
+ assertEquals(expectedWeaponType, weapon
+ .getWeaponType(), "Weapon must be of weaponType: " + expectedWeaponType);
}
}
diff --git a/feature-toggle/pom.xml b/feature-toggle/pom.xml
index 4ecd5f59df29..13f646b801a5 100644
--- a/feature-toggle/pom.xml
+++ b/feature-toggle/pom.xml
@@ -43,4 +43,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.featuretoggle.App
+
+
+
+
+
+
+
+
diff --git a/feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java b/feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java
index af8e731c8a98..ceb926b63f68 100644
--- a/feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java
+++ b/feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java
@@ -72,33 +72,33 @@ public class App {
*/
public static void main(String[] args) {
- final Properties properties = new Properties();
+ final var properties = new Properties();
properties.put("enhancedWelcome", true);
- Service service = new PropertiesFeatureToggleVersion(properties);
- final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
+ var service = new PropertiesFeatureToggleVersion(properties);
+ final var welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
LOGGER.info(welcomeMessage);
// ---------------------------------------------
- final Properties turnedOff = new Properties();
+ final var turnedOff = new Properties();
turnedOff.put("enhancedWelcome", false);
- Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
- final String welcomeMessageturnedOff =
+ var turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
+ final var welcomeMessageturnedOff =
turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
LOGGER.info(welcomeMessageturnedOff);
// --------------------------------------------
- Service service2 = new TieredFeatureToggleVersion();
+ var service2 = new TieredFeatureToggleVersion();
- final User paidUser = new User("Jamie Coder");
- final User freeUser = new User("Alan Defect");
+ final var paidUser = new User("Jamie Coder");
+ final var freeUser = new User("Alan Defect");
UserGroup.addUserToPaidGroup(paidUser);
UserGroup.addUserToFreeGroup(freeUser);
- final String welcomeMessagePaidUser = service2.getWelcomeMessage(paidUser);
- final String welcomeMessageFreeUser = service2.getWelcomeMessage(freeUser);
+ final var welcomeMessagePaidUser = service2.getWelcomeMessage(paidUser);
+ final var welcomeMessageFreeUser = service2.getWelcomeMessage(freeUser);
LOGGER.info(welcomeMessageFreeUser);
LOGGER.info(welcomeMessagePaidUser);
}
diff --git a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java
index 0bab8bca4ba2..69641a7ada37 100644
--- a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java
+++ b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java
@@ -23,17 +23,15 @@
package com.iluwatar.featuretoggle.pattern.propertiesversion;
-import com.iluwatar.featuretoggle.pattern.Service;
-import com.iluwatar.featuretoggle.user.User;
-import org.junit.jupiter.api.Test;
-
-import java.util.Properties;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import com.iluwatar.featuretoggle.user.User;
+import java.util.Properties;
+import org.junit.jupiter.api.Test;
+
/**
* Test Properties Toggle
*/
@@ -49,7 +47,7 @@ public void testNullPropertiesPassed() {
@Test
public void testNonBooleanProperty() {
assertThrows(IllegalArgumentException.class, () -> {
- final Properties properties = new Properties();
+ final var properties = new Properties();
properties.setProperty("enhancedWelcome", "Something");
new PropertiesFeatureToggleVersion(properties);
});
@@ -57,21 +55,21 @@ public void testNonBooleanProperty() {
@Test
public void testFeatureTurnedOn() {
- final Properties properties = new Properties();
+ final var properties = new Properties();
properties.put("enhancedWelcome", true);
- Service service = new PropertiesFeatureToggleVersion(properties);
+ var service = new PropertiesFeatureToggleVersion(properties);
assertTrue(service.isEnhanced());
- final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
+ final var welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
assertEquals("Welcome Jamie No Code. You're using the enhanced welcome message.", welcomeMessage);
}
@Test
public void testFeatureTurnedOff() {
- final Properties properties = new Properties();
+ final var properties = new Properties();
properties.put("enhancedWelcome", false);
- Service service = new PropertiesFeatureToggleVersion(properties);
+ var service = new PropertiesFeatureToggleVersion(properties);
assertFalse(service.isEnhanced());
- final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
+ final var welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
assertEquals("Welcome to the application.", welcomeMessage);
}
}
diff --git a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java
index 1d161c741a74..bb7195b7d2e6 100644
--- a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java
+++ b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java
@@ -23,15 +23,15 @@
package com.iluwatar.featuretoggle.pattern.tieredversion;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
/**
* Test Tiered Feature Toggle
*/
@@ -49,15 +49,15 @@ public void setUp() {
@Test
public void testGetWelcomeMessageForPaidUser() {
- final String welcomeMessage = service.getWelcomeMessage(paidUser);
- final String expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software.";
+ final var welcomeMessage = service.getWelcomeMessage(paidUser);
+ final var expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software.";
assertEquals(expected, welcomeMessage);
}
@Test
public void testGetWelcomeMessageForFreeUser() {
- final String welcomeMessage = service.getWelcomeMessage(freeUser);
- final String expected = "I suppose you can use this software.";
+ final var welcomeMessage = service.getWelcomeMessage(freeUser);
+ final var expected = "I suppose you can use this software.";
assertEquals(expected, welcomeMessage);
}
diff --git a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/user/UserGroupTest.java b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/user/UserGroupTest.java
index 9490b59a5967..9bc29fabfcf7 100644
--- a/feature-toggle/src/test/java/com/iluwatar/featuretoggle/user/UserGroupTest.java
+++ b/feature-toggle/src/test/java/com/iluwatar/featuretoggle/user/UserGroupTest.java
@@ -23,34 +23,34 @@
package com.iluwatar.featuretoggle.user;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
/**
* Test User Group specific feature
*/
public class UserGroupTest {
@Test
- public void testAddUserToFreeGroup() throws Exception {
- User user = new User("Free User");
+ public void testAddUserToFreeGroup() {
+ var user = new User("Free User");
UserGroup.addUserToFreeGroup(user);
assertFalse(UserGroup.isPaid(user));
}
@Test
- public void testAddUserToPaidGroup() throws Exception {
- User user = new User("Paid User");
+ public void testAddUserToPaidGroup() {
+ var user = new User("Paid User");
UserGroup.addUserToPaidGroup(user);
assertTrue(UserGroup.isPaid(user));
}
@Test
- public void testAddUserToPaidWhenOnFree() throws Exception {
- User user = new User("Paid User");
+ public void testAddUserToPaidWhenOnFree() {
+ var user = new User("Paid User");
UserGroup.addUserToFreeGroup(user);
assertThrows(IllegalArgumentException.class, () -> {
UserGroup.addUserToPaidGroup(user);
@@ -58,8 +58,8 @@ public void testAddUserToPaidWhenOnFree() throws Exception {
}
@Test
- public void testAddUserToFreeWhenOnPaid() throws Exception {
- User user = new User("Free User");
+ public void testAddUserToFreeWhenOnPaid() {
+ var user = new User("Free User");
UserGroup.addUserToPaidGroup(user);
assertThrows(IllegalArgumentException.class, () -> {
UserGroup.addUserToFreeGroup(user);
diff --git a/fluentinterface/pom.xml b/fluentinterface/pom.xml
index a40541fc4e2b..9eb063c132c5 100644
--- a/fluentinterface/pom.xml
+++ b/fluentinterface/pom.xml
@@ -46,4 +46,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.fluentinterface.app.App
+
+
+
+
+
+
+
+
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 b3f8fc0b6a32..547c657e4c53 100644
--- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java
+++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/app/App.java
@@ -28,8 +28,6 @@
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.StringJoiner;
import java.util.function.Function;
@@ -57,19 +55,23 @@ public class App {
*/
public static void main(String[] args) {
- List integerList = new ArrayList<>();
- integerList.addAll(List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2,
- -68, 45));
+ var integerList = List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2, -68);
prettyPrint("The initial list contains: ", integerList);
- List firstFiveNegatives =
- SimpleFluentIterable.fromCopyOf(integerList).filter(negatives()).first(3).asList();
+ var firstFiveNegatives = SimpleFluentIterable
+ .fromCopyOf(integerList)
+ .filter(negatives())
+ .first(3)
+ .asList();
prettyPrint("The first three negative values are: ", firstFiveNegatives);
- List lastTwoPositives =
- SimpleFluentIterable.fromCopyOf(integerList).filter(positives()).last(2).asList();
+ var lastTwoPositives = SimpleFluentIterable
+ .fromCopyOf(integerList)
+ .filter(positives())
+ .last(2)
+ .asList();
prettyPrint("The last two positive values are: ", lastTwoPositives);
SimpleFluentIterable
@@ -79,15 +81,21 @@ public static void main(String[] args) {
.ifPresent(evenNumber -> LOGGER.info("The first even number is: {}", evenNumber));
- List transformedList =
- SimpleFluentIterable.fromCopyOf(integerList).filter(negatives()).map(transformToString())
- .asList();
+ var transformedList = SimpleFluentIterable
+ .fromCopyOf(integerList)
+ .filter(negatives())
+ .map(transformToString())
+ .asList();
prettyPrint("A string-mapped list of negative numbers contains: ", transformedList);
- List lastTwoOfFirstFourStringMapped =
- LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2)
- .map(number -> "String[" + valueOf(number) + "]").asList();
+ var lastTwoOfFirstFourStringMapped = LazyFluentIterable
+ .from(integerList)
+ .filter(positives())
+ .first(4)
+ .last(2)
+ .map(number -> "String[" + valueOf(number) + "]")
+ .asList();
prettyPrint("The lazy list contains the last two of the first four positive numbers "
+ "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
@@ -96,12 +104,11 @@ public static void main(String[] args) {
.filter(negatives())
.first(2)
.last()
- .ifPresent(lastOfFirstTwo -> LOGGER
- .info("The last of the first two negatives is: {}", lastOfFirstTwo));
+ .ifPresent(number -> LOGGER.info("Last amongst first two negatives: {}", number));
}
private static Function transformToString() {
- return integer -> "String[" + valueOf(integer) + "]";
+ return integer -> "String[" + integer + "]";
}
private static Predicate super Integer> negatives() {
@@ -116,14 +123,12 @@ private static void prettyPrint(String prefix, Iterable iterable) {
prettyPrint(", ", prefix, iterable);
}
- private static void prettyPrint(String delimiter, String prefix,
- Iterable iterable) {
- StringJoiner joiner = new StringJoiner(delimiter, prefix, ".");
- Iterator iterator = iterable.iterator();
- while (iterator.hasNext()) {
- joiner.add(iterator.next().toString());
- }
-
+ private static void prettyPrint(
+ String delimiter, String prefix,
+ Iterable iterable
+ ) {
+ var joiner = new StringJoiner(delimiter, prefix, ".");
+ iterable.forEach(e -> joiner.add(e.toString()));
LOGGER.info(joiner.toString());
}
}
diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterable.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterable.java
index ea8d7c9bf1fb..2ffa4d3dd355 100644
--- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterable.java
+++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterable.java
@@ -24,7 +24,6 @@
package com.iluwatar.fluentinterface.fluentiterable;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@@ -102,11 +101,8 @@ public interface FluentIterable extends Iterable {
* @return a list with all objects of the given iterator
*/
static List copyToList(Iterable iterable) {
- List copy = new ArrayList<>();
- Iterator iterator = iterable.iterator();
- while (iterator.hasNext()) {
- copy.add(iterator.next());
- }
+ var copy = new ArrayList();
+ iterable.forEach(copy::add);
return copy;
}
}
diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/DecoratingIterator.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/DecoratingIterator.java
index 711b54fc9c1a..c0b52cec7e03 100644
--- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/DecoratingIterator.java
+++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/DecoratingIterator.java
@@ -65,7 +65,7 @@ public final E next() {
if (next == null) {
return fromIterator.next();
} else {
- final E result = next;
+ final var result = next;
next = null;
return result;
}
diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/LazyFluentIterable.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/LazyFluentIterable.java
index 82173c513189..f001c532f2c0 100644
--- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/LazyFluentIterable.java
+++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/lazy/LazyFluentIterable.java
@@ -67,14 +67,14 @@ protected LazyFluentIterable() {
*/
@Override
public FluentIterable filter(Predicate super E> predicate) {
- return new LazyFluentIterable() {
+ return new LazyFluentIterable<>() {
@Override
public Iterator iterator() {
return new DecoratingIterator(iterable.iterator()) {
@Override
public E computeNext() {
while (fromIterator.hasNext()) {
- E candidate = fromIterator.next();
+ var candidate = fromIterator.next();
if (predicate.test(candidate)) {
return candidate;
}
@@ -94,7 +94,7 @@ public E computeNext() {
*/
@Override
public Optional first() {
- Iterator resultIterator = first(1).iterator();
+ var resultIterator = first(1).iterator();
return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
}
@@ -116,7 +116,7 @@ public Iterator iterator() {
@Override
public E computeNext() {
if (currentIndex < count && fromIterator.hasNext()) {
- E candidate = fromIterator.next();
+ var candidate = fromIterator.next();
currentIndex++;
return candidate;
}
@@ -134,7 +134,7 @@ public E computeNext() {
*/
@Override
public Optional last() {
- Iterator resultIterator = last(1).iterator();
+ var resultIterator = last(1).iterator();
return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
}
@@ -162,25 +162,20 @@ public Iterator iterator() {
public E computeNext() {
initialize();
- E candidate = null;
while (currentIndex < stopIndex && fromIterator.hasNext()) {
currentIndex++;
fromIterator.next();
}
if (currentIndex >= stopIndex && fromIterator.hasNext()) {
- candidate = fromIterator.next();
+ return fromIterator.next();
}
- return candidate;
+ return null;
}
private void initialize() {
if (list == null) {
list = new ArrayList<>();
- Iterator newIterator = iterable.iterator();
- while (newIterator.hasNext()) {
- list.add(newIterator.next());
- }
-
+ iterable.forEach(list::add);
totalElementsCount = list.size();
stopIndex = totalElementsCount - count;
}
diff --git a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java
index 5165ca765e37..b6a0686532ec 100644
--- a/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java
+++ b/fluentinterface/src/main/java/com/iluwatar/fluentinterface/fluentiterable/simple/SimpleFluentIterable.java
@@ -62,9 +62,9 @@ protected SimpleFluentIterable(Iterable iterable) {
*/
@Override
public final FluentIterable filter(Predicate super E> predicate) {
- Iterator iterator = iterator();
+ var iterator = iterator();
while (iterator.hasNext()) {
- E nextElement = iterator.next();
+ var nextElement = iterator.next();
if (!predicate.test(nextElement)) {
iterator.remove();
}
@@ -79,7 +79,7 @@ public final FluentIterable filter(Predicate super E> predicate) {
*/
@Override
public final Optional first() {
- Iterator resultIterator = first(1).iterator();
+ var resultIterator = first(1).iterator();
return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
}
@@ -92,8 +92,8 @@ public final Optional first() {
*/
@Override
public final FluentIterable first(int count) {
- Iterator iterator = iterator();
- int currentCount = 0;
+ var iterator = iterator();
+ var currentCount = 0;
while (iterator.hasNext()) {
iterator.next();
if (currentCount >= count) {
@@ -111,7 +111,7 @@ public final FluentIterable first(int count) {
*/
@Override
public final Optional last() {
- List list = last(1).asList();
+ var list = last(1).asList();
if (list.isEmpty()) {
return Optional.empty();
}
@@ -127,9 +127,9 @@ public final Optional last() {
*/
@Override
public final FluentIterable last(int count) {
- int remainingElementsCount = getRemainingElementsCount();
- Iterator iterator = iterator();
- int currentIndex = 0;
+ var remainingElementsCount = getRemainingElementsCount();
+ var iterator = iterator();
+ var currentIndex = 0;
while (iterator.hasNext()) {
iterator.next();
if (currentIndex < remainingElementsCount - count) {
@@ -150,11 +150,8 @@ public final FluentIterable last(int count) {
*/
@Override
public final FluentIterable map(Function super E, T> function) {
- List temporaryList = new ArrayList<>();
- Iterator iterator = iterator();
- while (iterator.hasNext()) {
- temporaryList.add(function.apply(iterator.next()));
- }
+ var temporaryList = new ArrayList();
+ this.forEach(e -> temporaryList.add(function.apply(e)));
return from(temporaryList);
}
@@ -178,7 +175,7 @@ public static FluentIterable from(Iterable iterable) {
}
public static FluentIterable fromCopyOf(Iterable iterable) {
- List copy = FluentIterable.copyToList(iterable);
+ var copy = FluentIterable.copyToList(iterable);
return new SimpleFluentIterable<>(copy);
}
@@ -204,10 +201,8 @@ public Spliterator spliterator() {
* @return the count of remaining objects of the current Iterable
*/
public final int getRemainingElementsCount() {
- int counter = 0;
- Iterator iterator = iterator();
- while (iterator.hasNext()) {
- iterator.next();
+ var counter = 0;
+ for (var ignored : this) {
counter++;
}
return counter;
@@ -219,10 +214,8 @@ public final int getRemainingElementsCount() {
* @return a new List with the remaining objects.
*/
public static List toList(Iterator iterator) {
- List copy = new ArrayList<>();
- while (iterator.hasNext()) {
- copy.add(iterator.next());
- }
+ var copy = new ArrayList();
+ iterator.forEachRemaining(copy::add);
return copy;
}
}
diff --git a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/app/AppTest.java b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/app/AppTest.java
index f6543f46b3e5..6f25d841691d 100644
--- a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/app/AppTest.java
+++ b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/app/AppTest.java
@@ -32,7 +32,6 @@ public class AppTest {
@Test
public void test() {
- String[] args = {};
- App.main(args);
+ App.main(new String[]{});
}
}
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 4ee30d3e5734..2ae69eaf84d3 100644
--- a/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java
+++ b/fluentinterface/src/test/java/com/iluwatar/fluentinterface/fluentiterable/FluentIterableTest.java
@@ -23,16 +23,19 @@
package com.iluwatar.fluentinterface.fluentiterable;
-import org.junit.jupiter.api.Test;
+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 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.*;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.api.Test;
/**
* Date: 12/12/15 - 7:00 PM
@@ -50,28 +53,28 @@ public abstract class FluentIterableTest {
protected abstract FluentIterable createFluentIterable(final Iterable integers);
@Test
- public void testFirst() throws Exception {
- final List integers = List.of(1, 2, 3, 10, 9, 8);
- final Optional first = createFluentIterable(integers).first();
+ public void testFirst() {
+ final var integers = List.of(1, 2, 3, 10, 9, 8);
+ final var first = createFluentIterable(integers).first();
assertNotNull(first);
assertTrue(first.isPresent());
assertEquals(integers.get(0), first.get());
}
@Test
- public void testFirstEmptyCollection() throws Exception {
- final List integers = Collections.emptyList();
- final Optional first = createFluentIterable(integers).first();
+ public void testFirstEmptyCollection() {
+ final var integers = Collections.emptyList();
+ final var first = createFluentIterable(integers).first();
assertNotNull(first);
assertFalse(first.isPresent());
}
@Test
- public void testFirstCount() throws Exception {
- final List integers = List.of(1, 2, 3, 10, 9, 8);
- final List first4 = createFluentIterable(integers)
- .first(4)
- .asList();
+ public void testFirstCount() {
+ final var integers = List.of(1, 2, 3, 10, 9, 8);
+ final var first4 = createFluentIterable(integers)
+ .first(4)
+ .asList();
assertNotNull(first4);
assertEquals(4, first4.size());
@@ -83,11 +86,11 @@ public void testFirstCount() throws Exception {
}
@Test
- public void testFirstCountLessItems() throws Exception {
- final List integers = List.of(1, 2, 3);
- final List first4 = createFluentIterable(integers)
- .first(4)
- .asList();
+ public void testFirstCountLessItems() {
+ final var integers = List.of(1, 2, 3);
+ final var first4 = createFluentIterable(integers)
+ .first(4)
+ .asList();
assertNotNull(first4);
assertEquals(3, first4.size());
@@ -98,28 +101,28 @@ public void testFirstCountLessItems() throws Exception {
}
@Test
- public void testLast() throws Exception {
- final List integers = List.of(1, 2, 3, 10, 9, 8);
- final Optional last = createFluentIterable(integers).last();
+ public void testLast() {
+ final var integers = List.of(1, 2, 3, 10, 9, 8);
+ final var last = createFluentIterable(integers).last();
assertNotNull(last);
assertTrue(last.isPresent());
assertEquals(integers.get(integers.size() - 1), last.get());
}
@Test
- public void testLastEmptyCollection() throws Exception {
- final List integers = Collections.emptyList();
- final Optional last = createFluentIterable(integers).last();
+ public void testLastEmptyCollection() {
+ final var integers = Collections.emptyList();
+ final var last = createFluentIterable(integers).last();
assertNotNull(last);
assertFalse(last.isPresent());
}
@Test
- public void testLastCount() throws Exception {
- final List integers = List.of(1, 2, 3, 10, 9, 8);
- final List last4 = createFluentIterable(integers)
- .last(4)
- .asList();
+ public void testLastCount() {
+ final var integers = List.of(1, 2, 3, 10, 9, 8);
+ final var last4 = createFluentIterable(integers)
+ .last(4)
+ .asList();
assertNotNull(last4);
assertEquals(4, last4.size());
@@ -130,11 +133,11 @@ public void testLastCount() throws Exception {
}
@Test
- public void testLastCountLessItems() throws Exception {
- final List integers = List.of(1, 2, 3);
- final List last4 = createFluentIterable(integers)
- .last(4)
- .asList();
+ public void testLastCountLessItems() {
+ final var integers = List.of(1, 2, 3);
+ final var last4 = createFluentIterable(integers)
+ .last(4)
+ .asList();
assertNotNull(last4);
assertEquals(3, last4.size());
@@ -145,11 +148,11 @@ public void testLastCountLessItems() throws Exception {
}
@Test
- public void testFilter() throws Exception {
- final List integers = List.of(1, 2, 3, 10, 9, 8);
- final List evenItems = createFluentIterable(integers)
- .filter(i -> i % 2 == 0)
- .asList();
+ public void testFilter() {
+ final var integers = List.of(1, 2, 3, 10, 9, 8);
+ final var evenItems = createFluentIterable(integers)
+ .filter(i -> i % 2 == 0)
+ .asList();
assertNotNull(evenItems);
assertEquals(3, evenItems.size());
@@ -159,11 +162,11 @@ public void testFilter() throws Exception {
}
@Test
- public void testMap() throws Exception {
- final List integers = List.of(1, 2, 3);
- final List longs = createFluentIterable(integers)
- .map(Integer::longValue)
- .asList();
+ public void testMap() {
+ final var integers = List.of(1, 2, 3);
+ final var longs = createFluentIterable(integers)
+ .map(Integer::longValue)
+ .asList();
assertNotNull(longs);
assertEquals(integers.size(), longs.size());
@@ -174,7 +177,7 @@ public void testMap() throws Exception {
@Test
public void testForEach() {
- final List integers = List.of(1, 2, 3);
+ final var integers = List.of(1, 2, 3);
final Consumer consumer = mock(Consumer.class);
createFluentIterable(integers).forEach(consumer);
@@ -188,8 +191,8 @@ public void testForEach() {
@Test
public void testSpliterator() throws Exception {
- final List integers = List.of(1, 2, 3);
- final Spliterator split = createFluentIterable(integers).spliterator();
+ final var integers = List.of(1, 2, 3);
+ final var split = createFluentIterable(integers).spliterator();
assertNotNull(split);
}
diff --git a/flux/pom.xml b/flux/pom.xml
index 1c44d80574ec..8effd0fc941b 100644
--- a/flux/pom.xml
+++ b/flux/pom.xml
@@ -44,4 +44,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.flux.app.App
+
+
+
+
+
+
+
+
diff --git a/flux/src/main/java/com/iluwatar/flux/app/App.java b/flux/src/main/java/com/iluwatar/flux/app/App.java
index 13a16c977437..1344d9eaa101 100644
--- a/flux/src/main/java/com/iluwatar/flux/app/App.java
+++ b/flux/src/main/java/com/iluwatar/flux/app/App.java
@@ -54,13 +54,13 @@ public class App {
public static void main(String[] args) {
// initialize and wire the system
- MenuStore menuStore = new MenuStore();
+ var menuStore = new MenuStore();
Dispatcher.getInstance().registerStore(menuStore);
- ContentStore contentStore = new ContentStore();
+ var contentStore = new ContentStore();
Dispatcher.getInstance().registerStore(contentStore);
- MenuView menuView = new MenuView();
+ var menuView = new MenuView();
menuStore.registerView(menuView);
- ContentView contentView = new ContentView();
+ var contentView = new ContentView();
contentStore.registerView(contentView);
// render initial view
diff --git a/flux/src/main/java/com/iluwatar/flux/dispatcher/Dispatcher.java b/flux/src/main/java/com/iluwatar/flux/dispatcher/Dispatcher.java
index 206ef8b3fdd0..cf09ecf6866e 100644
--- a/flux/src/main/java/com/iluwatar/flux/dispatcher/Dispatcher.java
+++ b/flux/src/main/java/com/iluwatar/flux/dispatcher/Dispatcher.java
@@ -70,6 +70,6 @@ public void menuItemSelected(MenuItem menuItem) {
}
private void dispatchAction(Action action) {
- stores.stream().forEach(store -> store.onAction(action));
+ stores.forEach(store -> store.onAction(action));
}
}
diff --git a/flux/src/main/java/com/iluwatar/flux/store/ContentStore.java b/flux/src/main/java/com/iluwatar/flux/store/ContentStore.java
index be2a5e419bdb..60d3faea0e2e 100644
--- a/flux/src/main/java/com/iluwatar/flux/store/ContentStore.java
+++ b/flux/src/main/java/com/iluwatar/flux/store/ContentStore.java
@@ -38,7 +38,7 @@ public class ContentStore extends Store {
@Override
public void onAction(Action action) {
if (action.getType().equals(ActionType.CONTENT_CHANGED)) {
- ContentAction contentAction = (ContentAction) action;
+ var contentAction = (ContentAction) action;
content = contentAction.getContent();
notifyChange();
}
diff --git a/flux/src/main/java/com/iluwatar/flux/store/MenuStore.java b/flux/src/main/java/com/iluwatar/flux/store/MenuStore.java
index 4757a563e63f..819500c8a360 100644
--- a/flux/src/main/java/com/iluwatar/flux/store/MenuStore.java
+++ b/flux/src/main/java/com/iluwatar/flux/store/MenuStore.java
@@ -38,7 +38,7 @@ public class MenuStore extends Store {
@Override
public void onAction(Action action) {
if (action.getType().equals(ActionType.MENU_ITEM_SELECTED)) {
- MenuAction menuAction = (MenuAction) action;
+ var menuAction = (MenuAction) action;
selected = menuAction.getMenuItem();
notifyChange();
}
diff --git a/flux/src/main/java/com/iluwatar/flux/store/Store.java b/flux/src/main/java/com/iluwatar/flux/store/Store.java
index b0fc8bac0d23..cfbdf4af54ef 100644
--- a/flux/src/main/java/com/iluwatar/flux/store/Store.java
+++ b/flux/src/main/java/com/iluwatar/flux/store/Store.java
@@ -42,6 +42,6 @@ public void registerView(View view) {
}
protected void notifyChange() {
- views.stream().forEach(view -> view.storeChanged(this));
+ views.forEach(view -> view.storeChanged(this));
}
}
diff --git a/flux/src/main/java/com/iluwatar/flux/view/ContentView.java b/flux/src/main/java/com/iluwatar/flux/view/ContentView.java
index fc794d8dc6bf..b71a2c53ba38 100644
--- a/flux/src/main/java/com/iluwatar/flux/view/ContentView.java
+++ b/flux/src/main/java/com/iluwatar/flux/view/ContentView.java
@@ -40,7 +40,7 @@ public class ContentView implements View {
@Override
public void storeChanged(Store store) {
- ContentStore contentStore = (ContentStore) store;
+ var contentStore = (ContentStore) store;
content = contentStore.getContent();
render();
}
diff --git a/flux/src/main/java/com/iluwatar/flux/view/MenuView.java b/flux/src/main/java/com/iluwatar/flux/view/MenuView.java
index c09d146a9298..f4cdf7a4d7de 100644
--- a/flux/src/main/java/com/iluwatar/flux/view/MenuView.java
+++ b/flux/src/main/java/com/iluwatar/flux/view/MenuView.java
@@ -41,14 +41,14 @@ public class MenuView implements View {
@Override
public void storeChanged(Store store) {
- MenuStore menuStore = (MenuStore) store;
+ var menuStore = (MenuStore) store;
selected = menuStore.getSelected();
render();
}
@Override
public void render() {
- for (MenuItem item : MenuItem.values()) {
+ for (var item : MenuItem.values()) {
if (selected.equals(item)) {
LOGGER.info("* {}", item);
} else {
diff --git a/flux/src/test/java/com/iluwatar/flux/action/ContentTest.java b/flux/src/test/java/com/iluwatar/flux/action/ContentTest.java
index 3e047db216ca..f0f41f8ce0f7 100644
--- a/flux/src/test/java/com/iluwatar/flux/action/ContentTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/action/ContentTest.java
@@ -23,11 +23,11 @@
package com.iluwatar.flux.action;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import org.junit.jupiter.api.Test;
+
/**
* Date: 12/12/15 - 10:11 PM
*
@@ -36,9 +36,9 @@
public class ContentTest {
@Test
- public void testToString() throws Exception {
- for (final Content content : Content.values()) {
- final String toString = content.toString();
+ public void testToString() {
+ for (final var content : Content.values()) {
+ final var toString = content.toString();
assertNotNull(toString);
assertFalse(toString.trim().isEmpty());
}
diff --git a/flux/src/test/java/com/iluwatar/flux/action/MenuItemTest.java b/flux/src/test/java/com/iluwatar/flux/action/MenuItemTest.java
index 272c3a31b7c0..374f27daaa4c 100644
--- a/flux/src/test/java/com/iluwatar/flux/action/MenuItemTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/action/MenuItemTest.java
@@ -23,11 +23,11 @@
package com.iluwatar.flux.action;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import org.junit.jupiter.api.Test;
+
/**
* Date: 12/12/15 - 10:15 PM
*
@@ -36,9 +36,9 @@
public class MenuItemTest {
@Test
- public void testToString() throws Exception {
- for (final MenuItem menuItem : MenuItem.values()) {
- final String toString = menuItem.toString();
+ public void testToString() {
+ for (final var menuItem : MenuItem.values()) {
+ final var toString = menuItem.toString();
assertNotNull(toString);
assertFalse(toString.trim().isEmpty());
}
diff --git a/flux/src/test/java/com/iluwatar/flux/app/AppTest.java b/flux/src/test/java/com/iluwatar/flux/app/AppTest.java
index f4b58a9b11cb..8916ad4de856 100644
--- a/flux/src/test/java/com/iluwatar/flux/app/AppTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/app/AppTest.java
@@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;
/**
- *
* Application test
- *
*/
public class AppTest {
@Test
public void test() {
- String[] args = {};
- App.main(args);
+ App.main(new String[]{});
}
}
diff --git a/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java b/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java
index 33ee1b69d5c5..5212a57d8396 100644
--- a/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java
@@ -23,6 +23,14 @@
package com.iluwatar.flux.dispatcher;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+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 com.iluwatar.flux.action.Action;
import com.iluwatar.flux.action.ActionType;
import com.iluwatar.flux.action.Content;
@@ -30,23 +38,12 @@
import com.iluwatar.flux.action.MenuAction;
import com.iluwatar.flux.action.MenuItem;
import com.iluwatar.flux.store.Store;
+import java.util.List;
+import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
/**
* Date: 12/12/15 - 8:22 PM
*
@@ -61,53 +58,56 @@ public class DispatcherTest {
*/
@BeforeEach
public void setUp() throws Exception {
- final Constructor constructor;
- constructor = Dispatcher.class.getDeclaredConstructor();
+ final var constructor = Dispatcher.class.getDeclaredConstructor();
constructor.setAccessible(true);
- final Field field = Dispatcher.class.getDeclaredField("instance");
+ final var field = Dispatcher.class.getDeclaredField("instance");
field.setAccessible(true);
field.set(Dispatcher.getInstance(), constructor.newInstance());
}
@Test
- public void testGetInstance() throws Exception {
+ public void testGetInstance() {
assertNotNull(Dispatcher.getInstance());
assertSame(Dispatcher.getInstance(), Dispatcher.getInstance());
}
@Test
- public void testMenuItemSelected() throws Exception {
- final Dispatcher dispatcher = Dispatcher.getInstance();
+ public void testMenuItemSelected() {
+ final var dispatcher = Dispatcher.getInstance();
- final Store store = mock(Store.class);
+ final var store = mock(Store.class);
dispatcher.registerStore(store);
dispatcher.menuItemSelected(MenuItem.HOME);
dispatcher.menuItemSelected(MenuItem.COMPANY);
// We expect 4 events, 2 menu selections and 2 content change actions
- final ArgumentCaptor actionCaptor = ArgumentCaptor.forClass(Action.class);
+ final var actionCaptor = ArgumentCaptor.forClass(Action.class);
verify(store, times(4)).onAction(actionCaptor.capture());
verifyNoMoreInteractions(store);
- final List actions = actionCaptor.getAllValues();
- final List menuActions = actions.stream()
- .filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
- .map(a -> (MenuAction) a)
- .collect(Collectors.toList());
+ final var actions = actionCaptor.getAllValues();
+ final var menuActions = actions.stream()
+ .filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
+ .map(a -> (MenuAction) a)
+ .collect(Collectors.toList());
- final List contentActions = actions.stream()
- .filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
- .map(a -> (ContentAction) a)
- .collect(Collectors.toList());
+ final var contentActions = actions.stream()
+ .filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
+ .map(a -> (ContentAction) a)
+ .collect(Collectors.toList());
assertEquals(2, menuActions.size());
- assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals).count());
- assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.COMPANY::equals).count());
+ assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals)
+ .count());
+ assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem)
+ .filter(MenuItem.COMPANY::equals).count());
assertEquals(2, contentActions.size());
- assertEquals(1, contentActions.stream().map(ContentAction::getContent).filter(Content.PRODUCTS::equals).count());
- assertEquals(1, contentActions.stream().map(ContentAction::getContent).filter(Content.COMPANY::equals).count());
+ assertEquals(1, contentActions.stream().map(ContentAction::getContent)
+ .filter(Content.PRODUCTS::equals).count());
+ assertEquals(1, contentActions.stream().map(ContentAction::getContent)
+ .filter(Content.COMPANY::equals).count());
}
diff --git a/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java b/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java
index 5bb35a2f258c..cca59a5ab008 100644
--- a/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java
@@ -23,20 +23,20 @@
package com.iluwatar.flux.store;
-import com.iluwatar.flux.action.Content;
-import com.iluwatar.flux.action.ContentAction;
-import com.iluwatar.flux.action.MenuAction;
-import com.iluwatar.flux.action.MenuItem;
-import com.iluwatar.flux.view.View;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import com.iluwatar.flux.action.Content;
+import com.iluwatar.flux.action.ContentAction;
+import com.iluwatar.flux.action.MenuAction;
+import com.iluwatar.flux.action.MenuItem;
+import com.iluwatar.flux.view.View;
+import org.junit.jupiter.api.Test;
/**
* Date: 12/12/15 - 10:18 PM
@@ -46,10 +46,10 @@
public class ContentStoreTest {
@Test
- public void testOnAction() throws Exception {
- final ContentStore contentStore = new ContentStore();
+ public void testOnAction() {
+ final var contentStore = new ContentStore();
- final View view = mock(View.class);
+ final var view = mock(View.class);
contentStore.registerView(view);
verifyZeroInteractions(view);
diff --git a/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java b/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java
index 8085326c86a9..24a05f48659a 100644
--- a/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java
@@ -23,20 +23,20 @@
package com.iluwatar.flux.store;
-import com.iluwatar.flux.action.Content;
-import com.iluwatar.flux.action.ContentAction;
-import com.iluwatar.flux.action.MenuAction;
-import com.iluwatar.flux.action.MenuItem;
-import com.iluwatar.flux.view.View;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import com.iluwatar.flux.action.Content;
+import com.iluwatar.flux.action.ContentAction;
+import com.iluwatar.flux.action.MenuAction;
+import com.iluwatar.flux.action.MenuItem;
+import com.iluwatar.flux.view.View;
+import org.junit.jupiter.api.Test;
/**
* Date: 12/12/15 - 10:18 PM
@@ -46,10 +46,10 @@
public class MenuStoreTest {
@Test
- public void testOnAction() throws Exception {
- final MenuStore menuStore = new MenuStore();
+ public void testOnAction() {
+ final var menuStore = new MenuStore();
- final View view = mock(View.class);
+ final var view = mock(View.class);
menuStore.registerView(view);
verifyZeroInteractions(view);
diff --git a/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java b/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java
index fe6b46618a6d..15ffc48d0bbd 100644
--- a/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java
@@ -23,15 +23,15 @@
package com.iluwatar.flux.view;
-import com.iluwatar.flux.action.Content;
-import com.iluwatar.flux.store.ContentStore;
-import org.junit.jupiter.api.Test;
-
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import com.iluwatar.flux.action.Content;
+import com.iluwatar.flux.store.ContentStore;
+import org.junit.jupiter.api.Test;
/**
* Date: 12/12/15 - 10:31 PM
@@ -41,11 +41,11 @@
public class ContentViewTest {
@Test
- public void testStoreChanged() throws Exception {
- final ContentStore store = mock(ContentStore.class);
+ public void testStoreChanged() {
+ final var store = mock(ContentStore.class);
when(store.getContent()).thenReturn(Content.PRODUCTS);
- final ContentView view = new ContentView();
+ final var view = new ContentView();
view.storeChanged(store);
verify(store, times(1)).getContent();
diff --git a/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java b/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java
index 4383c0063fb6..2efe0ba025ae 100644
--- a/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java
+++ b/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java
@@ -23,13 +23,6 @@
package com.iluwatar.flux.view;
-import com.iluwatar.flux.action.Action;
-import com.iluwatar.flux.action.MenuItem;
-import com.iluwatar.flux.dispatcher.Dispatcher;
-import com.iluwatar.flux.store.MenuStore;
-import com.iluwatar.flux.store.Store;
-import org.junit.jupiter.api.Test;
-
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -37,6 +30,13 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import com.iluwatar.flux.action.Action;
+import com.iluwatar.flux.action.MenuItem;
+import com.iluwatar.flux.dispatcher.Dispatcher;
+import com.iluwatar.flux.store.MenuStore;
+import com.iluwatar.flux.store.Store;
+import org.junit.jupiter.api.Test;
+
/**
* Date: 12/12/15 - 10:31 PM
*
@@ -45,11 +45,11 @@
public class MenuViewTest {
@Test
- public void testStoreChanged() throws Exception {
- final MenuStore store = mock(MenuStore.class);
+ public void testStoreChanged() {
+ final var store = mock(MenuStore.class);
when(store.getSelected()).thenReturn(MenuItem.HOME);
- final MenuView view = new MenuView();
+ final var view = new MenuView();
view.storeChanged(store);
verify(store, times(1)).getSelected();
@@ -57,11 +57,11 @@ public void testStoreChanged() throws Exception {
}
@Test
- public void testItemClicked() throws Exception {
- final Store store = mock(Store.class);
+ public void testItemClicked() {
+ final var store = mock(Store.class);
Dispatcher.getInstance().registerStore(store);
- final MenuView view = new MenuView();
+ final var view = new MenuView();
view.itemClicked(MenuItem.PRODUCTS);
// We should receive a menu click action and a content changed action
diff --git a/flyweight/README.md b/flyweight/README.md
index 4847b828505b..a263cc438a7e 100644
--- a/flyweight/README.md
+++ b/flyweight/README.md
@@ -72,7 +72,7 @@ public class PotionFactory {
}
Potion createPotion(PotionType type) {
- Potion potion = potions.get(type);
+ var potion = potions.get(type);
if (potion == null) {
switch (type) {
case HEALING:
@@ -99,7 +99,7 @@ public class PotionFactory {
And it can be used as below
```java
-PotionFactory factory = new PotionFactory();
+var factory = new PotionFactory();
factory.createPotion(PotionType.INVISIBILITY).drink(); // You become invisible. (Potion=6566818)
factory.createPotion(PotionType.HEALING).drink(); // You feel healed. (Potion=648129364)
factory.createPotion(PotionType.INVISIBILITY).drink(); // You become invisible. (Potion=6566818)
diff --git a/flyweight/pom.xml b/flyweight/pom.xml
index a17b43dcd572..f3a8082b5afb 100644
--- a/flyweight/pom.xml
+++ b/flyweight/pom.xml
@@ -39,4 +39,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.flyweight.App
+
+
+
+
+
+
+
+
diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/AlchemistShop.java b/flyweight/src/main/java/com/iluwatar/flyweight/AlchemistShop.java
index e99cfc8078a8..4fa7312e56c1 100644
--- a/flyweight/src/main/java/com/iluwatar/flyweight/AlchemistShop.java
+++ b/flyweight/src/main/java/com/iluwatar/flyweight/AlchemistShop.java
@@ -23,7 +23,6 @@
package com.iluwatar.flyweight;
-import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +41,7 @@ public class AlchemistShop {
* Constructor.
*/
public AlchemistShop() {
- PotionFactory factory = new PotionFactory();
+ var factory = new PotionFactory();
topShelf = List.of(
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.INVISIBILITY),
@@ -68,7 +67,7 @@ public AlchemistShop() {
* @return The top shelf potions
*/
public final List getTopShelf() {
- return Collections.unmodifiableList(this.topShelf);
+ return List.copyOf(this.topShelf);
}
/**
@@ -77,24 +76,16 @@ public final List getTopShelf() {
* @return The bottom shelf potions
*/
public final List getBottomShelf() {
- return Collections.unmodifiableList(this.bottomShelf);
+ return List.copyOf(this.bottomShelf);
}
/**
* Enumerate potions.
*/
public void enumerate() {
-
LOGGER.info("Enumerating top shelf potions\n");
-
- for (Potion p : topShelf) {
- p.drink();
- }
-
+ topShelf.forEach(Potion::drink);
LOGGER.info("Enumerating bottom shelf potions\n");
-
- for (Potion p : bottomShelf) {
- p.drink();
- }
+ bottomShelf.forEach(Potion::drink);
}
}
diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/App.java b/flyweight/src/main/java/com/iluwatar/flyweight/App.java
index cbea6b9cc97b..8f5ff8742030 100644
--- a/flyweight/src/main/java/com/iluwatar/flyweight/App.java
+++ b/flyweight/src/main/java/com/iluwatar/flyweight/App.java
@@ -43,7 +43,7 @@ public class App {
* @param args command line args
*/
public static void main(String[] args) {
- AlchemistShop alchemistShop = new AlchemistShop();
+ var alchemistShop = new AlchemistShop();
alchemistShop.enumerate();
}
}
diff --git a/flyweight/src/main/java/com/iluwatar/flyweight/PotionFactory.java b/flyweight/src/main/java/com/iluwatar/flyweight/PotionFactory.java
index 19edf0e21502..a731c03590fb 100644
--- a/flyweight/src/main/java/com/iluwatar/flyweight/PotionFactory.java
+++ b/flyweight/src/main/java/com/iluwatar/flyweight/PotionFactory.java
@@ -40,7 +40,7 @@ public PotionFactory() {
}
Potion createPotion(PotionType type) {
- Potion potion = potions.get(type);
+ var potion = potions.get(type);
if (potion == null) {
switch (type) {
case HEALING:
diff --git a/flyweight/src/test/java/com/iluwatar/flyweight/AlchemistShopTest.java b/flyweight/src/test/java/com/iluwatar/flyweight/AlchemistShopTest.java
index 16374efb2f95..50053dddf65c 100644
--- a/flyweight/src/test/java/com/iluwatar/flyweight/AlchemistShopTest.java
+++ b/flyweight/src/test/java/com/iluwatar/flyweight/AlchemistShopTest.java
@@ -23,14 +23,12 @@
package com.iluwatar.flyweight;
-import org.junit.jupiter.api.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.util.ArrayList;
+import org.junit.jupiter.api.Test;
+
/**
* Date: 12/12/15 - 10:54 PM
*
@@ -39,18 +37,18 @@
public class AlchemistShopTest {
@Test
- public void testShop() throws Exception {
- final AlchemistShop shop = new AlchemistShop();
+ public void testShop() {
+ final var shop = new AlchemistShop();
- final List bottomShelf = shop.getBottomShelf();
+ final var bottomShelf = shop.getBottomShelf();
assertNotNull(bottomShelf);
assertEquals(5, bottomShelf.size());
- final List topShelf = shop.getTopShelf();
+ final var topShelf = shop.getTopShelf();
assertNotNull(topShelf);
assertEquals(8, topShelf.size());
- final List allPotions = new ArrayList<>();
+ final var allPotions = new ArrayList();
allPotions.addAll(topShelf);
allPotions.addAll(bottomShelf);
diff --git a/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java b/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java
index 8beff17235b5..3d81a6db2e7b 100644
--- a/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java
+++ b/flyweight/src/test/java/com/iluwatar/flyweight/AppTest.java
@@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;
/**
- *
* Application test
- *
*/
public class AppTest {
@Test
public void test() {
- String[] args = {};
- App.main(args);
+ App.main(new String[]{});
}
}
diff --git a/front-controller/pom.xml b/front-controller/pom.xml
index de0f084a9aa2..34dabc18200f 100644
--- a/front-controller/pom.xml
+++ b/front-controller/pom.xml
@@ -50,4 +50,23 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.front.controller.App
+
+
+
+
+
+
+
+
diff --git a/front-controller/src/main/java/com/iluwatar/front/controller/App.java b/front-controller/src/main/java/com/iluwatar/front/controller/App.java
index 7388a06f80d1..d1a77887f7f2 100644
--- a/front-controller/src/main/java/com/iluwatar/front/controller/App.java
+++ b/front-controller/src/main/java/com/iluwatar/front/controller/App.java
@@ -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");
diff --git a/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java b/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java
index 91535f9e04d6..acdb7b1c8f35 100644
--- a/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java
+++ b/front-controller/src/main/java/com/iluwatar/front/controller/FrontController.java
@@ -30,12 +30,12 @@
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 @@ private Command getCommand(String request) {
}
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;
}
}
diff --git a/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java b/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java
index c77da640dbd7..2ea58c6a6da2 100644
--- a/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java
+++ b/front-controller/src/test/java/com/iluwatar/front/controller/AppTest.java
@@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;
/**
- *
* Application test
- *
*/
public class AppTest {
@Test
public void test() {
- String[] args = {};
- App.main(args);
+ App.main(new String[]{});
}
}
diff --git a/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java b/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java
index 085c317555a4..165d13f44f0d 100644
--- a/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java
+++ b/front-controller/src/test/java/com/iluwatar/front/controller/ApplicationExceptionTest.java
@@ -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());
}
diff --git a/front-controller/src/test/java/com/iluwatar/front/controller/CommandTest.java b/front-controller/src/test/java/com/iluwatar/front/controller/CommandTest.java
index 82cd4c0da699..46a3ae94b5a1 100644
--- a/front-controller/src/test/java/com/iluwatar/front/controller/CommandTest.java
+++ b/front-controller/src/test/java/com/iluwatar/front/controller/CommandTest.java
@@ -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 void tearDown() {
}
static List