### Question:
SFTPManager extends FileSender { @Override public boolean isAvailable() { return validSettings(preferenceHelper.getSFTPRemoteServerPath(), preferenceHelper.getSFTPHost(),preferenceHelper.getSFTPPort(),preferenceHelper.getSFTPPrivateKeyFilePath(), preferenceHelper.getSFTPPrivateKeyPassphrase(),preferenceHelper.getSFTPUser(),preferenceHelper.getSFTPPassword(),preferenceHelper.getSFTPKnownHostKey()); } SFTPManager(PreferenceHelper preferenceHelper); @Override void uploadFile(List<File> files); void uploadFile(final File file); @Override boolean isAvailable(); @Override boolean hasUserAllowedAutoSending(); @Override boolean accept(File file, String s);  }### Answer:
@Test public void IsAvailable_WhenBasicValuesPresent_ReturnsTrue() { PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getSFTPHost()).thenReturn("aaa"); when(pm.getSFTPPort()).thenReturn(99); when(pm.getSFTPPassword()).thenReturn("hunter2"); when(pm.getSFTPRemoteServerPath()).thenReturn("/tmp"); SFTPManager manager = new SFTPManager(pm); assertThat("Basic values means is available", manager.isAvailable(), is(true)); }
@Test public void IsAvailable_WhenHostMissting_Invalid(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getSFTPPort()).thenReturn(99); when(pm.getSFTPPassword()).thenReturn("hunter2"); when(pm.getSFTPRemoteServerPath()).thenReturn("/tmp"); SFTPManager manager = new SFTPManager(pm); assertThat("Host value required", manager.isAvailable(), is(false)); }
@Test public void IsAvailable_WhenRemoteDirMissting_Invalid(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getSFTPHost()).thenReturn("aaa"); when(pm.getSFTPPort()).thenReturn(99); when(pm.getSFTPPassword()).thenReturn("hunter2"); SFTPManager manager = new SFTPManager(pm); assertThat("Remote dir value required", manager.isAvailable(), is(false)); }
@Test public void IsAvailable_WhenPasswordOrPrivateKeyMissing_Invalid(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getSFTPHost()).thenReturn("aaa"); when(pm.getSFTPPort()).thenReturn(99); when(pm.getSFTPRemoteServerPath()).thenReturn("/tmp"); SFTPManager manager = new SFTPManager(pm); assertThat("Either password or private key required", manager.isAvailable(), is(false)); when(pm.getSFTPPrivateKeyFilePath()).thenReturn("/home/user/id_rsa"); assertThat("Private key will suffice in the absence of a password", manager.isAvailable(), is(true)); }
@Test public void IsAvailable_WhenPortNumberInvalid_Invalid(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getSFTPHost()).thenReturn("aaa"); when(pm.getSFTPPort()).thenReturn(0); when(pm.getSFTPPassword()).thenReturn("hunter2"); when(pm.getSFTPRemoteServerPath()).thenReturn("/tmp"); SFTPManager manager = new SFTPManager(pm); assertThat("Valid port required", manager.isAvailable(), is(false)); when(pm.getSFTPPort()).thenReturn(-100); assertThat("Valid port required", manager.isAvailable(), is(false)); when(pm.getSFTPPort()).thenReturn(2999); assertThat("Port is valid", manager.isAvailable(), is(true)); }