Java 11 migrate c-d (remaining) (#1111)

* Moves converter pattern to Java 11

* Moves cqrs pattern to Java 11

* Moves dao pattern to Java 11

* Moves data-bus pattern to Java 11

* Moves data-locality pattern to Java 11

* Moves data-mapper pattern to Java 11

* Moves data-transfer-object pattern to Java 11

* Moves decorator pattern to Java 11

* Moves delegation pattern to Java 11

* Moves dependency-injection to Java 11

* Moves dirty-flag to Java 11

* Moves double-buffer to Java 11

* Moves double-checked-locking to Java 11

* Moves double-dispatch to Java 11

* Corrects with changes thats breaking test cases
This commit is contained in:
Anurag Agarwal
2019-12-15 00:02:45 +05:30
committed by Ilkka Seppälä
parent 5681684157
commit ea57934db6
75 changed files with 576 additions and 713 deletions

View File

@ -24,7 +24,6 @@
package com.iluwatar.dependency.injection;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Dependency Injection pattern deals with how objects handle their dependencies. The pattern
@ -55,18 +54,18 @@ public class App {
* @param args command line args
*/
public static void main(String[] args) {
SimpleWizard simpleWizard = new SimpleWizard();
var simpleWizard = new SimpleWizard();
simpleWizard.smoke();
AdvancedWizard advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco());
var advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco());
advancedWizard.smoke();
AdvancedSorceress advancedSorceress = new AdvancedSorceress();
var advancedSorceress = new AdvancedSorceress();
advancedSorceress.setTobacco(new SecondBreakfastTobacco());
advancedSorceress.smoke();
Injector injector = Guice.createInjector(new TobaccoModule());
GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class);
var injector = Guice.createInjector(new TobaccoModule());
var guiceWizard = injector.getInstance(GuiceWizard.class);
guiceWizard.smoke();
}
}

View File

@ -23,13 +23,14 @@
package com.iluwatar.dependency.injection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 28/04/17 - 7:40 AM
@ -52,27 +53,29 @@ public class AdvancedSorceressTest {
}
/**
* Test if the {@link AdvancedSorceress} smokes whatever instance of {@link Tobacco} is passed to her
* through the setter's parameter
* Test if the {@link AdvancedSorceress} smokes whatever instance of {@link Tobacco} is passed to
* her through the setter's parameter
*/
@Test
public void testSmokeEveryThing() throws Exception {
final Tobacco[] tobaccos = {
new OldTobyTobacco(), new RivendellTobacco(), new SecondBreakfastTobacco()
};
List<Tobacco> tobaccos = List.of(
new OldTobyTobacco(),
new RivendellTobacco(),
new SecondBreakfastTobacco()
);
for (final Tobacco tobacco : tobaccos) {
final AdvancedSorceress advancedSorceress = new AdvancedSorceress();
// Verify if the sorceress is smoking the correct tobacco ...
tobaccos.forEach(tobacco -> {
final var advancedSorceress = new AdvancedSorceress();
advancedSorceress.setTobacco(tobacco);
advancedSorceress.smoke();
// Verify if the sorceress is smoking the correct tobacco ...
assertEquals("AdvancedSorceress smoking " + tobacco.getClass().getSimpleName(), appender.getLastMessage());
}
String lastMessage = appender.getLastMessage();
assertEquals("AdvancedSorceress smoking " + tobacco.getClass().getSimpleName(), lastMessage);
});
// ... and nothing else is happening.
assertEquals(tobaccos.length, appender.getLogSize());
assertEquals(tobaccos.size(), appender.getLogSize());
}
}

View File

