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.documentsui.selection; 18 19 import static junit.framework.Assert.assertEquals; 20 import static junit.framework.Assert.assertFalse; 21 import static junit.framework.Assert.assertTrue; 22 23 import java.util.HashSet; 24 import java.util.Set; 25 26 public class TestItemSelectionListener implements SelectionManager.ItemCallback { 27 28 private final Set<String> mSelected = new HashSet<>(); 29 30 @Override 31 public void onItemStateChanged(String id, boolean selected) { 32 if (selected) { 33 assertNotSelected(id); 34 mSelected.add(id); 35 } else { 36 assertSelected(id); 37 mSelected.remove(id); 38 } 39 } 40 41 @Override 42 public void onSelectionReset() { 43 mSelected.clear(); 44 } 45 46 void assertNoSelection() { 47 assertTrue(mSelected.isEmpty()); 48 } 49 50 void assertSelectionSize(int expected) { 51 assertEquals(expected, mSelected.size()); 52 } 53 54 void assertSelected(String id) { 55 assertTrue(id + " is not selected.", mSelected.contains(id)); 56 } 57 58 void assertNotSelected(String id) { 59 assertFalse(id + " is already selected", mSelected.contains(id)); 60 } 61 } 62