Merge "Fork Search code to independantly develop and test search."
This commit is contained in:
committed by
Android (Google) Code Review
commit
3b64ad983f
@@ -64,6 +64,10 @@ public class SettingsRobolectricTestRunner extends RobolectricTestRunner {
|
||||
getPackageName(),
|
||||
Fs.fileFromPath("./frameworks/base/packages/SettingsLib/res"),
|
||||
null));
|
||||
paths.add(new ResourcePath(
|
||||
getPackageName(),
|
||||
Fs.fileFromPath("./frameworks/base/core/res/res"),
|
||||
null));
|
||||
return paths;
|
||||
}
|
||||
};
|
||||
|
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.DatabaseResultLoader;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.search2.ResultPayload.PayloadType;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
import com.android.settings.R;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DatabaseResultLoaderTest {
|
||||
private DatabaseResultLoader mLoader;
|
||||
|
||||
private static final String[] TITLES = new String[] {"title1", "title2", "title3"};
|
||||
private static final String SUMMARY = "SUMMARY";
|
||||
private static final int EXAMPLES = 3;
|
||||
private static final Intent mIntent = new Intent("com.android.settings");
|
||||
private static final int mIcon = R.drawable.ic_search_history;
|
||||
|
||||
private Drawable mDrawable;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = Robolectric.buildActivity(Activity.class).get();
|
||||
mDrawable = context.getDrawable(mIcon);
|
||||
mLoader = new DatabaseResultLoader(context, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNullResults_ReturnsNull() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(null);
|
||||
assertThat(results).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_NotNull() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
assertThat(results).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesRank() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).rank).isEqualTo(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesTitle() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).title).isEqualTo(TITLES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesSummary() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
assertThat(results.get(i).summary).isEqualTo(SUMMARY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIcon() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
Drawable resultDrawable = results.get(i).icon;
|
||||
assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesPayloadType() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
ResultPayload payload;
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
payload = results.get(i).payload;
|
||||
assertThat(payload.getType()).isEqualTo(PayloadType.INTENT);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCursor_MatchesIntentPayload() {
|
||||
List<SearchResult> results = mLoader.parseCursorForSearch(getDummyCursor());
|
||||
IntentPayload payload;
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
payload = (IntentPayload) results.get(i).payload;
|
||||
Intent intent = payload.intent;
|
||||
assertThat(intent.getAction()).isEqualTo(mIntent.getAction());
|
||||
}
|
||||
}
|
||||
|
||||
private MatrixCursor getDummyCursor() {
|
||||
String[] columns = new String[] {"rank", "title", "summary_on", "summary off", "entries",
|
||||
"keywords", "class name", "screen title", "icon", "intent action",
|
||||
"target package", "target class", "enabled", "key", "user id"};
|
||||
MatrixCursor cursor = new MatrixCursor(columns);
|
||||
final String BLANK = "";
|
||||
|
||||
for (int i = 0; i < EXAMPLES; i++) {
|
||||
ArrayList<String> item = new ArrayList<>(columns.length);
|
||||
item.add(Integer.toString(i));
|
||||
item.add(TITLES[i]);
|
||||
item.add(SUMMARY);
|
||||
item.add(BLANK); // summary off
|
||||
item.add(BLANK); // entries
|
||||
item.add(BLANK); // keywords
|
||||
item.add(BLANK); // classname
|
||||
item.add(BLANK); // screen title
|
||||
item.add(Integer.toString(mIcon));
|
||||
item.add(mIntent.getAction());
|
||||
item.add(BLANK); // target package
|
||||
item.add(BLANK); // target class
|
||||
item.add(BLANK); // enabled
|
||||
item.add(BLANK); // key
|
||||
item.add(BLANK); // user id
|
||||
|
||||
cursor.addRow(item);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.InlineSliderPayload;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InlineSliderPayloadTest {
|
||||
private InlineSliderPayload mPayload;
|
||||
|
||||
@Test
|
||||
public void testParcelOrdering_StaysValid() {
|
||||
Uri uri = Uri.parse("http://www.TESTURI.com");
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
mPayload = new InlineSliderPayload(uri);
|
||||
mPayload.writeToParcel(parcel, 0);
|
||||
// Reset parcel for reading
|
||||
parcel.setDataPosition(0);
|
||||
InlineSliderPayload newPayload = InlineSliderPayload.CREATOR.createFromParcel(parcel);
|
||||
|
||||
String originalUri = mPayload.uri.toString();
|
||||
String copiedUri = newPayload.uri.toString();
|
||||
assertThat(originalUri).isEqualTo(copiedUri);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class IntentPayloadTest {
|
||||
private IntentPayload mPayload;
|
||||
|
||||
private final String EXTRA_KEY = "key";
|
||||
private final String EXTRA_VALUE = "value";
|
||||
|
||||
@Test
|
||||
public void testParcelOrdering_StaysValid() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
mPayload = new IntentPayload(intent);
|
||||
mPayload.writeToParcel(parcel, 0);
|
||||
// Reset parcel for reading
|
||||
parcel.setDataPosition(0);
|
||||
IntentPayload newPayload = IntentPayload.CREATOR.createFromParcel(parcel);
|
||||
|
||||
String originalIntentExtra = mPayload.intent.getStringExtra(EXTRA_KEY);
|
||||
String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
|
||||
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.IntentSearchViewHolder;
|
||||
import com.android.settings.search2.SearchResult.Builder;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class IntentSearchViewHolderTest {
|
||||
private IntentSearchViewHolder mHolder;
|
||||
private static Drawable mIcon;
|
||||
|
||||
private static final String TITLE = "title";
|
||||
private static final String SUMMARY = "summary";
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.search_intent_item, null);
|
||||
mHolder = new IntentSearchViewHolder(view);
|
||||
|
||||
mIcon = context.getDrawable(R.drawable.ic_search_history);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_MembersNotNull() {
|
||||
assertThat(mHolder.titleView).isNotNull();
|
||||
assertThat(mHolder.summaryView).isNotNull();
|
||||
assertThat(mHolder.iconView).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_AllUpdated() {
|
||||
SearchResult result = getSearchResult();
|
||||
mHolder.onBind(result);
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.iconView.getDrawable()).isEqualTo(mIcon);
|
||||
}
|
||||
|
||||
private SearchResult getSearchResult() {
|
||||
Builder builder = new Builder();
|
||||
builder.addTitle(TITLE)
|
||||
.addSummary(SUMMARY)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(null))
|
||||
.addBreadcrumbs(new ArrayList<String>())
|
||||
.addIcon(mIcon);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.*;
|
||||
import com.android.settings.search2.SearchResult.Builder;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchAdapterTest {
|
||||
|
||||
private SearchResultsAdapter mAdapter;
|
||||
private Context mContext;
|
||||
private String mLoaderClassName;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = Robolectric.buildActivity(Activity.class).get();
|
||||
mAdapter = new SearchResultsAdapter();
|
||||
mLoaderClassName = DatabaseResultLoader.class.getName();
|
||||
}
|
||||
|
||||
private ArrayList<SearchResult> getIntentSampleResults() {
|
||||
ArrayList<SearchResult> sampleResults = new ArrayList<>();
|
||||
ArrayList<String> breadcrumbs = new ArrayList<>();
|
||||
final Drawable icon = mContext.getDrawable(R.drawable.ic_search_history);
|
||||
final ResultPayload payload = new IntentPayload(null);
|
||||
|
||||
SearchResult.Builder builder = new Builder();
|
||||
builder.addTitle("title")
|
||||
.addSummary("summary")
|
||||
.addRank(1)
|
||||
.addBreadcrumbs(breadcrumbs)
|
||||
.addIcon(icon)
|
||||
.addPayload(payload);
|
||||
sampleResults.add(builder.build());
|
||||
|
||||
builder.addRank(2);
|
||||
sampleResults.add(builder.build());
|
||||
|
||||
builder.addRank(3);
|
||||
sampleResults.add(builder.build());
|
||||
return sampleResults;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoResultsAdded_EmptyListReturned() {
|
||||
ArrayList<SearchResult> updatedResults = mAdapter.getSearchResults();
|
||||
assertThat(updatedResults).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSingleSourceMerge_ExactCopyReturned() {
|
||||
ArrayList<SearchResult> intentResults = getIntentSampleResults();
|
||||
mAdapter.mergeResults(intentResults, mLoaderClassName);
|
||||
|
||||
ArrayList<SearchResult> updatedResults = mAdapter.getSearchResults();
|
||||
assertThat(updatedResults).containsAllIn(intentResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateSourceMerge_ExactCopyReturned() {
|
||||
ArrayList<SearchResult> intentResults = getIntentSampleResults();
|
||||
mAdapter.mergeResults(intentResults, mLoaderClassName);
|
||||
mAdapter.mergeResults(intentResults, mLoaderClassName);
|
||||
|
||||
ArrayList<SearchResult> updatedResults = mAdapter.getSearchResults();
|
||||
assertThat(updatedResults).containsAllIn(intentResults);
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.Menu;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search2.SearchFeatureProviderImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchFeatureProviderImplTest {
|
||||
private SearchFeatureProviderImpl mProvider;
|
||||
private Activity mActivity;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Menu menu;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
|
||||
mProvider = (SearchFeatureProviderImpl) FeatureFactory.getFactory(mActivity)
|
||||
.getSearchFeatureProvider(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPassNull_NoError() {
|
||||
mProvider.setUpSearchMenu(null,null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUpMenu_HasItemAdded() {
|
||||
mProvider.setUpSearchMenu(menu, mActivity);
|
||||
|
||||
verify(menu).add(anyInt(),anyInt(), anyInt(), anyString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search2.IntentPayload;
|
||||
import com.android.settings.search2.ResultPayload;
|
||||
import com.android.settings.search2.SearchResult;
|
||||
import com.android.settings.search2.SearchResult.Builder;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchResultBuilderTest {
|
||||
|
||||
private Builder mBuilder;
|
||||
private String mTitle;
|
||||
private String mSummary;
|
||||
private ArrayList<String> mBreadcrumbs;
|
||||
private int mRank;
|
||||
private ResultPayload mResultPayload;
|
||||
private Drawable mIcon;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mBuilder = new Builder();
|
||||
mTitle = "title";
|
||||
mSummary = "summary";
|
||||
mBreadcrumbs = new ArrayList<>();
|
||||
mRank = 3;
|
||||
mResultPayload = new IntentPayload(null);
|
||||
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
mIcon = context.getDrawable(R.drawable.ic_search_history);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllInfo_BuildSearchResult() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addSummary(mSummary)
|
||||
.addRank(mRank)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mResultPayload);
|
||||
SearchResult result = mBuilder.build();
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.title).isEqualTo(mTitle);
|
||||
assertThat(result.summary).isEqualTo(mSummary);
|
||||
assertThat(result.rank).isEqualTo(mRank);
|
||||
assertThat(result.breadcrumbs).isEqualTo(mBreadcrumbs);
|
||||
assertThat(result.icon).isEqualTo(mIcon);
|
||||
assertThat(result.payload).isEqualTo(mResultPayload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTitle_BuildSearchResultException() {
|
||||
mBuilder.addSummary(mSummary)
|
||||
.addRank(mRank)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mResultPayload);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSummary_BuildSearchResultException() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addRank(mRank)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mResultPayload);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRank_BuildSearchResultException() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addSummary(mSummary)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mResultPayload);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoBreadcrumbs_BuildSearchResultException() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addSummary(mSummary)
|
||||
.addRank(mRank)
|
||||
.addIcon(mIcon)
|
||||
.addPayload(mResultPayload);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoIcon_BuildSearchResultException() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addSummary(mSummary)
|
||||
.addRank(mRank)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addPayload(mResultPayload);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPayload_BuildSearchResultException() {
|
||||
mBuilder.addTitle(mTitle)
|
||||
.addSummary(mSummary)
|
||||
.addRank(mRank)
|
||||
.addBreadcrumbs(mBreadcrumbs)
|
||||
.addIcon(mIcon);
|
||||
|
||||
SearchResult result = null;
|
||||
try {
|
||||
result = mBuilder.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// passes.
|
||||
}
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.overlay.SupportFeatureProvider;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -43,6 +44,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final LocaleFeatureProvider localeFeatureProvider;
|
||||
public final ApplicationFeatureProvider applicationFeatureProvider;
|
||||
public final EnterprisePrivacyFeatureProvider enterprisePrivacyFeatureProvider;
|
||||
public final SearchFeatureProvider searchFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -72,6 +74,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
localeFeatureProvider = mock(LocaleFeatureProvider.class);
|
||||
applicationFeatureProvider = mock(ApplicationFeatureProvider.class);
|
||||
enterprisePrivacyFeatureProvider = mock(EnterprisePrivacyFeatureProvider.class);
|
||||
searchFeatureProvider = mock(SearchFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,4 +111,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
return enterprisePrivacyFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchFeatureProvider getSearchFeatureProvider(Context context) {
|
||||
return searchFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user