* #984 Fix for abstract-document, abstract-factory, acyclic-visitor, adapter, aggregator-microservices * #984 Fix for abstract-document, abstract-factory, acyclic-visitor, adapter, aggregator-microservices
This commit is contained in:
parent
2217fbc5ff
commit
f00ebe1a8d
@ -61,7 +61,7 @@ public abstract class AbstractDocument implements Document {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
builder.append(getClass().getName()).append("[");
|
builder.append(getClass().getName()).append("[");
|
||||||
properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value).append("]"));
|
properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value).append("]"));
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
|
@ -24,7 +24,6 @@ package com.iluwatar.abstractdocument;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -52,23 +51,23 @@ public class App {
|
|||||||
public App() {
|
public App() {
|
||||||
LOGGER.info("Constructing parts and car");
|
LOGGER.info("Constructing parts and car");
|
||||||
|
|
||||||
Map<String, Object> carProperties = new HashMap<>();
|
var carProperties = new HashMap<String, Object>();
|
||||||
carProperties.put(Property.MODEL.toString(), "300SL");
|
carProperties.put(Property.MODEL.toString(), "300SL");
|
||||||
carProperties.put(Property.PRICE.toString(), 10000L);
|
carProperties.put(Property.PRICE.toString(), 10000L);
|
||||||
|
|
||||||
Map<String, Object> wheelProperties = new HashMap<>();
|
var wheelProperties = new HashMap<String, Object>();
|
||||||
wheelProperties.put(Property.TYPE.toString(), "wheel");
|
wheelProperties.put(Property.TYPE.toString(), "wheel");
|
||||||
wheelProperties.put(Property.MODEL.toString(), "15C");
|
wheelProperties.put(Property.MODEL.toString(), "15C");
|
||||||
wheelProperties.put(Property.PRICE.toString(), 100L);
|
wheelProperties.put(Property.PRICE.toString(), 100L);
|
||||||
|
|
||||||
Map<String, Object> doorProperties = new HashMap<>();
|
var doorProperties = new HashMap<String, Object>();
|
||||||
doorProperties.put(Property.TYPE.toString(), "door");
|
doorProperties.put(Property.TYPE.toString(), "door");
|
||||||
doorProperties.put(Property.MODEL.toString(), "Lambo");
|
doorProperties.put(Property.MODEL.toString(), "Lambo");
|
||||||
doorProperties.put(Property.PRICE.toString(), 300L);
|
doorProperties.put(Property.PRICE.toString(), 300L);
|
||||||
|
|
||||||
carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));
|
carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));
|
||||||
|
|
||||||
Car car = new Car(carProperties);
|
var car = new Car(carProperties);
|
||||||
|
|
||||||
LOGGER.info("Here is our car:");
|
LOGGER.info("Here is our car:");
|
||||||
LOGGER.info("-> model: {}", car.getModel().get());
|
LOGGER.info("-> model: {}", car.getModel().get());
|
||||||
|
@ -41,11 +41,11 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor();
|
var conUnix = new ConfigureForUnixVisitor();
|
||||||
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
|
var conDos = new ConfigureForDosVisitor();
|
||||||
|
|
||||||
Zoom zoom = new Zoom();
|
var zoom = new Zoom();
|
||||||
Hayes hayes = new Hayes();
|
var hayes = new Hayes();
|
||||||
|
|
||||||
hayes.accept(conDos); // Hayes modem with Dos configurator
|
hayes.accept(conDos); // Hayes modem with Dos configurator
|
||||||
zoom.accept(conDos); // Zoom modem with Dos configurator
|
zoom.accept(conDos); // Zoom modem with Dos configurator
|
||||||
|
@ -24,18 +24,10 @@ package com.iluwatar.acyclicvisitor;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.groups.Tuple.tuple;
|
import static org.assertj.core.groups.Tuple.tuple;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static uk.org.lidalia.slf4jext.Level.INFO;
|
import static uk.org.lidalia.slf4jext.Level.INFO;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.Hayes;
|
|
||||||
import com.iluwatar.acyclicvisitor.HayesVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.Zoom;
|
|
||||||
import com.iluwatar.acyclicvisitor.ZoomVisitor;
|
|
||||||
|
|
||||||
import uk.org.lidalia.slf4jtest.TestLogger;
|
import uk.org.lidalia.slf4jtest.TestLogger;
|
||||||
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
|
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
|
||||||
|
|
||||||
@ -48,8 +40,8 @@ public class ConfigureForDosVisitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitForZoom() {
|
public void testVisitForZoom() {
|
||||||
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
|
var conDos = new ConfigureForDosVisitor();
|
||||||
Zoom zoom = new Zoom();
|
var zoom = new Zoom();
|
||||||
|
|
||||||
conDos.visit(zoom);
|
conDos.visit(zoom);
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ public class ConfigureForUnixVisitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitForZoom() {
|
public void testVisitForZoom() {
|
||||||
ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor();
|
var conUnix = new ConfigureForUnixVisitor();
|
||||||
Zoom zoom = new Zoom();
|
var zoom = new Zoom();
|
||||||
|
|
||||||
conUnix.visit(zoom);
|
conUnix.visit(zoom);
|
||||||
|
|
||||||
|
@ -29,11 +29,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.Hayes;
|
|
||||||
import com.iluwatar.acyclicvisitor.HayesVisitor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hayes test class
|
* Hayes test class
|
||||||
*/
|
*/
|
||||||
@ -41,8 +36,8 @@ public class HayesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptForDos() {
|
public void testAcceptForDos() {
|
||||||
Hayes hayes = new Hayes();
|
var hayes = new Hayes();
|
||||||
ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class);
|
var mockVisitor = mock(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
hayes.accept(mockVisitor);
|
hayes.accept(mockVisitor);
|
||||||
verify((HayesVisitor)mockVisitor).visit(eq(hayes));
|
verify((HayesVisitor)mockVisitor).visit(eq(hayes));
|
||||||
@ -50,8 +45,8 @@ public class HayesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptForUnix() {
|
public void testAcceptForUnix() {
|
||||||
Hayes hayes = new Hayes();
|
var hayes = new Hayes();
|
||||||
ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class);
|
var mockVisitor = mock(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
hayes.accept(mockVisitor);
|
hayes.accept(mockVisitor);
|
||||||
|
|
||||||
|
@ -29,11 +29,6 @@ import static org.mockito.Mockito.mock;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
|
|
||||||
import com.iluwatar.acyclicvisitor.Zoom;
|
|
||||||
import com.iluwatar.acyclicvisitor.ZoomVisitor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zoom test class
|
* Zoom test class
|
||||||
*/
|
*/
|
||||||
@ -41,8 +36,8 @@ public class ZoomTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptForDos() {
|
public void testAcceptForDos() {
|
||||||
Zoom zoom = new Zoom();
|
var zoom = new Zoom();
|
||||||
ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class);
|
var mockVisitor = mock(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
zoom.accept(mockVisitor);
|
zoom.accept(mockVisitor);
|
||||||
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
||||||
@ -50,8 +45,8 @@ public class ZoomTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptForUnix() {
|
public void testAcceptForUnix() {
|
||||||
Zoom zoom = new Zoom();
|
var zoom = new Zoom();
|
||||||
ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class);
|
var mockVisitor = mock(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
zoom.accept(mockVisitor);
|
zoom.accept(mockVisitor);
|
||||||
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
||||||
|
@ -54,7 +54,7 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
|
// The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
|
||||||
Captain captain = new Captain(new FishingBoatAdapter());
|
var captain = new Captain(new FishingBoatAdapter());
|
||||||
captain.row();
|
captain.row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class AdapterPatternTest {
|
|||||||
FishingBoatAdapter fishingBoatAdapter = spy(new FishingBoatAdapter());
|
FishingBoatAdapter fishingBoatAdapter = spy(new FishingBoatAdapter());
|
||||||
beans.put(FISHING_BEAN, fishingBoatAdapter);
|
beans.put(FISHING_BEAN, fishingBoatAdapter);
|
||||||
|
|
||||||
Captain captain = new Captain();
|
var captain = new Captain();
|
||||||
captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
|
captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
|
||||||
beans.put(ROWING_BEAN, captain);
|
beans.put(ROWING_BEAN, captain);
|
||||||
}
|
}
|
||||||
@ -66,13 +66,13 @@ public class AdapterPatternTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAdapter() {
|
public void testAdapter() {
|
||||||
Captain captain = (Captain) beans.get(ROWING_BEAN);
|
var captain = (Captain) beans.get(ROWING_BEAN);
|
||||||
|
|
||||||
// when captain moves
|
// when captain moves
|
||||||
captain.row();
|
captain.row();
|
||||||
|
|
||||||
// the captain internally calls the battleship object to move
|
// the captain internally calls the battleship object to move
|
||||||
RowingBoat adapter = (RowingBoat) beans.get(FISHING_BEAN);
|
var adapter = (RowingBoat) beans.get(FISHING_BEAN);
|
||||||
verify(adapter).row();
|
verify(adapter).row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class Aggregator {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(path = "/product", method = RequestMethod.GET)
|
@RequestMapping(path = "/product", method = RequestMethod.GET)
|
||||||
public Product getProduct() {
|
public Product getProduct() {
|
||||||
Product product = new Product();
|
var product = new Product();
|
||||||
product.setTitle(informationClient.getProductTitle());
|
product.setTitle(informationClient.getProductTitle());
|
||||||
product.setProductInventories(inventoryClient.getProductInventories());
|
product.setProductInventories(inventoryClient.getProductInventories());
|
||||||
return product;
|
return product;
|
||||||
|
@ -43,10 +43,10 @@ public class ProductInformationClientImpl implements ProductInformationClient {
|
|||||||
@Override
|
@Override
|
||||||
public String getProductTitle() {
|
public String getProductTitle() {
|
||||||
String response = null;
|
String response = null;
|
||||||
HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51515/information")).build();
|
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51515/information")).build();
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
var client = HttpClient.newHttpClient();
|
||||||
try {
|
try {
|
||||||
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
response = httpResponse.body();
|
response = httpResponse.body();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
LOGGER.error("IOException Occurred", ioe);
|
LOGGER.error("IOException Occurred", ioe);
|
||||||
|
@ -42,12 +42,12 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProductInventories() {
|
public int getProductInventories() {
|
||||||
String response = "0";
|
var response = "0";
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build();
|
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build();
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
var client = HttpClient.newHttpClient();
|
||||||
try {
|
try {
|
||||||
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
response = httpResponse.body();
|
response = httpResponse.body();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
LOGGER.error("IOException Occurred", ioe);
|
LOGGER.error("IOException Occurred", ioe);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user