@Test(expected = TransactionInvalidatedException.class)
public void applyTwice() {

    String value = "value";
    PreferencesEditor editor = preferences.edit()
            .putString(key, value);
    editor.apply();
    editor.apply();
}