AndroidStateManager implements StateSaver, StateLoader { @Override public int loadInt(String key, int defaultIfNotFound) { if (bundle == null) { return defaultIfNotFound; } return bundle.getInt(key, defaultIfNotFound); } AndroidStateManager(Bundle bundle); @Override void saveInt(String key, int value); @Override int loadInt(String key, int defaultIfNotFound);  }
@Test public void loadInt_returnsTheValueForTheGivenKey_whenKeyExists() { Bundle bundle = mock(Bundle.class); when(bundle.getInt("key", 0)).thenReturn(1); AndroidStateManager manager = new AndroidStateManager(bundle); int res = manager.loadInt("key", 0); assertEquals(1, res); }
@Test public void loadInt_returnsTheProvidedDefault_whenBundleIsNull() { AndroidStateManager manager = new AndroidStateManager(null); int res = manager.loadInt("key", 0); assertEquals(0, res); }
@Test public void loadInt_returnsTheProvidedDefault_whenKeyDoesNotExist() { Bundle bundle = mock(Bundle.class); when(bundle.getInt("key", 0)).thenReturn(0); AndroidStateManager manager = new AndroidStateManager(bundle); int res = manager.loadInt("key", 0); assertEquals(0, res); }