View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections4;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertTrue;
21  
22  import java.util.TreeMap;
23  
24  import org.apache.commons.collections4.map.AbstractMapTest;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests TreeMap.
29   */
30  public abstract class AbstractTreeMapTest<K, V> extends AbstractMapTest<K, V> {
31  
32      public AbstractTreeMapTest(final String testName) {
33          super(testName);
34      }
35  
36      @Override
37      public boolean isAllowNullKey() {
38          return false;
39      }
40  
41      /**
42       * {@inheritDoc}
43       */
44      @Override
45      public abstract TreeMap<K, V> makeObject();
46  
47      @Test
48      public void testNewMap() {
49          final TreeMap<K, V> map = makeObject();
50          assertTrue(map.isEmpty(), "New map is empty");
51          assertEquals(0, map.size(), "New map has size zero");
52      }
53  
54      @Test
55      @SuppressWarnings("unchecked")
56      public void testSearch() {
57          final TreeMap<K, V> map = makeObject();
58          map.put((K) "first", (V) "First Item");
59          map.put((K) "second", (V) "Second Item");
60          assertEquals("First Item", map.get("first"),
61                  "Top item is 'Second Item'");
62          assertEquals("Second Item", map.get("second"),
63                  "Next Item is 'First Item'");
64      }
65  
66  }