mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-03 22:17:14 +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.balking;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* An interface to simulate delay while executing some work.
|
||||
*/
|
||||
/** An interface to simulate delay while executing some work. */
|
||||
public interface DelayProvider {
|
||||
void executeAfterDelay(long interval, TimeUnit timeUnit, Runnable task);
|
||||
}
|
||||
|
||||
@@ -28,30 +28,26 @@ import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Washing machine class.
|
||||
*/
|
||||
/** Washing machine class. */
|
||||
@Slf4j
|
||||
public class WashingMachine {
|
||||
|
||||
private final DelayProvider delayProvider;
|
||||
|
||||
@Getter
|
||||
private WashingMachineState washingMachineState;
|
||||
@Getter private WashingMachineState washingMachineState;
|
||||
|
||||
/**
|
||||
* Creates a new instance of WashingMachine.
|
||||
*/
|
||||
/** Creates a new instance of WashingMachine. */
|
||||
public WashingMachine() {
|
||||
this((interval, timeUnit, task) -> {
|
||||
try {
|
||||
Thread.sleep(timeUnit.toMillis(interval));
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("", ie);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
task.run();
|
||||
});
|
||||
this(
|
||||
(interval, timeUnit, task) -> {
|
||||
try {
|
||||
Thread.sleep(timeUnit.toMillis(interval));
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("", ie);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
task.run();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +59,7 @@ public class WashingMachine {
|
||||
this.washingMachineState = WashingMachineState.ENABLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method responsible for washing if the object is in appropriate state.
|
||||
*/
|
||||
/** Method responsible for washing if the object is in appropriate state. */
|
||||
public void wash() {
|
||||
synchronized (this) {
|
||||
var machineState = getWashingMachineState();
|
||||
@@ -81,12 +75,9 @@ public class WashingMachine {
|
||||
this.delayProvider.executeAfterDelay(50, TimeUnit.MILLISECONDS, this::endOfWashing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is responsible for ending the washing by changing machine state.
|
||||
*/
|
||||
/** Method is responsible for ending the washing by changing machine state. */
|
||||
public synchronized void endOfWashing() {
|
||||
washingMachineState = WashingMachineState.ENABLED;
|
||||
LOGGER.info("{}: Washing completed.", Thread.currentThread().getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,27 +24,22 @@
|
||||
*/
|
||||
package com.iluwatar.balking;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
/** Application test */
|
||||
class AppTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
*
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
|
||||
* throws an exception.
|
||||
* <p>Solution: Inserted assertion to check whether the execution of the main method in {@link
|
||||
* App} throws an exception.
|
||||
*/
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow((Executable) App::main);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link WashingMachine}
|
||||
*/
|
||||
/** Tests for {@link WashingMachine} */
|
||||
class WashingMachineTest {
|
||||
|
||||
private final FakeDelayProvider fakeDelayProvider = new FakeDelayProvider();
|
||||
@@ -69,4 +67,4 @@ class WashingMachineTest {
|
||||
this.task = task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user