@ -23,13 +23,14 @@
package com.iluwatar.dependency.injection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:40 PM
@ -57,21 +58,22 @@ public class AdvancedWizardTest {
@Test
public void testSmokeEveryThing() throws Exception {
final Tobacco[] tobaccos = {
new OldTobyTobacco(), new RivendellTobacco(), new SecondBreakfastTobacco()
};
List<Tobacco> tobaccos = List.of(
new OldTobyTobacco(),
new RivendellTobacco(),
new SecondBreakfastTobacco()
);
for (final Tobacco tobacco : tobaccos) {
// Verify if the wizard is smoking the correct tobacco ...
tobaccos.forEach(tobacco -> {
final AdvancedWizard advancedWizard = new AdvancedWizard(tobacco);
advancedWizard.smoke();
// Verify if the wizard is smoking the correct tobacco ...
assertEquals("AdvancedWizard smoking " + tobacco.getClass().getSimpleName(), appender.getLastMessage());
}
String lastMessage = appender.getLastMessage();
assertEquals("AdvancedWizard smoking " + tobacco.getClass().getSimpleName(), lastMessage);
});
// ... and nothing else is happening.
assertEquals(tobaccos.length, appender.getLogSize());
assertEquals(tobaccos.size(), appender.getLogSize());
}

View File

@ -26,15 +26,12 @@ package com.iluwatar.dependency.injection;
import org.junit.jupiter.api.Test;
/**
*
* Application test
*
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}

View File

@ -23,16 +23,16 @@
package com.iluwatar.dependency.injection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:57 PM
*
@ -59,20 +59,22 @@ public class GuiceWizardTest {
@Test
public void testSmokeEveryThingThroughConstructor() throws Exception {
final Tobacco[] tobaccos = {
new OldTobyTobacco(), new RivendellTobacco(), new SecondBreakfastTobacco()
};
List<Tobacco> tobaccos = List.of(
new OldTobyTobacco(),
new RivendellTobacco(),
new SecondBreakfastTobacco()
);
for (final Tobacco tobacco : tobaccos) {
// Verify if the wizard is smoking the correct tobacco ...
tobaccos.forEach(tobacco -> {
final GuiceWizard guiceWizard = new GuiceWizard(tobacco);
guiceWizard.smoke();
// Verify if the wizard is smoking the correct tobacco ...
assertEquals("GuiceWizard smoking " + tobacco.getClass().getSimpleName(), appender.getLastMessage());
}
String lastMessage = appender.getLastMessage();
assertEquals("GuiceWizard smoking " + tobacco.getClass().getSimpleName(), lastMessage);
});
// ... and nothing else is happening.
assertEquals(tobaccos.length, appender.getLogSize());
assertEquals(tobaccos.size(), appender.getLogSize());
}
/**
@ -82,30 +84,30 @@ public class GuiceWizardTest {
@Test
public void testSmokeEveryThingThroughInjectionFramework() throws Exception {
@SuppressWarnings("unchecked")
final Class<? extends Tobacco>[] tobaccos = new Class[]{
OldTobyTobacco.class, RivendellTobacco.class, SecondBreakfastTobacco.class
};
List<Class<? extends Tobacco>> tobaccos = List.of(
OldTobyTobacco.class,
RivendellTobacco.class,
SecondBreakfastTobacco.class
);
for (final Class<? extends Tobacco> tobaccoClass : tobaccos) {
// Configure the tobacco in the injection framework ...
final Injector injector = Guice.createInjector(new AbstractModule() {
// Configure the tobacco in the injection framework ...
// ... and create a new wizard with it
// Verify if the wizard is smoking the correct tobacco ...
tobaccos.forEach(tobaccoClass -> {
final var injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Tobacco.class).to(tobaccoClass);
}
});
// ... and create a new wizard with it
final GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class);
final var guiceWizard = injector.getInstance(GuiceWizard.class);
guiceWizard.smoke();
// Verify if the wizard is smoking the correct tobacco ...
assertEquals("GuiceWizard smoking " + tobaccoClass.getSimpleName(), appender.getLastMessage());
}
String lastMessage = appender.getLastMessage();
assertEquals("GuiceWizard smoking " + tobaccoClass.getSimpleName(), lastMessage);
});
// ... and nothing else is happening.
assertEquals(tobaccos.length, appender.getLogSize());
assertEquals(tobaccos.size(), appender.getLogSize());
}
}

View File

@ -23,13 +23,13 @@
package com.iluwatar.dependency.injection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:26 PM
*
@ -55,7 +55,7 @@ public class SimpleWizardTest {
*/
@Test
public void testSmoke() {
final SimpleWizard simpleWizard = new SimpleWizard();
final var simpleWizard = new SimpleWizard();
simpleWizard.smoke();
assertEquals("SimpleWizard smoking OldTobyTobacco", appender.getLastMessage());
assertEquals(1, appender.getLogSize());