@Test @SmallTest public void fromBundle_invalidBundle_throwsIllegalArgumentException() { Bundle bundle = buildTestBundle(); bundle.remove(APP_STATE_SEVERITY); try { KeyedAppState.fromBundle(bundle); fail(); } catch (IllegalArgumentException expected) { } }
static KeyedAppState fromBundle(Bundle bundle) { if (!isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return KeyedAppState.builder() .setKey(bundle.getString(APP_STATE_KEY)) .setSeverity(bundle.getInt(APP_STATE_SEVERITY)) .setMessage(bundle.getString(APP_STATE_MESSAGE)) .setData(bundle.getString(APP_STATE_DATA)) .build(); }
KeyedAppState { static KeyedAppState fromBundle(Bundle bundle) { if (!isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return KeyedAppState.builder() .setKey(bundle.getString(APP_STATE_KEY)) .setSeverity(bundle.getInt(APP_STATE_SEVERITY)) .setMessage(bundle.getString(APP_STATE_MESSAGE)) .setData(bundle.getString(APP_STATE_DATA)) .build(); } }
KeyedAppState { static KeyedAppState fromBundle(Bundle bundle) { if (!isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return KeyedAppState.builder() .setKey(bundle.getString(APP_STATE_KEY)) .setSeverity(bundle.getInt(APP_STATE_SEVERITY)) .setMessage(bundle.getString(APP_STATE_MESSAGE)) .setData(bundle.getString(APP_STATE_DATA)) .build(); } KeyedAppState(); }
KeyedAppState { static KeyedAppState fromBundle(Bundle bundle) { if (!isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return KeyedAppState.builder() .setKey(bundle.getString(APP_STATE_KEY)) .setSeverity(bundle.getInt(APP_STATE_SEVERITY)) .setMessage(bundle.getString(APP_STATE_MESSAGE)) .setData(bundle.getString(APP_STATE_DATA)) .build(); } KeyedAppState(); @NonNull static KeyedAppStateBuilder builder(); @NonNull abstract String getKey(); @Severity abstract int getSeverity(); @Nullable abstract String getMessage(); @Nullable abstract String getData(); }
KeyedAppState { static KeyedAppState fromBundle(Bundle bundle) { if (!isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return KeyedAppState.builder() .setKey(bundle.getString(APP_STATE_KEY)) .setSeverity(bundle.getInt(APP_STATE_SEVERITY)) .setMessage(bundle.getString(APP_STATE_MESSAGE)) .setData(bundle.getString(APP_STATE_DATA)) .build(); } 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; }