### Question:
AutoEmailManager extends FileSender { @Override public boolean isAvailable() { return isValid( preferenceHelper.getSmtpServer(), preferenceHelper.getSmtpPort(), preferenceHelper.getSmtpUsername(), preferenceHelper.getSmtpPassword(), preferenceHelper.getAutoEmailTargets()); } AutoEmailManager(PreferenceHelper helper); @Override void uploadFile(List<File> files); @Override boolean isAvailable(); @Override boolean hasUserAllowedAutoSending(); void sendTestEmail(String smtpServer, String smtpPort,
                       String smtpUsername, String smtpPassword, boolean smtpUseSsl,
                       String emailTarget, String fromAddress); @Override boolean accept(File dir, String name); boolean isValid(String server, String port, String username, String password, String target);  }### Answer:
@Test public void IsAvailable_WhenAllValuesPresent_ReturnsTrue(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getAutoEmailTargets()).thenReturn("aaaaaa"); when(pm.getSmtpServer()).thenReturn("bbbbbbb"); when(pm.getSmtpPort()).thenReturn("bbbbbbb"); when(pm.getSmtpUsername()).thenReturn("bbbbbbb"); AutoEmailManager aem = new AutoEmailManager(pm); assertThat("All values present means is available", aem.isAvailable(), is(true)); }
@Test public void IsAvailable_AllValuesButAutoSendUnchecked_ReturnsTrue(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getAutoEmailTargets()).thenReturn("aaaaaa"); when(pm.getSmtpServer()).thenReturn("bbbbbbb"); when(pm.getSmtpPort()).thenReturn("bbbbbbb"); when(pm.getSmtpUsername()).thenReturn("bbbbbbb"); AutoEmailManager aem = new AutoEmailManager(pm); assertThat("All values present but auto-send unchecked, still available", aem.isAvailable(), is(true)); }
@Test public void IsAvailable_WhenSomeValuesMissing_ReturnsFalse(){ PreferenceHelper pm = mock(PreferenceHelper.class); when(pm.getAutoEmailTargets()).thenReturn("aaaaaa"); when(pm.getSmtpServer()).thenReturn(""); when(pm.getSmtpPort()).thenReturn("bbbbbbb"); when(pm.getSmtpUsername()).thenReturn("bbbbbbb"); AutoEmailManager aem = new AutoEmailManager(pm); assertThat("Some values missing indicates invalid email settings", aem.isAvailable(), is(false)); }