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 package com.android.documentsui.inspector; 17 18 import static junit.framework.Assert.assertEquals; 19 import static junit.framework.Assert.assertFalse; 20 import static junit.framework.Assert.assertNull; 21 import static junit.framework.Assert.assertTrue; 22 23 import android.view.View.OnClickListener; 24 25 import com.android.documentsui.inspector.InspectorController.TableDisplay; 26 27 import java.util.HashMap; 28 import java.util.Map; 29 30 /** 31 * Friendly testable table implementation. 32 */ 33 class TestTable implements TableDisplay { 34 35 private Map<Integer, CharSequence> mRows; 36 private boolean mVisible; 37 TestTable()38 public TestTable() { 39 mRows = new HashMap<>(); 40 } 41 assertHasRow(int keyId, CharSequence expected)42 public void assertHasRow(int keyId, CharSequence expected) { 43 assertEquals(expected, mRows.get(keyId)); 44 } 45 assertNotInTable(int keyId)46 public void assertNotInTable (int keyId) { 47 assertNull(mRows.get(keyId)); 48 } 49 50 @Override put(int keyId, CharSequence value)51 public void put(int keyId, CharSequence value) { 52 mRows.put(keyId, value); 53 } 54 55 @Override put(int keyId, CharSequence value, OnClickListener callback)56 public void put(int keyId, CharSequence value, OnClickListener callback) { 57 mRows.put(keyId, value); 58 } 59 60 @Override setVisible(boolean visible)61 public void setVisible(boolean visible) { 62 mVisible = visible; 63 } 64 65 @Override isEmpty()66 public boolean isEmpty() { 67 return mRows.isEmpty(); 68 } 69 assertEmpty()70 void assertEmpty() { 71 assertTrue(mRows.isEmpty()); 72 } 73 assertNotEmpty()74 void assertNotEmpty() { 75 assertFalse(mRows.isEmpty()); 76 } 77 assertVisible(boolean expected)78 void assertVisible(boolean expected) { 79 assertEquals(expected, mVisible); 80 } 81 } 82