AndroidStateManager implements StateSaver, StateLoader { @Override public boolean loadBool(String key, boolean defaultIfNotFound) { if (bundle == null) { return defaultIfNotFound; } return bundle.getBoolean(key, defaultIfNotFound); } AndroidStateManager(Bundle bundle); @Override void saveInt(String key, int value); @Override int loadInt(String key, int defaultIfNotFound); @Override void saveBool(String key, boolean value); @Override boolean loadBool(String key, boolean defaultIfNotFound);  }
@Test public void loadBool_returnsTheValueForTheGivenKey_whenKeyExists() { Bundle bundle = mock(Bundle.class); when(bundle.getBoolean(eq("key"), anyBoolean())).thenReturn(true); AndroidStateManager manager = new AndroidStateManager(bundle); boolean res = manager.loadBool("key", false); assertEquals(true, res); }
@Test public void loadBool_returnsTheProvidedDefault_whenBundleIsNull() { AndroidStateManager manager = new AndroidStateManager(null); boolean res = manager.loadBool("key", true); assertEquals(true, res); }
@Test public void loadBool_returnsTheProvidedDefault_whenKeyDoesNotExist() { Bundle bundle = mock(Bundle.class); when(bundle.getBoolean("key", false)).thenReturn(false); AndroidStateManager manager = new AndroidStateManager(bundle); boolean res = manager.loadBool("key", false); assertEquals(false, res); }