📍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>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -23,8 +23,7 @@
package com.iluwatar.decorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Decorator pattern is a more flexible alternative to subclassing. The Decorator class
@ -36,10 +35,9 @@ import org.slf4j.LoggerFactory;
* battle. Then we decorate the {@link SimpleTroll} with a {@link ClubbedTroll} and perform the
* attack again. You can see how the behavior changes after the decoration.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -23,22 +23,18 @@
package com.iluwatar.decorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* Decorator that adds a club for the troll.
*/
@Slf4j
@RequiredArgsConstructor
public class ClubbedTroll implements Troll {
private static final Logger LOGGER = LoggerFactory.getLogger(ClubbedTroll.class);
private final Troll decorated;
public ClubbedTroll(Troll decorated) {
this.decorated = decorated;
}
@Override
public void attack() {
decorated.attack();

View File

@ -23,16 +23,14 @@
package com.iluwatar.decorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* SimpleTroll implements {@link Troll} interface directly.
*/
@Slf4j
public class SimpleTroll implements Troll {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleTroll.class);
@Override
public void attack() {
LOGGER.info("The troll tries to grab you!");

View File

@ -34,10 +34,10 @@ import org.junit.jupiter.api.Test;
/**
* Tests for {@link ClubbedTroll}
*/
public class ClubbedTrollTest {
class ClubbedTrollTest {
@Test
public void testClubbedTroll() {
void testClubbedTroll() {
// Create a normal troll first, but make sure we can spy on it later on.
final var simpleTroll = spy(new SimpleTroll());

View File

@ -38,22 +38,22 @@ import org.slf4j.LoggerFactory;
/**
* Tests for {@link SimpleTroll}
*/
public class SimpleTrollTest {
class SimpleTrollTest {
private InMemoryAppender appender;
@BeforeEach
public void setUp() {
void setUp() {
appender = new InMemoryAppender(SimpleTroll.class);
}
@AfterEach
public void tearDown() {
void tearDown() {
appender.stop();
}
@Test
public void testTrollActions() {
void testTrollActions() {
final var troll = new SimpleTroll();
assertEquals(10, troll.getAttackPower());
@ -70,7 +70,7 @@ public class SimpleTrollTest {
private final List<ILoggingEvent> log = new LinkedList<>();
public InMemoryAppender(Class clazz) {
InMemoryAppender(Class clazz) {
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
start();
}
@ -80,11 +80,11 @@ public class SimpleTrollTest {
log.add(eventObject);
}
public String getLastMessage() {
String getLastMessage() {
return log.get(log.size() - 1).getMessage();
}
public int getLogSize() {
int getLogSize() {
return log.size();
}
}