@Test public void triggerPush_WhenCallTimeoutIsReached_ShouldNotTriggerPush() { final BingRule bingRule = Mockito.mock(BingRule.class); Mockito.when(bingRule.shouldNotify()).thenReturn(true); Mockito.when(mBingRulesManager.fulfilledBingRule(Mockito.any(Event.class))).thenReturn(bingRule); final Event event = new Event(); event.type = Event.EVENT_TYPE_CALL_INVITE; event.originServerTs = System.currentTimeMillis() - 124000; final RoomState roomState = new RoomState(); mTimelinePushWorker.triggerPush(roomState, event); Mockito.verify(mDataHandler, Mockito.never()).onBingEvent(event, roomState, bingRule); }
@Test public void triggerPush_WhenEventBingRuleDoesNotAllowNotify_ShouldNotTriggerPush() { final BingRule bingRule = Mockito.mock(BingRule.class); Mockito.when(bingRule.shouldNotify()).thenReturn(false); Mockito.when(mBingRulesManager.fulfilledBingRule(Mockito.any(Event.class))).thenReturn(bingRule); final Event event = new Event(); final RoomState roomState = new RoomState(); mTimelinePushWorker.triggerPush(roomState, event); Mockito.verify(mDataHandler, Mockito.never()).onBingEvent(event, roomState, bingRule); }
@Test public void triggerPush_WhenEventHasNoLifetime_ShouldTriggerPush() { final BingRule bingRule = Mockito.mock(BingRule.class); Mockito.when(bingRule.shouldNotify()).thenReturn(true); Mockito.when(mBingRulesManager.fulfilledBingRule(Mockito.any(Event.class))).thenReturn(bingRule); final Event event = new Event(); final RoomState roomState = new RoomState(); mTimelinePushWorker.triggerPush(roomState, event); Mockito.verify(mDataHandler).onBingEvent(event, roomState, bingRule); }
@Test public void triggerPush_WhenCallTimeoutIsNotReached_ShouldTriggerPush() { final BingRule bingRule = Mockito.mock(BingRule.class); Mockito.when(bingRule.shouldNotify()).thenReturn(true); Mockito.when(mBingRulesManager.fulfilledBingRule(Mockito.any(Event.class))).thenReturn(bingRule); final Event event = new Event(); event.type = Event.EVENT_TYPE_CALL_INVITE; event.originServerTs = System.currentTimeMillis() - 8000; final RoomState roomState = new RoomState(); mTimelinePushWorker.triggerPush(roomState, event); Mockito.verify(mDataHandler).onBingEvent(event, roomState, bingRule); } }
@Test public void triggerPush_WhenMaxLifetimeIsReached_ShouldNotTriggerPush() { final Gson gson = JsonUtils.getBasicGson(); final BingRule bingRule = Mockito.mock(BingRule.class); Mockito.when(bingRule.shouldNotify()).thenReturn(true); Mockito.when(mBingRulesManager.fulfilledBingRule(Mockito.any(Event.class))).thenReturn(bingRule); final Event event = new Event(); Map<String, String> contentMap = new HashMap<>(); contentMap.put("lifetime", "10000"); event.content = gson.toJsonTree(contentMap); event.originServerTs = System.currentTimeMillis() - 50000; final RoomState roomState = new RoomState(); mTimelinePushWorker.triggerPush(roomState, event); Mockito.verify(mDataHandler, Mockito.never()).onBingEvent(event, roomState, bingRule); }
mDataHandler.onBingEvent(event, state, bingRule); } else { Log.d(LOG_TAG, "rule id " + bingRule.ruleId + " event id " + event.eventId