@Test @SmallTest public void isValid_tooHighKeyLength_isFalse() { Bundle bundle = buildTestBundle(); bundle.putString(APP_STATE_KEY, buildStringOfLength(MAX_KEY_LENGTH + 1)); assertThat(KeyedAppState.isValid(bundle)).isFalse(); }
static boolean isValid(Bundle bundle) { String key = bundle.getString(APP_STATE_KEY); if (key == null || key.length() > MAX_KEY_LENGTH) { return false; } int severity = bundle.getInt(APP_STATE_SEVERITY); if (severity != SEVERITY_INFO && severity != SEVERITY_ERROR) { return false; } String message = bundle.getString(APP_STATE_MESSAGE); if (message != null && message.length() > MAX_MESSAGE_LENGTH) { return false; } String data = bundle.getString(APP_STATE_DATA); if (data != null && data.length() > MAX_DATA_LENGTH) { return false; } return true; }
KeyedAppState { static boolean isValid(Bundle bundle) { String key = bundle.getString(APP_STATE_KEY); if (key == null || key.length() > MAX_KEY_LENGTH) { return false; } int severity = bundle.getInt(APP_STATE_SEVERITY); if (severity != SEVERITY_INFO && severity != SEVERITY_ERROR) { return false; } String message = bundle.getString(APP_STATE_MESSAGE); if (message != null && message.length() > MAX_MESSAGE_LENGTH) { return false; } String data = bundle.getString(APP_STATE_DATA); if (data != null && data.length() > MAX_DATA_LENGTH) { return false; } return true; } }
KeyedAppState { static boolean isValid(Bundle bundle) { String key = bundle.getString(APP_STATE_KEY); if (key == null || key.length() > MAX_KEY_LENGTH) { return false; } int severity = bundle.getInt(APP_STATE_SEVERITY); if (severity != SEVERITY_INFO && severity != SEVERITY_ERROR) { return false; } String message = bundle.getString(APP_STATE_MESSAGE); if (message != null && message.length() > MAX_MESSAGE_LENGTH) { return false; } String data = bundle.getString(APP_STATE_DATA); if (data != null && data.length() > MAX_DATA_LENGTH) { return false; } return true; } KeyedAppState(); }
KeyedAppState { static boolean isValid(Bundle bundle) { String key = bundle.getString(APP_STATE_KEY); if (key == null || key.length() > MAX_KEY_LENGTH) { return false; } int severity = bundle.getInt(APP_STATE_SEVERITY); if (severity != SEVERITY_INFO && severity != SEVERITY_ERROR) { return false; } String message = bundle.getString(APP_STATE_MESSAGE); if (message != null && message.length() > MAX_MESSAGE_LENGTH) { return false; } String data = bundle.getString(APP_STATE_DATA); if (data != null && data.length() > MAX_DATA_LENGTH) { return false; } return true; } KeyedAppState(); @NonNull static KeyedAppStateBuilder builder(); @NonNull abstract String getKey(); @Severity abstract int getSeverity(); @Nullable abstract String getMessage(); @Nullable abstract String getData(); }
KeyedAppState { static boolean isValid(Bundle bundle) { String key = bundle.getString(APP_STATE_KEY); if (key == null || key.length() > MAX_KEY_LENGTH) { return false; } int severity = bundle.getInt(APP_STATE_SEVERITY); if (severity != SEVERITY_INFO && severity != SEVERITY_ERROR) { return false; } String message = bundle.getString(APP_STATE_MESSAGE); if (message != null && message.length() > MAX_MESSAGE_LENGTH) { return false; } String data = bundle.getString(APP_STATE_DATA); if (data != null && data.length() > MAX_DATA_LENGTH) { return false; } return true; } KeyedAppState(); @NonNull static KeyedAppStateBuilder builder(); @NonNull abstract String getKey(); @Severity abstract int getSeverity(); @Nullable abstract String getMessage(); @Nullable abstract String getData(); static final int SEVERITY_INFO; static final int SEVERITY_ERROR; static final int MAX_KEY_LENGTH; static final int MAX_MESSAGE_LENGTH; static final int MAX_DATA_LENGTH; }