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.juneau.collections;
18  
19  import static org.apache.juneau.common.utils.Utils.*;
20  import static org.junit.jupiter.api.Assertions.*;
21  
22  import org.apache.juneau.*;
23  import org.junit.jupiter.api.*;
24  
25  class Args_Test extends TestBase {
26  
27  	//-----------------------------------------------------------------------------------------------------------------
28  	// test - Basic tests
29  	//-----------------------------------------------------------------------------------------------------------------
30  	@Test void basic() {
31  		var a = new Args(a());
32  
33  		// Empty args
34  		assertNull(a.getArg(0));
35  		assertNull(a.getArg(1));
36  		assertNull(a.getArg(-1));
37  		assertNull(a.getArg("foo"));
38  		assertEquals(0, a.getArgs("foo").size());
39  		assertFalse(a.containsKey("foo"));
40  
41  		a = new Args(new String[]{"foo"});
42  		assertEquals("foo", a.getArg(0));
43  		assertNull(a.getArg(1));
44  		assertNull(a.getArg(-1));
45  		assertNull(a.getArg("foo"));
46  		assertEquals(0, a.getArgs("foo").size());
47  		assertFalse(a.containsKey("foo"));
48  
49  		a = new Args(new String[]{"foo", "bar bar"});
50  		assertEquals("foo", a.getArg(0));
51  		assertEquals("bar bar", a.getArg(1));
52  		assertNull(a.getArg(-1));
53  		assertNull(a.getArg("foo"));
54  		assertEquals(0, a.getArgs("foo").size());
55  		assertFalse(a.containsKey("foo"));
56  
57  		a = new Args(new String[]{"foo", "bar bar", "-foo"});
58  		assertEquals("foo", a.getArg(0));
59  		assertEquals("bar bar", a.getArg(1));
60  		assertNull(a.getArg(-1));
61  		assertNull(a.getArg("foo"));
62  		assertEquals(0, a.getArgs("foo").size());
63  		assertTrue(a.containsKey("foo"));
64  
65  		a = new Args(new String[]{"foo", "bar bar", "-foo", "bar bar"});
66  		assertEquals("foo", a.getArg(0));
67  		assertEquals("bar bar", a.getArg(1));
68  		assertNull(a.getArg(-1));
69  		assertEquals("bar bar", a.getArg("foo"));
70  		assertEquals(1, a.getArgs("foo").size());
71  		assertEquals("bar bar", a.getArgs("foo").get(0));
72  		assertTrue(a.containsKey("foo"));
73  	}
74  }