mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-20 02:28:08 +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:
@@ -27,13 +27,10 @@ package com.iluwatar.flux.action;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Action is the data payload dispatched to the stores when something happens.
|
||||
*/
|
||||
/** Action is the data payload dispatched to the stores when something happens. */
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public abstract class Action {
|
||||
|
||||
private final ActionType type;
|
||||
|
||||
}
|
||||
|
||||
@@ -24,12 +24,8 @@
|
||||
*/
|
||||
package com.iluwatar.flux.action;
|
||||
|
||||
/**
|
||||
* Types of actions.
|
||||
*/
|
||||
/** Types of actions. */
|
||||
public enum ActionType {
|
||||
|
||||
MENU_ITEM_SELECTED,
|
||||
CONTENT_CHANGED
|
||||
|
||||
}
|
||||
|
||||
@@ -26,12 +26,9 @@ package com.iluwatar.flux.action;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Content items.
|
||||
*/
|
||||
/** Content items. */
|
||||
@RequiredArgsConstructor
|
||||
public enum Content {
|
||||
|
||||
PRODUCTS("Products - This page lists the company's products."),
|
||||
COMPANY("Company - This page displays information about the company.");
|
||||
|
||||
|
||||
@@ -26,13 +26,10 @@ package com.iluwatar.flux.action;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ContentAction is a concrete action.
|
||||
*/
|
||||
/** ContentAction is a concrete action. */
|
||||
public class ContentAction extends Action {
|
||||
|
||||
@Getter
|
||||
private final Content content;
|
||||
@Getter private final Content content;
|
||||
|
||||
public ContentAction(Content content) {
|
||||
super(ActionType.CONTENT_CHANGED);
|
||||
|
||||
@@ -24,16 +24,12 @@
|
||||
*/
|
||||
package com.iluwatar.flux.action;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* MenuAction is a concrete action.
|
||||
*/
|
||||
/** MenuAction is a concrete action. */
|
||||
public class MenuAction extends Action {
|
||||
|
||||
@Getter
|
||||
private final MenuItem menuItem;
|
||||
@Getter private final MenuItem menuItem;
|
||||
|
||||
public MenuAction(MenuItem menuItem) {
|
||||
super(ActionType.MENU_ITEM_SELECTED);
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.flux.action;
|
||||
|
||||
/**
|
||||
* Menu items.
|
||||
*/
|
||||
/** Menu items. */
|
||||
public enum MenuItem {
|
||||
|
||||
HOME("Home"), PRODUCTS("Products"), COMPANY("Company");
|
||||
HOME("Home"),
|
||||
PRODUCTS("Products"),
|
||||
COMPANY("Company");
|
||||
|
||||
private final String title;
|
||||
|
||||
|
||||
@@ -34,26 +34,20 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Dispatcher sends Actions to registered Stores.
|
||||
*/
|
||||
/** Dispatcher sends Actions to registered Stores. */
|
||||
public final class Dispatcher {
|
||||
|
||||
@Getter
|
||||
private static Dispatcher instance = new Dispatcher();
|
||||
@Getter private static Dispatcher instance = new Dispatcher();
|
||||
|
||||
private final List<Store> stores = new LinkedList<>();
|
||||
|
||||
private Dispatcher() {
|
||||
}
|
||||
private Dispatcher() {}
|
||||
|
||||
public void registerStore(Store store) {
|
||||
stores.add(store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu item selected handler.
|
||||
*/
|
||||
/** Menu item selected handler. */
|
||||
public void menuItemSelected(MenuItem menuItem) {
|
||||
dispatchAction(new MenuAction(menuItem));
|
||||
if (menuItem == MenuItem.COMPANY) {
|
||||
|
||||
@@ -30,13 +30,10 @@ import com.iluwatar.flux.action.Content;
|
||||
import com.iluwatar.flux.action.ContentAction;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ContentStore is a concrete store.
|
||||
*/
|
||||
/** ContentStore is a concrete store. */
|
||||
public class ContentStore extends Store {
|
||||
|
||||
@Getter
|
||||
private Content content = Content.PRODUCTS;
|
||||
@Getter private Content content = Content.PRODUCTS;
|
||||
|
||||
@Override
|
||||
public void onAction(Action action) {
|
||||
|
||||
@@ -30,13 +30,10 @@ import com.iluwatar.flux.action.MenuAction;
|
||||
import com.iluwatar.flux.action.MenuItem;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* MenuStore is a concrete store.
|
||||
*/
|
||||
/** MenuStore is a concrete store. */
|
||||
public class MenuStore extends Store {
|
||||
|
||||
@Getter
|
||||
private MenuItem selected = MenuItem.HOME;
|
||||
@Getter private MenuItem selected = MenuItem.HOME;
|
||||
|
||||
@Override
|
||||
public void onAction(Action action) {
|
||||
|
||||
@@ -29,9 +29,7 @@ import com.iluwatar.flux.view.View;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Store is a data model.
|
||||
*/
|
||||
/** Store is a data model. */
|
||||
public abstract class Store {
|
||||
|
||||
private final List<View> views = new LinkedList<>();
|
||||
|
||||
@@ -29,9 +29,7 @@ import com.iluwatar.flux.store.ContentStore;
|
||||
import com.iluwatar.flux.store.Store;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* ContentView is a concrete view.
|
||||
*/
|
||||
/** ContentView is a concrete view. */
|
||||
@Slf4j
|
||||
public class ContentView implements View {
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ import com.iluwatar.flux.store.MenuStore;
|
||||
import com.iluwatar.flux.store.Store;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* MenuView is a concrete view.
|
||||
*/
|
||||
/** MenuView is a concrete view. */
|
||||
@Slf4j
|
||||
public class MenuView implements View {
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.flux.view;
|
||||
|
||||
import com.iluwatar.flux.store.Store;
|
||||
|
||||
/**
|
||||
* Views define the representation of data.
|
||||
*/
|
||||
/** Views define the representation of data. */
|
||||
public interface View {
|
||||
|
||||
void storeChanged(Store store);
|
||||
|
||||
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ContentTest
|
||||
*
|
||||
*/
|
||||
/** ContentTest */
|
||||
class ContentTest {
|
||||
|
||||
@Test
|
||||
@@ -43,5 +40,4 @@ class ContentTest {
|
||||
assertFalse(toString.trim().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,10 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* MenuItemTest
|
||||
*
|
||||
*/
|
||||
/** MenuItemTest */
|
||||
class MenuItemTest {
|
||||
|
||||
@Test
|
||||
@@ -43,5 +40,4 @@ class MenuItemTest {
|
||||
assertFalse(toString.trim().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.flux.app;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Application test */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
/**
|
||||
* DispatcherTest
|
||||
*
|
||||
*/
|
||||
/** DispatcherTest */
|
||||
class DispatcherTest {
|
||||
|
||||
/**
|
||||
@@ -85,28 +82,37 @@ class DispatcherTest {
|
||||
verifyNoMoreInteractions(store);
|
||||
|
||||
final var actions = actionCaptor.getAllValues();
|
||||
final var menuActions = actions.stream()
|
||||
.filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
|
||||
.map(a -> (MenuAction) a)
|
||||
.toList();
|
||||
final var menuActions =
|
||||
actions.stream()
|
||||
.filter(a -> a.getType().equals(ActionType.MENU_ITEM_SELECTED))
|
||||
.map(a -> (MenuAction) a)
|
||||
.toList();
|
||||
|
||||
final var contentActions = actions.stream()
|
||||
.filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
|
||||
.map(a -> (ContentAction) a)
|
||||
.toList();
|
||||
final var contentActions =
|
||||
actions.stream()
|
||||
.filter(a -> a.getType().equals(ActionType.CONTENT_CHANGED))
|
||||
.map(a -> (ContentAction) a)
|
||||
.toList();
|
||||
|
||||
assertEquals(2, menuActions.size());
|
||||
assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals)
|
||||
.count());
|
||||
assertEquals(1, menuActions.stream().map(MenuAction::getMenuItem)
|
||||
.filter(MenuItem.COMPANY::equals).count());
|
||||
assertEquals(
|
||||
1, menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.HOME::equals).count());
|
||||
assertEquals(
|
||||
1,
|
||||
menuActions.stream().map(MenuAction::getMenuItem).filter(MenuItem.COMPANY::equals).count());
|
||||
|
||||
assertEquals(2, contentActions.size());
|
||||
assertEquals(1, contentActions.stream().map(ContentAction::getContent)
|
||||
.filter(Content.PRODUCTS::equals).count());
|
||||
assertEquals(1, contentActions.stream().map(ContentAction::getContent)
|
||||
.filter(Content.COMPANY::equals).count());
|
||||
|
||||
assertEquals(
|
||||
1,
|
||||
contentActions.stream()
|
||||
.map(ContentAction::getContent)
|
||||
.filter(Content.PRODUCTS::equals)
|
||||
.count());
|
||||
assertEquals(
|
||||
1,
|
||||
contentActions.stream()
|
||||
.map(ContentAction::getContent)
|
||||
.filter(Content.COMPANY::equals)
|
||||
.count());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ import com.iluwatar.flux.action.MenuItem;
|
||||
import com.iluwatar.flux.view.View;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ContentStoreTest
|
||||
*
|
||||
*/
|
||||
/** ContentStoreTest */
|
||||
class ContentStoreTest {
|
||||
|
||||
@Test
|
||||
@@ -62,7 +59,5 @@ class ContentStoreTest {
|
||||
verify(view, times(1)).storeChanged(eq(contentStore));
|
||||
verifyNoMoreInteractions(view);
|
||||
assertEquals(Content.COMPANY, contentStore.getContent());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ import com.iluwatar.flux.action.MenuItem;
|
||||
import com.iluwatar.flux.view.View;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* MenuStoreTest
|
||||
*
|
||||
*/
|
||||
/** MenuStoreTest */
|
||||
class MenuStoreTest {
|
||||
|
||||
@Test
|
||||
@@ -62,7 +59,5 @@ class MenuStoreTest {
|
||||
verify(view, times(1)).storeChanged(eq(menuStore));
|
||||
verifyNoMoreInteractions(view);
|
||||
assertEquals(MenuItem.PRODUCTS, menuStore.getSelected());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,10 +34,7 @@ import com.iluwatar.flux.action.Content;
|
||||
import com.iluwatar.flux.store.ContentStore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ContentViewTest
|
||||
*
|
||||
*/
|
||||
/** ContentViewTest */
|
||||
class ContentViewTest {
|
||||
|
||||
@Test
|
||||
@@ -51,5 +48,4 @@ class ContentViewTest {
|
||||
verify(store, times(1)).getContent();
|
||||
verifyNoMoreInteractions(store);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ import com.iluwatar.flux.store.MenuStore;
|
||||
import com.iluwatar.flux.store.Store;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* MenuViewTest
|
||||
*
|
||||
*/
|
||||
/** MenuViewTest */
|
||||
class MenuViewTest {
|
||||
|
||||
@Test
|
||||
@@ -66,7 +63,5 @@ class MenuViewTest {
|
||||
|
||||
// We should receive a menu click action and a content changed action
|
||||
verify(store, times(2)).onAction(any(Action.class));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user