Search in sources :

Example 1 with HelloAndroidActivity

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));
}
Also used : HelloAndroidActivity(com.octo.android.sample.ui.HelloAndroidActivity) Button(android.widget.Button) Computer(com.octo.android.sample.model.Computer) DummyComputer(com.octo.android.sample.model.DummyComputer) TextView(android.widget.TextView) UiThreadTest(android.test.UiThreadTest)

Example 2 with HelloAndroidActivity

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));
}
Also used : HelloAndroidActivity(com.octo.android.sample.ui.HelloAndroidActivity) Button(android.widget.Button) Computer(com.octo.android.sample.model.Computer) DummyComputer(com.octo.android.sample.model.DummyComputer) TextView(android.widget.TextView) UiThreadTest(android.test.UiThreadTest)

Aggregations

UiThreadTest (android.test.UiThreadTest)2 Button (android.widget.Button)2 TextView (android.widget.TextView)2 Computer (com.octo.android.sample.model.Computer)2 DummyComputer (com.octo.android.sample.model.DummyComputer)2 HelloAndroidActivity (com.octo.android.sample.ui.HelloAndroidActivity)2