Validation { public boolean isValidUsbDeviceCandidate(@Nonnull final File file) { final boolean retVal; if (!file.exists()) { retVal = false; } else if (!file.isDirectory()) { retVal = false; } else if (".".equals(file.getName()) || "..".equals(file.getName())) { retVal = false; } else { retVal = true; } return retVal; }  boolean isValidUsbDeviceCandidate(@Nonnull final File file); @Nonnull File[] getListOfChildren(@Nonnull final File path);  }
@Test public void isValidUsbDeviceCandidate_not_existent() { final File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.exists()).thenReturn(false); assertFalse(cut.isValidUsbDeviceCandidate(mockFile)); }
@Test public void isValidUsbDeviceCandidate_not_directory() { final File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.exists()).thenReturn(true); Mockito.when(mockFile.isDirectory()).thenReturn(false); assertFalse(cut.isValidUsbDeviceCandidate(mockFile)); }
@Test public void isValidUsbDeviceCandidate_is_current_dir() { final File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.exists()).thenReturn(true); Mockito.when(mockFile.isDirectory()).thenReturn(true); Mockito.when(mockFile.getName()).thenReturn("."); assertFalse(cut.isValidUsbDeviceCandidate(mockFile)); }
@Test public void isValidUsbDeviceCandidate_is_parent_dir() { final File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.exists()).thenReturn(true); Mockito.when(mockFile.isDirectory()).thenReturn(true); Mockito.when(mockFile.getName()).thenReturn(".."); assertFalse(cut.isValidUsbDeviceCandidate(mockFile)); }
@Test public void isValidUsbDeviceCandidate_is_valid() { final File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.exists()).thenReturn(true); Mockito.when(mockFile.isDirectory()).thenReturn(true); Mockito.when(mockFile.getName()).thenReturn("foo"); assertTrue(cut.isValidUsbDeviceCandidate(mockFile)); }
@Test(expected = NullPointerException.class) public void isValidUsbDeviceCandidate_is_null() { final File mockFile = null; cut.isValidUsbDeviceCandidate(mockFile); }