Merge "Forward wallpaper activity results to the caller."
This commit is contained in:
committed by
Android (Google) Code Review
commit
f558d4663b
@@ -42,7 +42,7 @@ import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class
|
||||
})
|
||||
@@ -67,6 +67,8 @@ public class WallpaperSuggestionActivityTest {
|
||||
final Intent intent = activity.getNextStartedActivity();
|
||||
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -0,0 +1,67 @@
|
||||
package com.android.settings.wallpaper;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
|
||||
public class WallpaperTypeSettingsTest {
|
||||
|
||||
private Preference mPreference;
|
||||
|
||||
private Intent mIntent;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mIntent = new Intent();
|
||||
mPreference = new Preference(application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceTreeClick_intentNull_shouldDoNothing() {
|
||||
Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings());
|
||||
doReturn(activity).when(fragment).getActivity();
|
||||
|
||||
boolean handled = fragment.onPreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(handled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceTreeClick_shouldLaunchIntentAndFinish() {
|
||||
Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings());
|
||||
doReturn(activity).when(fragment).getActivity();
|
||||
mPreference.setIntent(mIntent);
|
||||
doNothing().when(fragment).finish();
|
||||
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
|
||||
doNothing().when(fragment).startActivity(intent.capture());
|
||||
|
||||
boolean handled = fragment.onPreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(handled).isTrue();
|
||||
verify(fragment, times(1)).finish();
|
||||
assertThat(intent.getValue()).isSameAs(mIntent);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user