1 /* 2 * Copyright (C) 2017 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 com.android.tv.testing; 18 19 import android.database.Cursor; 20 import java.util.ArrayList; 21 import java.util.List; 22 23 /** Static utilities for testing using databases. */ 24 public final class DbTestingUtils { 25 toList(Cursor cursor)26 public static List<List<String>> toList(Cursor cursor) { 27 ArrayList<List<String>> result = new ArrayList<>(); 28 int colCount = cursor.getColumnCount(); 29 while (cursor.moveToNext()) { 30 List<String> row = new ArrayList<>(colCount); 31 for (int i = 0; i < colCount; i++) { 32 row.add(cursor.isNull(i) ? "null" : cursor.getString(i)); 33 } 34 result.add(row); 35 } 36 return result; 37 } 38 DbTestingUtils()39 private DbTestingUtils() {} 40 } 41