@Test public void dequeEvents_withQueueSizeLessThanEventSendThreshhold_shouldDequeueQueueSize() throws Exception { when(mockQueue.size()).thenReturn(99); when(mockQueue.peek()).thenAnswer(new Answer<BaseEvent>() { int i; @Override public BaseEvent answer(InvocationOnMock invocation) throws Throwable { return i++ < 99 ? mockEvent : null; } }); when(mockQueue.poll()).thenAnswer(new Answer<BaseEvent>() { int i; @Override public BaseEvent answer(InvocationOnMock invocation) throws Throwable { return i++ < 99 ? mockEvent : null; } }); List<BaseEvent> events = subject.dequeueEvents(); verify(mockQueue, times(100)).peek(); verify(mockQueue, times(99)).poll(); assertThat(events.size()).isEqualTo(99); }
@VisibleForTesting @NonNull List<BaseEvent> dequeueEvents() { ArrayList<BaseEvent> baseEvents = new ArrayList<BaseEvent>(); while (mEventQueue.peek() != null && baseEvents.size() < EVENT_COUNT_SEND_THRESHHOLD) { baseEvents.add(mEventQueue.poll()); } return baseEvents; }
ScribeEventRecorder implements EventRecorder { @VisibleForTesting @NonNull List<BaseEvent> dequeueEvents() { ArrayList<BaseEvent> baseEvents = new ArrayList<BaseEvent>(); while (mEventQueue.peek() != null && baseEvents.size() < EVENT_COUNT_SEND_THRESHHOLD) { baseEvents.add(mEventQueue.poll()); } return baseEvents; } }
ScribeEventRecorder implements EventRecorder { @VisibleForTesting @NonNull List<BaseEvent> dequeueEvents() { ArrayList<BaseEvent> baseEvents = new ArrayList<BaseEvent>(); while (mEventQueue.peek() != null && baseEvents.size() < EVENT_COUNT_SEND_THRESHHOLD) { baseEvents.add(mEventQueue.poll()); } return baseEvents; } ScribeEventRecorder(@NonNull Looper looper); @VisibleForTesting  ScribeEventRecorder(@NonNull EventSampler eventSampler,
            @NonNull Queue<BaseEvent> eventQueue,
            @NonNull EventSerializer eventSerializer,
            @NonNull ScribeRequestManager scribeRequestManager,
            @NonNull Handler handler); }
ScribeEventRecorder implements EventRecorder { @VisibleForTesting @NonNull List<BaseEvent> dequeueEvents() { ArrayList<BaseEvent> baseEvents = new ArrayList<BaseEvent>(); while (mEventQueue.peek() != null && baseEvents.size() < EVENT_COUNT_SEND_THRESHHOLD) { baseEvents.add(mEventQueue.poll()); } return baseEvents; } ScribeEventRecorder(@NonNull Looper looper); @VisibleForTesting  ScribeEventRecorder(@NonNull EventSampler eventSampler,
            @NonNull Queue<BaseEvent> eventQueue,
            @NonNull EventSerializer eventSerializer,
            @NonNull ScribeRequestManager scribeRequestManager,
            @NonNull Handler handler); @Override void record(@NonNull BaseEvent baseEvent); }
ScribeEventRecorder implements EventRecorder { @VisibleForTesting @NonNull List<BaseEvent> dequeueEvents() { ArrayList<BaseEvent> baseEvents = new ArrayList<BaseEvent>(); while (mEventQueue.peek() != null && baseEvents.size() < EVENT_COUNT_SEND_THRESHHOLD) { baseEvents.add(mEventQueue.poll()); } return baseEvents; } ScribeEventRecorder(@NonNull Looper looper); @VisibleForTesting  ScribeEventRecorder(@NonNull EventSampler eventSampler,
            @NonNull Queue<BaseEvent> eventQueue,
            @NonNull EventSerializer eventSerializer,
            @NonNull ScribeRequestManager scribeRequestManager,
            @NonNull Handler handler); @Override void record(@NonNull BaseEvent baseEvent);  }