Search in sources :

Example 1 with Computer

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)));
}
Also used : Button(android.widget.Button) Computer(com.octo.android.sample.model.Computer) TextView(android.widget.TextView) Test(org.junit.Test)

Example 2 with Computer

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)));
}
Also used : Button(android.widget.Button) Computer(com.octo.android.sample.model.Computer) TextView(android.widget.TextView) Test(org.junit.Test)

Example 3 with Computer

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)));
}
Also used : Computer(com.octo.android.sample.model.Computer) Test(org.junit.Test) BoundBox(org.boundbox.BoundBox)

Example 4 with Computer

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));
}
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 5 with Computer

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));
}
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

Computer (com.octo.android.sample.model.Computer)5 Button (android.widget.Button)4 TextView (android.widget.TextView)4 Test (org.junit.Test)3 UiThreadTest (android.test.UiThreadTest)2 DummyComputer (com.octo.android.sample.model.DummyComputer)2 HelloAndroidActivity (com.octo.android.sample.ui.HelloAndroidActivity)2 BoundBox (org.boundbox.BoundBox)1