Code example for Preference

Methods: setKey

0
    	shadow = Robolectric.shadowOf(group);
 
		pref1 = new Preference(context);
		pref1.setKey("pref1");
 
		pref2 = new Preference(context);		
		pref2.setKey("pref2");
    } 
     
	@Test 
	public void shouldInheritFromPreference() { 
        assertThat(shadow).isInstanceOf(ShadowPreference.class);
	}	 
	 
	@Test 
	public void shouldAddPreferences() { 
        assertThat(group.getPreferenceCount()).isEqualTo(0);
		 
		// First add succeeds 
        assertThat(group.addPreference(pref1)).isTrue();
        assertThat(group.getPreferenceCount()).isEqualTo(1);