sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app.appsearch; |
| 18 | |
Alexander Dorokhine | e708e18 | 2020-03-06 15:30:34 -0800 | [diff] [blame^] | 19 | import static com.google.common.truth.Truth.assertThat; |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 20 | |
| 21 | import static org.testng.Assert.assertThrows; |
| 22 | |
| 23 | import androidx.test.filters.SmallTest; |
| 24 | |
| 25 | import com.google.android.icing.proto.DocumentProto; |
| 26 | import com.google.android.icing.proto.SearchResultProto; |
| 27 | |
| 28 | import org.junit.Test; |
| 29 | |
| 30 | @SmallTest |
| 31 | public 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 | } |