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.http;
18  
19  import static org.apache.juneau.StringRanges.*;
20  import static org.apache.juneau.commons.utils.CollectionUtils.*;
21  import static org.apache.juneau.junit.bct.BctAssertions.*;
22  import static org.junit.jupiter.api.Assertions.*;
23  
24  import org.apache.juneau.*;
25  import org.junit.jupiter.api.*;
26  
27  class StringRanges_Test extends TestBase {
28  
29  	@Test void a01_match() {
30  		var x = l("foo","bar","baz");
31  
32  		assertEquals(-1, of((String)null).match(x));
33  
34  		assertEquals(1, of("foo;q=0.5,bar").match(x));
35  		assertEquals(1, of("foo;q=0.5,bar").match(x));
36  		assertEquals(0, of("foo,*").match(x));
37  		assertEquals(1, of("*,bar").match(x));
38  		assertEquals(0, of("foo;q=0.6,bar;q=0.5").match(x));
39  		assertEquals(0, of("foo;q=0.6,bar;q=0.5,qux").match(x));
40  		assertEquals(-1, of("qux").match(x));
41  		assertEquals(-1, of("qux,q2x;q=0").match(x));
42  		assertEquals(-1, of("foo;q=0").match(x));
43  	}
44  
45  	@Test void a02_getRange() {
46  		assertNotNull(of("foo").getRange(0));
47  		assertNull(of((String)null).getRange(0));
48  		assertNull(of("").getRange(0));
49  		assertNull(of((String)null).getRange(-1));
50  		assertNull(of((String)null).getRange(1));
51  	}
52  
53  	@Test void a03_getRanges() {
54  		assertList(of("foo").toList(), "foo");
55  		assertEmpty(of((String)null).toList());
56  	}
57  
58  	@Test void a04_toString() {
59  		assertString("*", new StringRange("*"));
60  		assertString("qux, bar;q=0.9, foo;q=0.6", of("foo;q=0.6,bar;q=0.9,qux"));
61  	}
62  }