1 package com.android.settings.localepicker; 2 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertNotNull; 5 import static org.mockito.Mockito.mock; 6 import static org.mockito.Mockito.spy; 7 8 import android.app.Activity; 9 10 import com.android.internal.app.LocaleStore; 11 12 import org.junit.Before; 13 import org.junit.Test; 14 import org.junit.runner.RunWith; 15 import org.mockito.MockitoAnnotations; 16 import org.robolectric.Robolectric; 17 import org.robolectric.RobolectricTestRunner; 18 import org.robolectric.Shadows; 19 import org.robolectric.android.controller.ActivityController; 20 import org.robolectric.shadows.ShadowActivity; 21 22 @RunWith(RobolectricTestRunner.class) 23 public class LocalePickerWithRegionActivityTest { 24 25 private LocalePickerWithRegionActivity mActivity; 26 27 @Before setUp()28 public void setUp() { 29 MockitoAnnotations.initMocks(this); 30 final ActivityController<LocalePickerWithRegionActivity> mActivityController = 31 Robolectric.buildActivity(LocalePickerWithRegionActivity.class); 32 mActivity = spy(mActivityController.get()); 33 } 34 35 @Test onLocaleSelected_resultShouldBeOK()36 public void onLocaleSelected_resultShouldBeOK() { 37 final ShadowActivity shadowActivity = Shadows.shadowOf(mActivity); 38 mActivity.onLocaleSelected(mock(LocaleStore.LocaleInfo.class)); 39 40 assertEquals(Activity.RESULT_OK, shadowActivity.getResultCode()); 41 } 42 43 @Test onLocaleSelected_localeInfoShouldBeSentBack()44 public void onLocaleSelected_localeInfoShouldBeSentBack() { 45 final ShadowActivity shadowActivity = Shadows.shadowOf(mActivity); 46 mActivity.onLocaleSelected(mock(LocaleStore.LocaleInfo.class)); 47 48 assertNotNull(shadowActivity.getResultIntent().getSerializableExtra( 49 LocaleListEditor.INTENT_LOCALE_KEY)); 50 } 51 } 52