blob: 67cc53c3a7a5b60423f0d0721bab35e8c37be967 [file] [log] [blame]
sidchhabraa7c8f8a2020-01-16 18:38:17 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app.appsearch;
18
Alexander Dorokhinee708e182020-03-06 15:30:34 -080019import static com.google.common.truth.Truth.assertThat;
sidchhabraa7c8f8a2020-01-16 18:38:17 -080020
21import static org.testng.Assert.assertThrows;
22
23import androidx.test.filters.SmallTest;
24
25import com.google.android.icing.proto.DocumentProto;
26import com.google.android.icing.proto.SearchResultProto;
27
28import org.junit.Test;
29
30@SmallTest
31public class SearchResultsTest {
32
33 @Test
34 public void testSearchResultsEqual() {
35 final String uri = "testUri";
36 final String schemaType = "testSchema";
37 SearchResultProto.ResultProto result1 = SearchResultProto.ResultProto.newBuilder()
38 .setDocument(DocumentProto.newBuilder()
39 .setUri(uri)
40 .setSchema(schemaType)
41 .build())
42 .build();
43 SearchResultProto searchResults1 = SearchResultProto.newBuilder()
44 .addResults(result1)
45 .build();
46 SearchResults res1 = new SearchResults(searchResults1);
47 SearchResultProto.ResultProto result2 = SearchResultProto.ResultProto.newBuilder()
48 .setDocument(DocumentProto.newBuilder()
49 .setUri(uri)
50 .setSchema(schemaType)
51 .build())
52 .build();
53 SearchResultProto searchResults2 = SearchResultProto.newBuilder()
54 .addResults(result2)
55 .build();
56 SearchResults res2 = new SearchResults(searchResults2);
57 assertThat(res1.toString()).isEqualTo(res2.toString());
58 }
59
60 @Test
61 public void buildSearchSpecWithoutTermMatchType() {
62 assertThrows(RuntimeException.class, () -> SearchSpec.newBuilder()
63 .setSchemaTypes("testSchemaType")
64 .build());
65 }
66}