mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 15:26:01 +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:
@@ -34,12 +34,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public final class App {
|
||||
|
||||
private App() {
|
||||
}
|
||||
private App() {}
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
/** Program entry point. */
|
||||
public static void main(final String[] args) {
|
||||
var task = new SimpleTask();
|
||||
task.executeWith(() -> LOGGER.info("I'm done now."));
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.callback;
|
||||
|
||||
/**
|
||||
* Callback interface.
|
||||
*/
|
||||
/** Callback interface. */
|
||||
public interface Callback {
|
||||
|
||||
void call();
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.callback;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Implementation of task that need to be executed.
|
||||
*/
|
||||
/** Implementation of task that need to be executed. */
|
||||
@Slf4j
|
||||
public final class SimpleTask extends Task {
|
||||
|
||||
|
||||
@@ -26,14 +26,10 @@ package com.iluwatar.callback;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Template-method class for callback hook execution.
|
||||
*/
|
||||
/** Template-method class for callback hook execution. */
|
||||
public abstract class Task {
|
||||
|
||||
/**
|
||||
* Execute with callback.
|
||||
*/
|
||||
/** Execute with callback. */
|
||||
final void executeWith(Callback callback) {
|
||||
execute();
|
||||
Optional.ofNullable(callback).ifPresent(Callback::call);
|
||||
|
||||
@@ -24,25 +24,22 @@
|
||||
*/
|
||||
package com.iluwatar.callback;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Tests that Callback example runs without errors.
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Tests that Callback example runs without errors. */
|
||||
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(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* Add a field as a counter. Every time the callback method is called increment this field. Unit
|
||||
* test checks that the field is being incremented.
|
||||
* <p>
|
||||
* Could be done with mock objects as well where the call method call is verified.
|
||||
*
|
||||
* <p>Could be done with mock objects as well where the call method call is verified.
|
||||
*/
|
||||
class CallbackTest {
|
||||
|
||||
@@ -53,6 +53,5 @@ class CallbackTest {
|
||||
task.executeWith(callback);
|
||||
|
||||
assertEquals(Integer.valueOf(2), callingCount, "Callback called twice");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user