📍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:
@ -49,10 +49,9 @@ public interface WizardTower {
|
||||
void enter(Wizard wizard);
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
public class IvoryTower implements WizardTower {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(IvoryTower.class);
|
||||
|
||||
public void enter(Wizard wizard) {
|
||||
LOGGER.info("{} enters the tower.", wizard);
|
||||
}
|
||||
@ -81,10 +80,9 @@ public class Wizard {
|
||||
Then we have the `WizardTowerProxy` to add access control to `WizardTower`.
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
public class WizardTowerProxy implements WizardTower {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WizardTowerProxy.class);
|
||||
|
||||
private static final int NUM_WIZARDS_ALLOWED = 3;
|
||||
|
||||
private int numWizards;
|
||||
|
@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.proxy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The object to be proxied.
|
||||
*/
|
||||
@Slf4j
|
||||
public class IvoryTower implements WizardTower {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(IvoryTower.class);
|
||||
|
||||
public void enter(Wizard wizard) {
|
||||
LOGGER.info("{} enters the tower.", wizard);
|
||||
}
|
||||
|
@ -23,17 +23,16 @@
|
||||
|
||||
package com.iluwatar.proxy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Wizard.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class Wizard {
|
||||
|
||||
private final String name;
|
||||
|
||||
public Wizard(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.proxy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The proxy controlling access to the {@link IvoryTower}.
|
||||
*/
|
||||
@Slf4j
|
||||
public class WizardTowerProxy implements WizardTower {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WizardTowerProxy.class);
|
||||
|
||||
private static final int NUM_WIZARDS_ALLOWED = 3;
|
||||
|
||||
private int numWizards;
|
||||
|
@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Tests for {@link IvoryTower}
|
||||
*/
|
||||
public class IvoryTowerTest {
|
||||
class IvoryTowerTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@ -50,7 +50,7 @@ public class IvoryTowerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnter() {
|
||||
void testEnter() {
|
||||
final var wizards = List.of(
|
||||
new Wizard("Gandalf"),
|
||||
new Wizard("Dumbledore"),
|
||||
|
@ -31,10 +31,10 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Tests for {@link Wizard}
|
||||
*/
|
||||
public class WizardTest {
|
||||
class WizardTest {
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
void testToString() {
|
||||
List.of("Gandalf", "Dumbledore", "Oz", "Merlin")
|
||||
.forEach(name -> assertEquals(name, new Wizard(name).toString()));
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Tests for {@link WizardTowerProxy}
|
||||
*/
|
||||
public class WizardTowerProxyTest {
|
||||
class WizardTowerProxyTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@ -50,7 +50,7 @@ public class WizardTowerProxyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnter() throws Exception {
|
||||
void testEnter() {
|
||||
final var wizards = List.of(
|
||||
new Wizard("Gandalf"),
|
||||
new Wizard("Dumbledore"),
|
||||
|
@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender(Class clazz) {
|
||||
public InMemoryAppender(Class<?> clazz) {
|
||||
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
|
||||
start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user