### Question:
OpenGTSManager extends FileSender { @Override public boolean isAvailable() { return !Strings.isNullOrEmpty(preferenceHelper.getOpenGTSServer()) && !Strings.isNullOrEmpty(preferenceHelper.getOpenGTSServerPort()) && Strings.toInt(preferenceHelper.getOpenGTSServerPort(), 0) != 0 && !Strings.isNullOrEmpty(preferenceHelper.getOpenGTSServerCommunicationMethod()) && !Strings.isNullOrEmpty(preferenceHelper.getOpenGTSDeviceId()); } OpenGTSManager(PreferenceHelper preferenceHelper);  OpenGTSManager(PreferenceHelper preferenceHelper, int batteryLevel); @Override void uploadFile(List<File> files); void sendLocations(SerializableLocation[] locations); static String gprmcEncode(SerializableLocation loc); static String getNmeaGprmcTime(Date dateToFormat); static String getNmeaGprmcDate(Date dateToFormat); static String getNmeaGprmcCoordinates(double coord); static String getNmeaChecksum(String msg); static String getUrl(String id, String accountName, SerializableLocation loc, String communication, String path, String server, int port, int batteryLevel); @Override boolean isAvailable(); @Override boolean hasUserAllowedAutoSending(); @Override boolean accept(File dir, String name);  }### Answer:
@Test public void IsAvailable_WhenAllValuesPresent_True(){ PreferenceHelper pm = mock(PreferenceHelper.class); OpenGTSManager manager = new OpenGTSManager(pm); assertThat("Default state is unavailable", manager.isAvailable(), is(false)); when(pm.getOpenGTSServer()).thenReturn("XXXXXXXXXXXX"); when(pm.getOpenGTSServerPort()).thenReturn("9001"); when(pm.getOpenGTSServerCommunicationMethod()).thenReturn("UDPTLSSSLSSH"); when(pm.getOpenGTSDeviceId()).thenReturn("99"); assertThat("With values, it becomes available", manager.isAvailable(), is(true)); }
@Test public void IsAutoSendAvailable_WhenPortIsNotNumberic_False(){ PreferenceHelper pm = mock(PreferenceHelper.class); OpenGTSManager manager = new OpenGTSManager(pm); assertThat("Default state is unavailable", manager.isAvailable(), is(false)); when(pm.getOpenGTSServer()).thenReturn("XXXXXXXXXXXX"); when(pm.getOpenGTSServerPort()).thenReturn("aaaaaaaaaaaaa"); when(pm.getOpenGTSServerCommunicationMethod()).thenReturn("UDPTLSSSLSSH"); when(pm.getOpenGTSDeviceId()).thenReturn("99"); assertThat("When port is non numeric, validation fails", manager.isAvailable(), is(false)); }