ReceivedKeyedAppState { static ReceivedKeyedAppState fromBundle(Bundle bundle, String packageName, long timestamp) { if (!KeyedAppState.isValid(bundle)) { throw new IllegalArgumentException("Bundle is not valid"); } return builder() .setPackageName(packageName) .setTimestamp(timestamp) .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(); } ReceivedKeyedAppState(); @NonNull static ReceivedKeyedAppStateBuilder builder(); @NonNull abstract String getPackageName(); abstract long getTimestamp(); @NonNull abstract String getKey(); abstract int getSeverity(); @Nullable abstract String getMessage(); @Nullable abstract String getData();  }
@Test @SmallTest public void fromBundle() { Bundle bundle = new Bundle(); bundle.putString(APP_STATE_KEY, KEY); bundle.putString(APP_STATE_MESSAGE, MESSAGE); bundle.putInt(APP_STATE_SEVERITY, SEVERITY); bundle.putString(APP_STATE_DATA, DATA); ReceivedKeyedAppState state = ReceivedKeyedAppState.fromBundle(bundle, PACKAGE_NAME, TIMESTAMP); assertThat(state.getKey()).isEqualTo(KEY); assertThat(state.getMessage()).isEqualTo(MESSAGE); assertThat(state.getSeverity()).isEqualTo(SEVERITY); assertThat(state.getData()).isEqualTo(DATA); assertThat(state.getPackageName()).isEqualTo(PACKAGE_NAME); assertThat(state.getTimestamp()).isEqualTo(TIMESTAMP); }
@Test @SmallTest public void fromBundle_invalidBundle_throwsIllegalArgumentException() { Bundle bundle = new Bundle(); bundle.putString(APP_STATE_KEY, KEY); bundle.putString(APP_STATE_MESSAGE, MESSAGE); bundle.putString(APP_STATE_DATA, DATA); try { ReceivedKeyedAppState.fromBundle(bundle, PACKAGE_NAME, TIMESTAMP); fail(); } catch (IllegalArgumentException expected) { } }