1 /*
2  * Copyright (C) 2007 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.database;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.database.TranslatingCursor.Translator;
22 import android.net.Uri;
23 
24 import junit.framework.TestCase;
25 
26 public class TranslatingCursorTest extends TestCase {
27 
testDuplicateColumnName()28     public void testDuplicateColumnName() {
29         MatrixCursor base = new MatrixCursor(new String[] {"_id", "colA", "colB", "colA"});
30         base.addRow(new Object[] { 0, "r1_a", "r1_b", "r1_a"});
31         base.addRow(new Object[] { 1, "r2_a", "r2_b", "r2_a"});
32         Translator translator = (data, idIndex, matchingColumn, cursor) -> data.toUpperCase();
33         TranslatingCursor.Config config = new TranslatingCursor.Config(Uri.EMPTY, "_id", "colA");
34         TranslatingCursor translating = new TranslatingCursor(base, config, translator, false);
35 
36         translating.moveToNext();
37         String[] expected = new String[] { "ignored", "R1_A", "r1_b", "R1_A" };
38         for (int i = 1; i < translating.getColumnCount(); i++) {
39             assertThat(translating.getString(i)).isEqualTo(expected[i]);
40         }
41         translating.moveToNext();
42         expected = new String[] { "ignored", "R2_A", "r2_b", "R2_A" };
43         for (int i = 1; i < translating.getColumnCount(); i++) {
44             assertThat(translating.getString(i)).isEqualTo(expected[i]);
45         }
46     }
47 
48 }
49