public BalanceUnderMinimumEventListener(final SupportedListener listener, final AbstractTargetHandler handler) { super(listener, handler); this.minimumBalance = handler.getListenerSpecificIntProperty(SupportedListener.BALANCE_UNDER_MINIMUM, "minimumBalance", 200); }
public BalanceOnTargetEventListener(final SupportedListener listener, final AbstractTargetHandler handler) { super(listener, handler); this.targetBalance = handler.getListenerSpecificIntProperty(SupportedListener.BALANCE_ON_TARGET, "targetBalance", 200); }
public BalanceUnderMinimumEventListener(final SupportedListener listener, final AbstractTargetHandler handler) { super(listener, handler); this.minimumBalance = handler.getListenerSpecificIntProperty(SupportedListener.BALANCE_UNDER_MINIMUM, "minimumBalance", 200); }
public BalanceOnTargetEventListener(final SupportedListener listener, final AbstractTargetHandler handler) { super(listener, handler); this.targetBalance = handler.getListenerSpecificIntProperty(SupportedListener.BALANCE_ON_TARGET, "targetBalance", 200); }
private int getHourlyLimit(final SupportedListener listener) { return this.getListenerSpecificIntProperty(listener, HOURLY_LIMIT, Integer.MAX_VALUE); }
private int getHourlyLimit(final SupportedListener listener) { return this.getListenerSpecificIntProperty(listener, HOURLY_LIMIT, Integer.MAX_VALUE); }
public int getListenerSpecificIntProperty(final SupportedListener listener, final String property, final int defaultValue) { return this.getListenerSpecificIntProperty(listener, property).orElse(defaultValue); }
public int getListenerSpecificIntProperty(final SupportedListener listener, final String property, final int defaultValue) { return this.getListenerSpecificIntProperty(listener, property).orElse(defaultValue); }
@Test void check() throws Exception { final AbstractTargetHandler h = mock(AbstractTargetHandler.class); doNothing().when(h).offer(any()); when(h.getTarget()).thenReturn(Target.EMAIL); when(h.getListenerSpecificIntProperty(eq(SupportedListener.BALANCE_ON_TARGET), eq("targetBalance"), anyInt())) .thenAnswer(i -> i.getArgument(2)); final PortfolioOverview p = mockPortfolioOverview(1000); final ExecutionStartedEvent evt = new TestingExecutionStartedEvent(p); final AbstractListener<ExecutionStartedEvent> l = new BalanceOnTargetEventListener(SupportedListener.BALANCE_ON_TARGET, h); l.handle(evt, SESSION_INFO); // balance change verify(h, times(1)).offer(any()); l.handle(evt, SESSION_INFO); // no change, no notification verify(h, times(1)).offer(any()); final PortfolioOverview p2 = mockPortfolioOverview(0); final ExecutionStartedEvent evt2 = new TestingExecutionStartedEvent(p2); l.handle(evt2, SESSION_INFO); // no change, no notification verify(h, times(1)).offer(any()); l.handle(evt, SESSION_INFO); // back over threshold, send notification verify(h, times(2)).offer(any()); } }
@Test void check() throws Exception { final AbstractTargetHandler h = mock(AbstractTargetHandler.class); doNothing().when(h).offer(any()); when(h.getTarget()).thenReturn(Target.EMAIL); when(h.getListenerSpecificIntProperty(eq(SupportedListener.BALANCE_UNDER_MINIMUM), eq("minimumBalance"), anyInt())) .thenAnswer(i -> i.getArgument(2)); final PortfolioOverview p = mockPortfolioOverview(1); final ExecutionStartedEvent evt = new TestingExecutionStartedEvent(p); final AbstractListener<ExecutionStartedEvent> l = new BalanceUnderMinimumEventListener(SupportedListener.BALANCE_UNDER_MINIMUM, h); l.handle(evt, SESSION_INFO); // balance change verify(h, times(1)).offer(any()); l.handle(evt, SESSION_INFO); // no change, no notification verify(h, times(1)).offer(any()); final PortfolioOverview p2 = mockPortfolioOverview(1000); final ExecutionStartedEvent evt2 = new TestingExecutionStartedEvent(p2); l.handle(evt2, SESSION_INFO); // no change, no notification verify(h, times(1)).offer(any()); l.handle(evt, SESSION_INFO); // back over threshold, send notification verify(h, times(2)).offer(any()); } }