EventHelper { public void recordEvent(AccessibilityNodeInfo source) { if (source != null) { AccessibilityNodeInfo lastSource = swapper.swap(source); if (lastSource != null) { lastSource.recycle(); } } } EventHelper(ThreadSafeSwapper<AccessibilityNodeInfo> swapper); void recordEvent(AccessibilityNodeInfo source); AccessibilityNodeInfo claimLastSource(); boolean restoreLastSource(AccessibilityNodeInfo previousSource);  }
@Test public void recordEventProperlyHandlesNonNullEventSource() { when(mockSwapper.swap(mockNodeInfo)).thenReturn(mockLastNodeInfo); testSubject.recordEvent(mockNodeInfo); verify(mockLastNodeInfo, times(1)).recycle(); }
@Test public void recordEventProperlyHandlesNullEventSource() { testSubject.recordEvent(null); verify(mockSwapper, times(0)).swap(mockNodeInfo); verify(mockLastNodeInfo, times(0)).recycle(); }
@Test public void recordEventProperlyHandlesNullLastSource() { when(mockSwapper.swap(mockNodeInfo)).thenReturn(null); testSubject.recordEvent(mockNodeInfo); verify(mockLastNodeInfo, times(0)).recycle(); }