1 /* 2 * Copyright (C) 2016 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.tradefed.util; 17 18 import junit.framework.TestCase; 19 20 import java.util.ArrayList; 21 import java.util.List; 22 23 /** 24 * Unit tests for {@link ConfigCompletor} 25 */ 26 public class ConfigCompletorTest extends TestCase { 27 28 private ConfigCompletor mConfigCompletor; 29 private List<?> mCandidates; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 List<String> fakeConfigs = new ArrayList<String>(); 35 fakeConfigs.add("util/timewaster"); 36 fakeConfigs.add("util/wifi"); 37 fakeConfigs.add("util/wipe"); 38 mConfigCompletor = new ConfigCompletor(fakeConfigs); 39 mCandidates = new ArrayList<>(); 40 } 41 42 /** 43 * Test that when the buffer has no start of configuration it returns all the possibilities. 44 */ 45 public void testFullList() { 46 final String buffer = "run "; 47 mConfigCompletor.complete(buffer, buffer.length(), mCandidates); 48 assertEquals(3, mCandidates.size()); 49 } 50 51 /** 52 * Test that when a partial match is happening, it returns only the concerned matching entries. 53 */ 54 public void testPartialMatch() { 55 final String buffer = "run util/wi"; 56 mConfigCompletor.complete(buffer, buffer.length(), mCandidates); 57 assertEquals(2, mCandidates.size()); 58 assertTrue(mCandidates.contains("util/wifi")); 59 assertTrue(mCandidates.contains("util/wipe")); 60 } 61 } 62