State { public String getErrorMessage(Resources resources) { if (exception == null) return null; if (exception instanceof MessagingException && "Unable to get IMAP prefix".equals(exception.getMessage())) { return resources.getString(R.string.status_gmail_temp_error); } else if (exception instanceof LocalizableException) { return resources.getString(((LocalizableException) exception).errorResourceId()); } else { return exception.getLocalizedMessage(); } } State(SmsSyncState state, @Nullable DataType dataType, Exception exception); String getErrorMessage(Resources resources); String getDetailedErrorMessage(Resources resources); boolean isInitialState(); boolean isRunning(); boolean isFinished(); abstract State transition(SmsSyncState newState, Exception exception); boolean isAuthException(); boolean isPermissionException(); boolean isConnectivityError(); boolean isError(); boolean isCanceled(); String getNotificationLabel(Resources resources); String[] getMissingPermissions(); final SmsSyncState state; final Exception exception; final @Nullable DataType dataType; }
@Test public void shouldGetErrorMessageRequiresWifi() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new RequiresWifiException()); assertThat(state.getErrorMessage(resources)).isEqualTo("No Wifi connection"); }
@Test public void shouldGetErrorMessagePrefix() throws Exception { BackupState state = new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new MessagingException("Unable to get IMAP prefix")); assertThat(state.getErrorMessage(resources)).isEqualTo("Temporary IMAP error, try again later."); }