Code example for Spinner

Methods: setAdapter, getSelectedItem, setSelection

0
		spinner.setAdapter(arrayAdapter);
	} 
 
	@Test 
	public void getSelectedItemShouldReturnCorrectValue(){ 
		spinner.setAdapter(arrayAdapter);
		spinner.setSelection(0);
        assertThat((String) spinner.getSelectedItem()).isEqualTo("foo");
        assertThat((String) spinner.getSelectedItem()).isNotEqualTo("bar");
		 
		spinner.setSelection(1);
        assertThat((String) spinner.getSelectedItem()).isEqualTo("bar");
		assertThat((String) spinner.getSelectedItem()).isNotEqualTo("foo");
	} 
	 
	@Test 
	public void getSelectedItemShouldReturnNull_NoAdapterSet(){ 
        assertThat(spinner.getSelectedItem()).isNull();
	} 
	 
	@Test (expected = IndexOutOfBoundsException.class)