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  
18  package org.apache.commons.configuration2.plist;
19  
20  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  
24  import java.io.Reader;
25  import java.util.Calendar;
26  import java.util.SimpleTimeZone;
27  
28  import org.junit.jupiter.api.Test;
29  
30  /**
31   */
32  public class TestPropertyListParser {
33      private final PropertyListParser parser = new PropertyListParser((Reader) null);
34  
35      @Test
36      public void testFilterData() throws Exception {
37          final byte[] expected = {0x20, 0x20};
38          assertArrayEquals(null, parser.filterData(null));
39          assertArrayEquals(expected, parser.filterData("<2020>"));
40          assertArrayEquals(expected, parser.filterData("2020"));
41          assertArrayEquals(expected, parser.filterData("20 20"));
42          assertArrayEquals(new byte[] {9, 0x20}, parser.filterData("920"));
43      }
44  
45      @Test
46      public void testParseDate() throws Exception {
47          final Calendar calendar = Calendar.getInstance();
48          calendar.set(Calendar.YEAR, 2002);
49          calendar.set(Calendar.MONTH, Calendar.MARCH);
50          calendar.set(Calendar.DAY_OF_MONTH, 22);
51          calendar.set(Calendar.HOUR_OF_DAY, 11);
52          calendar.set(Calendar.MINUTE, 30);
53          calendar.set(Calendar.SECOND, 0);
54          calendar.set(Calendar.MILLISECOND, 0);
55          calendar.setTimeZone(new SimpleTimeZone(60 * 60 * 1000, "Apache/Jakarta"));
56  
57          assertEquals(calendar.getTime(), parser.parseDate("<*D2002-03-22 11:30:00 +0100>"));
58      }
59  
60      @Test
61      public void testRemoveQuotes() {
62          assertEquals("abc", parser.removeQuotes("abc"));
63          assertEquals("abc", parser.removeQuotes("\"abc\""));
64          assertEquals("", parser.removeQuotes("\"\""));
65          assertEquals("", parser.removeQuotes(""));
66          assertNull(parser.removeQuotes(null));
67      }
68  
69      @Test
70      public void testUnescapeQuotes() {
71          assertEquals("aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\"bbb\"ccc"));
72          assertEquals("aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\\\"bbb\\\"ccc"));
73      }
74  }