### Question:
SnapshotTaker { public void execute(SnapshotInfo info) { this.info = info; if (info.getChangeType() == ChangeType.FILE_RENAME || info.getChangeType() == ChangeType.FOLDER_RENAME) { handleRename(); } else { handleChange(); } } SnapshotTaker(ActiveThreadSet threadSet, EventReceiver receiver, Settings settings, ProjectDAO projectDAO); void execute(SnapshotInfo info);  }### Answer:
@Test public void receiverDoesNotReceiveEventIfSpywareIsDisabled() throws IOException, InterruptedException { when(settings.isSpywareEnabled()).thenReturn(false); taker.execute(new SnapshotInfo("testProject", "", relPath, "", fullPath, ChangeType.FILE_CHANGE)); Thread.sleep(50); assertEquals(event, null); }
@Test public void receiverDoesNotReceiveEventIfProjectIsNull() throws IOException, InterruptedException { ProjectDAO dao = mock(ProjectDAO.class); when(dao.getProjectByFile(any(String.class))).thenReturn(null); this.taker = new SnapshotTaker(new ActiveThreadSet(), receiver, settings, dao); taker.execute(new SnapshotInfo("testProject", "", relPath, "", fullPath, ChangeType.FILE_CHANGE)); Thread.sleep(50); assertEquals(event, null); }
@Test public void fileChangeTest() { SnapshotInfo info = new SnapshotInfo("testProject", "", relPath, "", fullPath, ChangeType.FILE_CHANGE); taker.execute(info); int i = 0; while (event == null) { if (i > 400) { fail("LoggableEvent is null after waiting over 2000ms"); } i++; try { Thread.sleep(5); } catch (InterruptedException e) { } } assertEquals(event.getCourseName(), "course1"); }
@Test public void fileRenameTest() { SnapshotInfo info = new SnapshotInfo("testProject", relPath + "a", relPath, fullPath + "a", fullPath, ChangeType.FILE_RENAME); taker.execute(info); int i = 0; while (event == null) { if (i > 400) { fail("LoggableEvent is null after waiting over 2000ms"); } i++; try { Thread.sleep(5); } catch (InterruptedException e) { } } assertEquals(event.getCourseName(), "course1"); }
@Test public void folderRenameTest() { SnapshotInfo info = new SnapshotInfo("testProject", relPath + "a", relPath, fullPath + "a", fullPath, ChangeType.FOLDER_RENAME); taker.execute(info); int i = 0; while (event == null) { if (i > 400) { fail("LoggableEvent is null after waiting over 2000ms"); } i++; try { Thread.sleep(5); } catch (InterruptedException e) { } } assertEquals(event.getCourseName(), "course1"); }