use of com.octo.android.sample.ui.HelloAndroidActivity in project Quality-Tools-for-Android by stephanenicolas.
the class HelloAndroidActivityTest method testActivity_shouldUseCustomComputerUsingMockito.
@UiThreadTest
public void testActivity_shouldUseCustomComputerUsingMockito() throws Exception {
final int EXPECTED_RESULT = 1;
// given
HelloAndroidActivity activityUnderTest = getActivity();
Computer mockComputer = Mockito.mock(Computer.class);
Mockito.when(mockComputer.getResult()).thenReturn(EXPECTED_RESULT);
activityUnderTest.setComputer(mockComputer);
// when
Button button = (Button) activityUnderTest.findViewById(R.id.button_main);
button.performClick();
// then
Mockito.verify(mockComputer, Mockito.times(1)).getResult();
TextView textViewHello = (TextView) activityUnderTest.findViewById(R.id.textview_hello);
String textViewHelloString = textViewHello.getText().toString();
assertEquals(textViewHelloString, String.valueOf(EXPECTED_RESULT));
}
use of com.octo.android.sample.ui.HelloAndroidActivity in project Quality-Tools-for-Android by stephanenicolas.
the class HelloAndroidActivityTest method testActivity_shouldUseCustomComputerUsingEasyMock.
@UiThreadTest
public void testActivity_shouldUseCustomComputerUsingEasyMock() throws Exception {
final int EXPECTED_RESULT = 1;
// given
HelloAndroidActivity activityUnderTest = getActivity();
Computer mockComputer = EasyMock.createMock(DummyComputer.class);
EasyMock.expect(mockComputer.getResult()).andReturn(EXPECTED_RESULT);
activityUnderTest.setComputer(mockComputer);
EasyMock.replay(mockComputer);
// when
Button button = (Button) activityUnderTest.findViewById(R.id.button_main);
button.performClick();
// then
EasyMock.verify(mockComputer);
TextView textViewHello = (TextView) activityUnderTest.findViewById(R.id.textview_hello);
String textViewHelloString = textViewHello.getText().toString();
assertEquals(textViewHelloString, String.valueOf(EXPECTED_RESULT));
}
Aggregations