The Wayback Machine - https://web.archive.org/web/20211021090204/https://github.com/iluwatar/java-design-patterns/commit/5cf2fe009bc2c04dab737d41523576c6149e605c
Skip to content
Permalink
Browse files
📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
  • Loading branch information
va1m and va1m committed Mar 13, 2021
1 parent 0e26a6a commit 5cf2fe009bc2c04dab737d41523576c6149e605c
Showing 681 changed files with 2,468 additions and 4,962 deletions.
@@ -27,8 +27,7 @@
import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* The Abstract Document pattern enables handling additional, non-static properties. This pattern
@@ -38,10 +37,9 @@
* <p>In Abstract Document pattern,({@link AbstractDocument}) fully implements {@link Document})
* interface. Traits are then defined to enable access to properties in usual, static way.
*/
@Slf4j
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Program entry point.
*
@@ -23,19 +23,18 @@

package com.iluwatar.abstractdocument;

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

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* AbstractDocument test class
*/
public class AbstractDocumentTest {
class AbstractDocumentTest {

private static final String KEY = "key";
private static final String VALUE = "value";
@@ -50,13 +49,13 @@
private final DocumentImplementation document = new DocumentImplementation(new HashMap<>());

@Test
public void shouldPutAndGetValue() {
void shouldPutAndGetValue() {
document.put(KEY, VALUE);
assertEquals(VALUE, document.get(KEY));
}

@Test
public void shouldRetrieveChildren() {
void shouldRetrieveChildren() {
var children = List.of(Map.of(), Map.of());

document.put(KEY, children);
@@ -67,14 +66,14 @@ public void shouldRetrieveChildren() {
}

@Test
public void shouldRetrieveEmptyStreamForNonExistingChildren() {
void shouldRetrieveEmptyStreamForNonExistingChildren() {
var children = document.children(KEY, DocumentImplementation::new);
assertNotNull(children);
assertEquals(0, children.count());
}

@Test
public void shouldIncludePropsInToString() {
void shouldIncludePropsInToString() {
var props = Map.of(KEY, (Object) VALUE);
var document = new DocumentImplementation(props);
assertTrue(document.toString().contains(KEY));
@@ -23,19 +23,20 @@

package com.iluwatar.abstractdocument;

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

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.Part;
import com.iluwatar.abstractdocument.domain.enums.Property;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

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

/**
* Test for Part and Car
*/
public class DomainTest {
class DomainTest {

private static final String TEST_PART_TYPE = "test-part-type";
private static final String TEST_PART_MODEL = "test-part-model";
@@ -45,7 +46,7 @@
private static final long TEST_CAR_PRICE = 1L;

@Test
public void shouldConstructPart() {
void shouldConstructPart() {
var partProperties = Map.of(
Property.TYPE.toString(), TEST_PART_TYPE,
Property.MODEL.toString(), TEST_PART_MODEL,
@@ -58,7 +59,7 @@ public void shouldConstructPart() {
}

@Test
public void shouldConstructCar() {
void shouldConstructCar() {
var carProperties = Map.of(
Property.MODEL.toString(), TEST_CAR_MODEL,
Property.PRICE.toString(), TEST_CAR_PRICE,
@@ -23,8 +23,7 @@

package com.iluwatar.abstractfactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that
@@ -40,10 +39,9 @@
* and its implementations ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
* both concrete implementations to create a king, a castle and an army.
*/
@Slf4j
public class App implements Runnable {

private static Logger log = LoggerFactory.getLogger(App.class);

private final Kingdom kingdom = new Kingdom();

public Kingdom getKingdom() {
@@ -62,17 +60,17 @@ public static void main(String[] args) {

@Override
public void run() {
log.info("Elf Kingdom");
LOGGER.info("Elf Kingdom");
createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
log.info(kingdom.getArmy().getDescription());
log.info(kingdom.getCastle().getDescription());
log.info(kingdom.getKing().getDescription());
LOGGER.info(kingdom.getArmy().getDescription());
LOGGER.info(kingdom.getCastle().getDescription());
LOGGER.info(kingdom.getKing().getDescription());

log.info("Orc Kingdom");
LOGGER.info("Orc Kingdom");
createKingdom(Kingdom.FactoryMaker.KingdomType.ORC);
log.info(kingdom.getArmy().getDescription());
log.info(kingdom.getCastle().getDescription());
log.info(kingdom.getKing().getDescription());
LOGGER.info(kingdom.getArmy().getDescription());
LOGGER.info(kingdom.getCastle().getDescription());
LOGGER.info(kingdom.getKing().getDescription());
}

/**
@@ -23,36 +23,17 @@

package com.iluwatar.abstractfactory;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Kingdom {

private King king;
private Castle castle;
private Army army;

public King getKing() {
return king;
}

public Castle getCastle() {
return castle;
}

public Army getArmy() {
return army;
}

public void setKing(King king) {
this.king = king;
}

public void setCastle(Castle castle) {
this.castle = castle;
}

public void setArmy(Army army) {
this.army = army;
}

/**
* The factory of kingdom factories.
*/
@@ -31,12 +31,12 @@
/**
* Test for abstract factory.
*/
public class AbstractFactoryTest {
class AbstractFactoryTest {

private final App app = new App();

@Test
public void king() {
void king() {
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
final var kingdom = app.getKingdom();

@@ -51,7 +51,7 @@ public void king() {
}

@Test
public void castle() {
void castle() {
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
final var kingdom = app.getKingdom();

@@ -66,7 +66,7 @@ public void castle() {
}

@Test
public void army() {
void army() {
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
final var kingdom = app.getKingdom();

@@ -81,7 +81,7 @@ public void army() {
}

@Test
public void createElfKingdom() {
void createElfKingdom() {
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
final var kingdom = app.getKingdom();

@@ -97,7 +97,7 @@ public void createElfKingdom() {
}

@Test
public void createOrcKingdom() {
void createOrcKingdom() {
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ORC);
final var kingdom = app.getKingdom();

@@ -23,17 +23,15 @@

package com.iluwatar.acyclicvisitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos
* manufacturer.
*/
@Slf4j
public class ConfigureForDosVisitor implements AllModemVisitor {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);

@Override
public void visit(Hayes hayes) {
LOGGER.info(hayes + " used with Dos configurator.");
@@ -23,17 +23,15 @@

package com.iluwatar.acyclicvisitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* ConfigureForUnixVisitor class implements zoom's visit method for Unix manufacturer, unlike
* traditional visitor pattern, this class may selectively implement visit for other modems.
*/
@Slf4j
public class ConfigureForUnixVisitor implements ZoomVisitor {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForUnixVisitor.class);

@Override
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Unix configurator.");
@@ -23,16 +23,14 @@

package com.iluwatar.acyclicvisitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* Hayes class implements its accept method.
*/
@Slf4j
public class Hayes extends Modem {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);

/**
* Accepts all visitors but honors only HayesVisitor.
*/
@@ -23,16 +23,14 @@

package com.iluwatar.acyclicvisitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* Zoom class implements its accept method.
*/
@Slf4j
public class Zoom extends Modem {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);

/**
* Accepts all visitors but honors only ZoomVisitor.
*/
@@ -35,34 +35,34 @@
/**
* ConfigureForDosVisitor test class
*/
public class ConfigureForDosVisitorTest {
class ConfigureForDosVisitorTest {

private final TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);

@Test
public void testVisitForZoom() {
void testVisitForZoom() {
var conDos = new ConfigureForDosVisitor();
var zoom = new Zoom();

conDos.visit(zoom);

assertThat(logger.getLoggingEvents())
.extracting("level", "message")
.contains(tuple(INFO, zoom + " used with Dos configurator."));
}

@Test
public void testVisitForHayes() {
void testVisitForHayes() {
var conDos = new ConfigureForDosVisitor();
var hayes = new Hayes();

conDos.visit(hayes);

assertThat(logger.getLoggingEvents())
.extracting("level", "message")
.contains(tuple(INFO, hayes + " used with Dos configurator."));
}

@AfterEach
public void clearLoggers() {
TestLoggerFactory.clear();

0 comments on commit 5cf2fe0

Please sign in to comment.