Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
10   55   7   3.33
6   23   0.7   3
3     2.33  
1    
5% of code in this file is excluded from these metrics.
 
  JComboBoxItemIndexValidator       Line # 34 10 5% 7 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Nov 10, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.driver;
17   
18    import static java.lang.String.valueOf;
19    import static org.fest.util.Strings.concat;
20   
21    import javax.swing.JComboBox;
22   
23    import org.fest.swing.annotation.RunsInCurrentThread;
24   
25    /**
26    * Understands verification that a given number is a valid index of an item in a <code>{@link JComboBox}</code>.
27    * <p>
28    * <b>Note:</b> Methods in this class are <b>not</b> executed in the event dispatch thread (EDT.) Clients are
29    * responsible for invoking them in the EDT.
30    * </p>
31    *
32    * @author Alex Ruiz
33    */
 
34    final class JComboBoxItemIndexValidator {
35   
 
36  18 toggle @RunsInCurrentThread
37    static void validateIndex(JComboBox comboBox, int index) {
38  2 if (index < 0) throw invalidIndex(concat(itemIndex(index), " should not be less than zero"));
39  16 int itemCount = comboBox.getItemCount();
40  1 if (itemCount == 0) throw invalidIndex("JComboBox is empty");
41  13 if (index >= 0 && index < itemCount) return;
42  2 throw invalidIndex(concat(
43    itemIndex(index), " should be between [", valueOf(0), "] and [", valueOf(itemCount - 1), "] (inclusive)"));
44    }
45   
 
46  4 toggle private static String itemIndex(int index) {
47  4 return concat("Item index (", valueOf(index), ")");
48    }
49   
 
50  5 toggle private static IndexOutOfBoundsException invalidIndex(String msg) {
51  5 throw new IndexOutOfBoundsException(msg);
52    }
53   
 
54    toggle private JComboBoxItemIndexValidator() {}
55    }