📍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

@ -46,20 +46,18 @@ public interface WeatherObserver {
void update(WeatherType currentWeather);
}
@Slf4j
public class Orcs implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Orcs.class);
@Override
public void update(WeatherType currentWeather) {
LOGGER.info("The orcs are facing " + currentWeather.getDescription() + " weather now");
}
}
@Slf4j
public class Hobbits implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Hobbits.class);
@Override
public void update(WeatherType currentWeather) {
switch (currentWeather) {
@ -72,10 +70,9 @@ public class Hobbits implements WeatherObserver {
Then here's the `Weather` that is constantly changing.
```java
@Slf4j
public class Weather {
private static final Logger LOGGER = LoggerFactory.getLogger(Weather.class);
private WeatherType currentWeather;
private final List<WeatherObserver> observers;

View File

@ -26,8 +26,7 @@ package com.iluwatar.observer;
import com.iluwatar.observer.generic.GHobbits;
import com.iluwatar.observer.generic.GOrcs;
import com.iluwatar.observer.generic.GWeather;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Observer pattern is a software design pattern in which an object, called the subject,
@ -40,10 +39,9 @@ import org.slf4j.LoggerFactory;
* <p>In this example {@link Weather} has a state that can be observed. The {@link Orcs} and {@link
* Hobbits} register as observers and receive notifications when the {@link Weather} changes.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -23,18 +23,16 @@
package com.iluwatar.observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Hobbits.
*/
@Slf4j
public class Hobbits implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Hobbits.class);
@Override
public void update(WeatherType currentWeather) {
LOGGER.info("The hobbits are facing " + currentWeather.getDescription() + " weather now");
LOGGER.info("The hobbits are facing {} weather now", currentWeather.getDescription());
}
}

View File

@ -23,16 +23,14 @@
package com.iluwatar.observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Orcs.
*/
@Slf4j
public class Orcs implements WeatherObserver {
private static final Logger LOGGER = LoggerFactory.getLogger(Orcs.class);
@Override
public void update(WeatherType currentWeather) {
LOGGER.info("The orcs are facing " + currentWeather.getDescription() + " weather now");

View File

@ -25,17 +25,15 @@ package com.iluwatar.observer;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Weather can be observed by implementing {@link WeatherObserver} interface and registering as
* listener.
*/
@Slf4j
public class Weather {
private static final Logger LOGGER = LoggerFactory.getLogger(Weather.class);
private WeatherType currentWeather;
private final List<WeatherObserver> observers;

View File

@ -24,16 +24,14 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* GHobbits.
*/
@Slf4j
public class GHobbits implements Race {
private static final Logger LOGGER = LoggerFactory.getLogger(GHobbits.class);
@Override
public void update(GWeather weather, WeatherType weatherType) {
LOGGER.info("The hobbits are facing " + weatherType.getDescription() + " weather now");

View File

@ -24,16 +24,14 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* GOrcs.
*/
@Slf4j
public class GOrcs implements Race {
private static final Logger LOGGER = LoggerFactory.getLogger(GOrcs.class);
@Override
public void update(GWeather weather, WeatherType weatherType) {
LOGGER.info("The orcs are facing " + weatherType.getDescription() + " weather now");

View File

@ -24,16 +24,14 @@
package com.iluwatar.observer.generic;
import com.iluwatar.observer.WeatherType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* GWeather.
*/
@Slf4j
public class GWeather extends Observable<GWeather, Race, WeatherType> {
private static final Logger LOGGER = LoggerFactory.getLogger(GWeather.class);
private WeatherType currentWeather;
public GWeather() {

View File

@ -23,12 +23,12 @@
package com.iluwatar.observer;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
/**
*
*
* Application test
*
*/

View File

@ -36,10 +36,10 @@ public class HobbitsTest extends WeatherObserverTest<Hobbits> {
@Override
public Collection<Object[]> dataProvider() {
return List.of(
new Object[]{WeatherType.SUNNY, "The hobbits are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The hobbits are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The hobbits are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The hobbits are facing Cold weather now"});
new Object[]{WeatherType.SUNNY, "The hobbits are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The hobbits are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The hobbits are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The hobbits are facing Cold weather now"});
}
/**

View File

@ -36,10 +36,10 @@ public class OrcsTest extends WeatherObserverTest<Orcs> {
@Override
public Collection<Object[]> dataProvider() {
return List.of(
new Object[]{WeatherType.SUNNY, "The orcs are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The orcs are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The orcs are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The orcs are facing Cold weather now"});
new Object[]{WeatherType.SUNNY, "The orcs are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The orcs are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The orcs are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The orcs are facing Cold weather now"});
}
/**

View File

@ -23,12 +23,6 @@
package com.iluwatar.observer;
import com.iluwatar.observer.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
@ -36,6 +30,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import com.iluwatar.observer.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Date: 12/27/15 - 11:08 AM
*
@ -60,7 +59,7 @@ public class WeatherTest {
* observer again and verify that there are no more notifications.
*/
@Test
public void testAddRemoveObserver() {
void testAddRemoveObserver() {
final var observer = mock(WeatherObserver.class);
final var weather = new Weather();
@ -83,7 +82,7 @@ public class WeatherTest {
* Verify if the weather passes in the order of the {@link WeatherType}s
*/
@Test
public void testTimePasses() {
void testTimePasses() {
final var observer = mock(WeatherObserver.class);
final var weather = new Weather();
weather.addObserver(observer);

View File

@ -38,10 +38,10 @@ public class GHobbitsTest extends ObserverTest<GHobbits> {
@Override
public Collection<Object[]> dataProvider() {
return List.of(
new Object[]{WeatherType.SUNNY, "The hobbits are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The hobbits are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The hobbits are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The hobbits are facing Cold weather now"}
new Object[]{WeatherType.SUNNY, "The hobbits are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The hobbits are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The hobbits are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The hobbits are facing Cold weather now"}
);
}

View File

@ -23,16 +23,19 @@
package com.iluwatar.observer.generic;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import com.iluwatar.observer.WeatherObserver;
import com.iluwatar.observer.WeatherType;
import com.iluwatar.observer.utils.InMemoryAppender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
/**
* Date: 12/27/15 - 11:08 AM
@ -58,7 +61,7 @@ public class GWeatherTest {
* observer again and verify that there are no more notifications.
*/
@Test
public void testAddRemoveObserver() {
void testAddRemoveObserver() {
final var observer = mock(Race.class);
final var weather = new GWeather();
@ -81,7 +84,7 @@ public class GWeatherTest {
* Verify if the weather passes in the order of the {@link WeatherType}s
*/
@Test
public void testTimePasses() {
void testTimePasses() {
final var observer = mock(Race.class);
final var weather = new GWeather();
weather.addObserver(observer);

View File

@ -38,10 +38,10 @@ public class OrcsTest extends ObserverTest<GOrcs> {
@Override
public Collection<Object[]> dataProvider() {
return List.of(
new Object[]{WeatherType.SUNNY, "The orcs are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The orcs are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The orcs are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The orcs are facing Cold weather now"}
new Object[]{WeatherType.SUNNY, "The orcs are facing Sunny weather now"},
new Object[]{WeatherType.RAINY, "The orcs are facing Rainy weather now"},
new Object[]{WeatherType.WINDY, "The orcs are facing Windy weather now"},
new Object[]{WeatherType.COLD, "The orcs are facing Cold weather now"}
);
}