use of com.octo.android.sample.model.Computer in project Quality-Tools-for-Android by stephanenicolas.
the class MyActivityTest method shouldUseCustomComputerUsingMockito.
@Test
public void shouldUseCustomComputerUsingMockito() throws Exception {
final int EXPECTED_RESULT = 1;
// given
HelloAndroidActivity activityUnderTest = Robolectric.buildActivity(HelloAndroidActivity.class).create().get();
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();
assertThat(textViewHelloString, equalTo(String.valueOf(EXPECTED_RESULT)));
}
use of com.octo.android.sample.model.Computer in project Quality-Tools-for-Android by stephanenicolas.
the class MyActivityTest method shouldUseCustomComputerUsingEasyMock.
@Test
public void shouldUseCustomComputerUsingEasyMock() throws Exception {
final int EXPECTED_RESULT = 1;
// given
HelloAndroidActivity activityUnderTest = Robolectric.buildActivity(HelloAndroidActivity.class).create().get();
Computer mockComputer = EasyMock.createMock(Computer.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();
assertThat(textViewHelloString, equalTo(String.valueOf(EXPECTED_RESULT)));
}
use of com.octo.android.sample.model.Computer in project Quality-Tools-for-Android by stephanenicolas.
the class MyActivityTest method shouldUseCustomComputerUsingMockitoAndBoundBox.
@BoundBox(boundClass = HelloAndroidActivity.class, maxSuperClass = FragmentActivity.class)
@Test
public void shouldUseCustomComputerUsingMockitoAndBoundBox() throws Exception {
final int EXPECTED_RESULT = 1;
// given
HelloAndroidActivity activityUnderTest = Robolectric.buildActivity(HelloAndroidActivity.class).create().get();
BoundBoxOfHelloAndroidActivity boundBoxOfHelloAndroidActivity = new BoundBoxOfHelloAndroidActivity(activityUnderTest);
Computer mockComputer = Mockito.mock(Computer.class);
Mockito.when(mockComputer.getResult()).thenReturn(EXPECTED_RESULT);
boundBoxOfHelloAndroidActivity.setComputer(mockComputer);
// when
boundBoxOfHelloAndroidActivity.boundBox_getButton().performClick();
// then
Mockito.verify(mockComputer, Mockito.times(1)).getResult();
String textViewHelloString = boundBoxOfHelloAndroidActivity.boundBox_getTextView().getText().toString();
assertThat(textViewHelloString, equalTo(String.valueOf(EXPECTED_RESULT)));
}
use of com.octo.android.sample.model.Computer 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.model.Computer 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