package com.tiger_miao.niceweather.activity;

import com.tiger_miao.niceweather.BuildConfig;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.assertTrue;

/**
 * Created by tiger on 15-7-16.
 */
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class ChooseAreaActivityTest {

    @Test
    public void testSomething() throws Exception {
        assertTrue(Robolectric.buildActivity(ChooseAreaActivity.class).create().get() != null);
    }

}

@@ -50,283 +50,717 @@
 ort 
-com.tiger_miao.niceweather.BuildConfig;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.robolectric.Robolectric;%0Aimport org.robolectric.RobolectricGradleTestRunner;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport static junit.framework.Assert.assertTrue
+android.widget.ListView;%0Aimport android.widget.TextView;%0A%0Aimport com.google.inject.AbstractModule;%0Aimport com.tiger_miao.niceweather.BuildConfig;%0Aimport com.tiger_miao.niceweather.R;%0Aimport com.tiger_miao.niceweather.model.IChooseAreaActivityViewModel;%0A%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.robolectric.Robolectric;%0Aimport org.robolectric.RobolectricGradleTestRunner;%0Aimport org.robolectric.RuntimeEnvironment;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport roboguice.RoboGuice;%0A%0Aimport static junit.framework.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertEquals
 ;%0A%0A/
@@ -938,13 +938,120 @@
     
-@Test
+private ChooseAreaActivity activity;%0A    private ListView listView;%0A    private TextView titleText;%0A%0A    @Before
 %0A   
@@ -1067,21 +1067,13 @@
 oid 
-testSomething
+setUp
 () t
@@ -1102,95 +1102,1664 @@
     
-assertTrue(Robolectric.buildActivity(ChooseAreaActivity.class).create().get() != null);
+RoboGuice.overrideApplicationInjector(RuntimeEnvironment.application, new MyTestGuiceModule());%0A%0A        activity = Robolectric.buildActivity(ChooseAreaActivity.class).create().get();%0A%0A        listView = (ListView) activity.findViewById(R.id.list_view);%0A        titleText = (TextView) activity.findViewById(R.id.title_text);%0A    %7D%0A%0A    @Test%0A    public void testPreconditions() %7B%0A        assertNotNull(activity);%0A    %7D%0A%0A    @Test%0A    public void testClickOnItemOne() %7B%0A        listView.performItemClick(%0A                listView.getAdapter().getView(0, null, null),%0A                0,%0A                listView.getAdapter().getItemId(0));%0A%0A        assertEquals(%22%E5%8C%97%E4%BA%AC%22, titleText.getText().toString());%0A    %7D%0A%0A    @Test%0A    public void testClickOnItemThree() %7B%0A        listView.performItemClick(%0A                listView.getAdapter().getView(2, null, null),%0A                2,%0A                listView.getAdapter().getItemId(2));%0A%0A        assertEquals(%22%E4%B8%8A%E6%B5%B7%22, titleText.getText().toString());%0A    %7D%0A%0A    @After%0A    public void tearDown()%0A    %7B%0A        RoboGuice.Util.reset();%0A    %7D%0A%0A    public static class MyTestViewModel implements IChooseAreaActivityViewModel %7B%0A        @Override%0A        public List%3CString%3E getDataList() %7B%0A            List%3CString%3E dataList = new ArrayList%3C%3E();%0A%0A            dataList.add(%22%E5%8C%97%E4%BA%AC%22);%0A            dataList.add(%22%E5%A4%A9%E6%B4%A5%22);%0A            dataList.add(%22%E4%B8%8A%E6%B5%B7%22);%0A            dataList.add(%22%E6%88%90%E9%83%BD%22);%0A%0A            return dataList;%0A        %7D%0A    %7D%0A%0A    public class MyTestGuiceModule extends AbstractModule %7B%0A        @Override%0A        protected void configure() %7B%0A            bind(IChooseAreaActivityViewModel.class).to(MyTestViewModel.class);%0A        %7D
 %0A   

重构了ChooseAreaActivity unit test