Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 11 migrate 7 remaining f #1115

Merged
merged 10 commits into from
Dec 22, 2019
8 changes: 2 additions & 6 deletions facade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public abstract class DwarvenMineWorker {
}

public void action(Action... actions) {
for (Action action : actions) {
action(action);
}
Arrays.stream(actions).forEach(this::action);
}

public abstract void work();
Expand Down Expand Up @@ -166,9 +164,7 @@ public class DwarvenGoldmineFacade {

private static void makeActions(Collection<DwarvenMineWorker> workers,
DwarvenMineWorker.Action... actions) {
for (DwarvenMineWorker worker : workers) {
worker.action(actions);
}
workers.forEach(worker -> worker.action(actions));
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion facade/src/main/java/com/iluwatar/facade/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class App {
* @param args command line args
*/
public static void main(String[] args) {
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
var facade = new DwarvenGoldmineFacade();
facade.startNewDay();
facade.digOutGold();
facade.endDay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ private static void makeActions(
Collection<DwarvenMineWorker> workers,
DwarvenMineWorker.Action... actions
) {
for (DwarvenMineWorker worker : workers) {
worker.action(actions);
}
workers.forEach(worker -> worker.action(actions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.iluwatar.facade;

import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -76,9 +77,7 @@ private void action(Action action) {
* Perform actions.
*/
public void action(Action... actions) {
for (Action action : actions) {
action(action);
}
Arrays.stream(actions).forEach(this::action);
}

public abstract void work();
Expand Down
5 changes: 1 addition & 4 deletions facade/src/test/java/com/iluwatar/facade/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@

package com.iluwatar.facade;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import java.util.LinkedList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Date: 12/9/15 - 9:40 PM
*
Expand All @@ -56,16 +55,16 @@ public void tearDown() {
appender.stop();
}

/**
/**
* Test a complete day cycle in the gold mine by executing all three different steps: {@link
* DwarvenGoldmineFacade#startNewDay()}, {@link DwarvenGoldmineFacade#digOutGold()} and {@link
* DwarvenGoldmineFacade#endDay()}.
*
* <p>
* 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 ...
Expand Down Expand 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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions factory-kit/src/main/java/com/iluwatar/factorykit/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -52,7 +51,7 @@ public interface WeaponFactory {
* @return factory with specified {@link Builder}s
*/
static WeaponFactory factory(Consumer<Builder> consumer) {
Map<WeaponType, Supplier<Weapon>> map = new HashMap<>();
var map = new HashMap<WeaponType, Supplier<Weapon>>();
consumer.accept(map::put);
return name -> map.get(name).get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class AppTest {

@Test
public void test() {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion factory-method/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.iluwatar.factory.method;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.iluwatar.factory.method;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]{});
}
}
Loading