View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.impl;
20  
21  import java.util.Iterator;
22  import java.util.Map.Entry;
23  import java.util.NoSuchElementException;
24  import java.util.Properties;
25  import java.util.Set;
26  
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertEquals;
30  import static org.junit.jupiter.api.Assertions.assertFalse;
31  import static org.junit.jupiter.api.Assertions.assertNotNull;
32  import static org.junit.jupiter.api.Assertions.assertThrows;
33  import static org.junit.jupiter.api.Assertions.assertTrue;
34  
35  class PropertiesAsMapTest {
36  
37      @Test
38      void testPropertiesAsMap() {
39          Properties props = new Properties();
40          props.setProperty("foo1", "bar1");
41          props.setProperty("foo2", "bar2");
42          PropertiesAsMap pam = new PropertiesAsMap(props);
43          assertEquals(2, pam.size());
44          Set<Entry<String, String>> set = pam.entrySet();
45          assertNotNull(set);
46          assertEquals(2, set.size());
47          Iterator<Entry<String, String>> iterator = set.iterator();
48          assertNotNull(iterator);
49          assertTrue(iterator.hasNext());
50          assertTrue(iterator.hasNext());
51          Entry<String, String> entry = iterator.next();
52          assertNotNull(entry);
53          entry = iterator.next();
54          assertNotNull(entry);
55          assertThrows(NoSuchElementException.class, () -> iterator.next());
56          assertFalse(iterator.hasNext());
57      }
58  }