ListDirectoryObserver extends DisposableObserver<File> { @Override public void onComplete() { dataSet.directoryList.sort(); if(dataSet.getParentDirectory() !=null) { dataSet.directoryList.add(0, dataSet.getParentDirectory()); } bus.post(new DataSetChangedEvent()); Log.d("TAG", "onCompleted ListDirectoryObserver"); } ListDirectoryObserver(DirectoryTree dataSet, EventBus bus); @Override void onComplete(); @Override void onError(Throwable e); @Override void onNext(File file);  }
@Test public void onCompleteShouldSortDirectoryTree() throws Exception { DirectoryList spyDirectoryList = spy(new DirectoryList()); directoryTree.directoryList = spyDirectoryList; sut.onComplete(); verify(directoryTree.directoryList).sort(); }
@Test public void onCompleteShouldAddParentDirectoryIfExists() throws Exception { File mockParentFile = mock(File.class); directoryTree.setParentDirectory(mockParentFile); sut.onComplete(); assertThat(directoryTree.directoryList.get(0), is(mockParentFile)); }
@Test public void onCompleteShouldNotAddMissingParent() throws Exception { directoryTree.setParentDirectory(null); sut.onComplete(); assertTrue(directoryTree.directoryList.isEmpty()); }
@Test public void onCompleteShouldNotifyDataSetChanged() throws Exception { sut.onComplete(); verify(mockBus).post(any(DataSetChangedEvent.class)); }