mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-24 17:34:57 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -26,9 +26,7 @@ package com.iluwatar.observer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Hobbits.
|
||||
*/
|
||||
/** Hobbits. */
|
||||
@Slf4j
|
||||
public class Hobbits implements WeatherObserver {
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.observer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Orcs.
|
||||
*/
|
||||
/** Orcs. */
|
||||
@Slf4j
|
||||
public class Orcs implements WeatherObserver {
|
||||
|
||||
|
||||
@@ -51,9 +51,7 @@ public class Weather {
|
||||
observers.remove(obs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes time pass for weather.
|
||||
*/
|
||||
/** Makes time pass for weather. */
|
||||
public void timePasses() {
|
||||
var enumValues = WeatherType.values();
|
||||
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
/**
|
||||
* Observer interface.
|
||||
*/
|
||||
public interface WeatherObserver {
|
||||
|
||||
void update(WeatherType currentWeather);
|
||||
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
/** Observer interface. */
|
||||
public interface WeatherObserver {
|
||||
|
||||
void update(WeatherType currentWeather);
|
||||
}
|
||||
|
||||
@@ -24,18 +24,16 @@
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import lombok.Getter; /**
|
||||
* WeatherType enumeration.
|
||||
*/
|
||||
public enum WeatherType {
|
||||
import lombok.Getter;
|
||||
|
||||
/** WeatherType enumeration. */
|
||||
public enum WeatherType {
|
||||
SUNNY("Sunny"),
|
||||
RAINY("Rainy"),
|
||||
WINDY("Windy"),
|
||||
COLD("Cold");
|
||||
|
||||
@Getter
|
||||
private final String description;
|
||||
@Getter private final String description;
|
||||
|
||||
WeatherType(String description) {
|
||||
this.description = description;
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.observer.generic;
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GHobbits.
|
||||
*/
|
||||
/** GHobbits. */
|
||||
@Slf4j
|
||||
public class GenHobbits implements Race {
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.observer.generic;
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GOrcs.
|
||||
*/
|
||||
/** GOrcs. */
|
||||
@Slf4j
|
||||
public class GenOrcs implements Race {
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.observer.generic;
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GWeather.
|
||||
*/
|
||||
/** GWeather. */
|
||||
@Slf4j
|
||||
public class GenWeather extends Observable<GenWeather, Race, WeatherType> {
|
||||
|
||||
@@ -39,9 +37,7 @@ public class GenWeather extends Observable<GenWeather, Race, WeatherType> {
|
||||
currentWeather = WeatherType.SUNNY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes time pass for weather.
|
||||
*/
|
||||
/** Makes time pass for weather. */
|
||||
public void timePasses() {
|
||||
var enumValues = WeatherType.values();
|
||||
currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
|
||||
|
||||
@@ -50,9 +50,7 @@ public abstract class Observable<S extends Observable<S, O, A>, O extends Observ
|
||||
this.observers.remove(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify observers.
|
||||
*/
|
||||
/** Notify observers. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public void notifyObservers(A argument) {
|
||||
for (var observer : observers) {
|
||||
|
||||
@@ -26,8 +26,5 @@ package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
|
||||
/**
|
||||
* Race.
|
||||
*/
|
||||
public interface Race extends Observer<GenWeather, Race, WeatherType> {
|
||||
}
|
||||
/** Race. */
|
||||
public interface Race extends Observer<GenWeather, Race, WeatherType> {}
|
||||
|
||||
@@ -28,13 +28,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Application test.
|
||||
*/
|
||||
/** Application test. */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,26 +27,20 @@ package com.iluwatar.observer;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HobbitsTest
|
||||
*
|
||||
*/
|
||||
/** HobbitsTest */
|
||||
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"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*/
|
||||
/** Create a new test with the given weather and expected response */
|
||||
public HobbitsTest() {
|
||||
super(Hobbits::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,26 +27,20 @@ package com.iluwatar.observer;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OrcsTest
|
||||
*
|
||||
*/
|
||||
/** OrcsTest */
|
||||
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"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*/
|
||||
/** Create a new test with the given weather and expected response */
|
||||
public OrcsTest() {
|
||||
super(Orcs::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Weather Observer Tests
|
||||
*
|
||||
* @param <O> Type of WeatherObserver
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@@ -54,15 +55,13 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* The observer instance factory
|
||||
*/
|
||||
/** The observer instance factory */
|
||||
private final Supplier<O> factory;
|
||||
|
||||
/**
|
||||
* Create a new test instance using the given parameters
|
||||
*
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
*/
|
||||
WeatherObserverTest(final Supplier<O> factory) {
|
||||
this.factory = factory;
|
||||
@@ -70,9 +69,7 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||
|
||||
public abstract Collection<Object[]> dataProvider();
|
||||
|
||||
/**
|
||||
* Verify if the weather has the expected influence on the observer
|
||||
*/
|
||||
/** Verify if the weather has the expected influence on the observer */
|
||||
@ParameterizedTest
|
||||
@MethodSource("dataProvider")
|
||||
void testObserver(WeatherType weather, String response) {
|
||||
@@ -83,5 +80,4 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||
assertEquals(response, appender.getLastMessage());
|
||||
assertEquals(1, appender.getLogSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,10 +35,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* WeatherTest
|
||||
*
|
||||
*/
|
||||
/** WeatherTest */
|
||||
class WeatherTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
@@ -77,9 +74,7 @@ class WeatherTest {
|
||||
assertEquals(2, appender.getLogSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the weather passes in the order of the {@link WeatherType}s
|
||||
*/
|
||||
/** Verify if the weather passes in the order of the {@link WeatherType}s */
|
||||
@Test
|
||||
void testTimePasses() {
|
||||
final var observer = mock(WeatherObserver.class);
|
||||
@@ -95,5 +90,4 @@ class WeatherTest {
|
||||
|
||||
verifyNoMoreInteractions(observer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,26 +28,20 @@ import com.iluwatar.observer.WeatherType;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* GHobbitsTest.
|
||||
*/
|
||||
/** GHobbitsTest. */
|
||||
class GHobbitsTest extends ObserverTest<GenHobbits> {
|
||||
|
||||
@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"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response.
|
||||
*/
|
||||
/** Create a new test with the given weather and expected response. */
|
||||
public GHobbitsTest() {
|
||||
super(GenHobbits::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* GWeatherTest
|
||||
*
|
||||
*/
|
||||
/** GWeatherTest */
|
||||
class GWeatherTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
@@ -79,9 +76,7 @@ class GWeatherTest {
|
||||
assertEquals(2, appender.getLogSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the weather passes in the order of the {@link WeatherType}s
|
||||
*/
|
||||
/** Verify if the weather passes in the order of the {@link WeatherType}s */
|
||||
@Test
|
||||
void testTimePasses() {
|
||||
final var observer = mock(Race.class);
|
||||
@@ -97,5 +92,4 @@ class GWeatherTest {
|
||||
|
||||
verifyNoMoreInteractions(observer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,21 +24,21 @@
|
||||
*/
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test for Observers
|
||||
*
|
||||
* @param <O> Type of Observer
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@@ -56,15 +56,13 @@ public abstract class ObserverTest<O extends Observer<?, ?, WeatherType>> {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* The observer instance factory
|
||||
*/
|
||||
/** The observer instance factory */
|
||||
private final Supplier<O> factory;
|
||||
|
||||
/**
|
||||
* Create a new test instance using the given parameters
|
||||
*
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
*/
|
||||
ObserverTest(final Supplier<O> factory) {
|
||||
this.factory = factory;
|
||||
@@ -72,9 +70,7 @@ public abstract class ObserverTest<O extends Observer<?, ?, WeatherType>> {
|
||||
|
||||
public abstract Collection<Object[]> dataProvider();
|
||||
|
||||
/**
|
||||
* Verify if the weather has the expected influence on the observer
|
||||
*/
|
||||
/** Verify if the weather has the expected influence on the observer */
|
||||
@ParameterizedTest
|
||||
@MethodSource("dataProvider")
|
||||
void testObserver(WeatherType weather, String response) {
|
||||
@@ -85,5 +81,4 @@ public abstract class ObserverTest<O extends Observer<?, ?, WeatherType>> {
|
||||
assertEquals(response, appender.getLastMessage());
|
||||
assertEquals(1, appender.getLogSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,27 +28,20 @@ import com.iluwatar.observer.WeatherType;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OrcsTest
|
||||
*
|
||||
*/
|
||||
/** OrcsTest */
|
||||
class OrcsTest extends ObserverTest<GenOrcs> {
|
||||
|
||||
@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"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*/
|
||||
/** Create a new test with the given weather and expected response */
|
||||
public OrcsTest() {
|
||||
super(GenOrcs::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* InMemory Log Appender Util.
|
||||
*/
|
||||
/** InMemory Log Appender Util. */
|
||||
public class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user