### Question:
EnumPreference extends AbsPreference<E> { @Override public void set(E value) { if (value == null) throw new NullPointerException("value"); this.set(value.ordinal()); } EnumPreference(SharedPreferences preferences, String key, E defaultValue); @SuppressWarnings("unchecked") @Override E get(); @Override void set(E value);  }### Answer:
@Test public void throwWhenSetWithNull() { String key = "testKey1"; EnumPreference<TestEnum> preference = new EnumPreference<TestEnum>(preferences, key, TEST1); try { preference.set(null); } catch (NullPointerException e) { return; } throw new AssertionError("Calling 'set' with null did not throw"); }
@Test public void saveValue() { TestEnum expected = TEST2; String key = "testKey"; EnumPreference<TestEnum> preference = new EnumPreference<TestEnum>(preferences, key, TEST1); preference.set(expected); assertThat(TestEnum.values()[preferences.getInt(key, 0)]).isEqualTo(expected); }