State { public String getNotificationLabel(Resources resources) { switch (state) { case LOGIN: return resources.getString(R.string.status_login_details); case CALC: return resources.getString(R.string.status_calc_details); case ERROR: return getErrorMessage(resources); default: return null; } } 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 shouldGetNotificationLabelLogin() throws Exception { assertThat(new BackupState(SmsSyncState.LOGIN, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_login_details) ); }
@Test public void shouldGetNotificationLabelCalculating() throws Exception { assertThat(new BackupState(SmsSyncState.CALC, 0, 0, BackupType.REGULAR, DataType.SMS, null).getNotificationLabel(resources)).isEqualTo( resources.getString(R.string.status_calc_details) ); }
@Test public void shouldGetNotificationLabelError() throws Exception { assertThat(new BackupState(SmsSyncState.ERROR, 0, 0, BackupType.REGULAR, DataType.SMS, new IOException("foo")).getNotificationLabel(resources)) .isEqualTo("foo"); }