Skip to content

Commit

Permalink
📍Use lombok, reformat, and optimize the code (iluwatar#1560)
Browse files Browse the repository at this point in the history
* 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 authored Mar 13, 2021
1 parent 0e26a6a commit 5cf2fe0
Show file tree
Hide file tree
Showing 681 changed files with 2,468 additions and 4,962 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -50,13 +49,13 @@ private static class DocumentImplementation extends AbstractDocument {
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);
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -45,7 +46,7 @@ public class DomainTest {
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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

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

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 5cf2fe0

Please sign in to comment.