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