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   *   https://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  
20  package org.apache.commons.compress.utils;
21  
22  import static org.junit.jupiter.api.Assertions.assertEquals;
23  import static org.junit.jupiter.api.Assertions.assertThrows;
24  
25  import java.io.IOException;
26  
27  import org.junit.jupiter.params.ParameterizedTest;
28  import org.junit.jupiter.params.provider.ValueSource;
29  
30  /**
31   * Tests for class {@link ParsingUtils}.
32   *
33   * @see ParsingUtils
34   */
35  class ParsingUtilsTest {
36  
37      @ParameterizedTest
38      @ValueSource(strings = {Integer.MIN_VALUE + "1", "x.x", "9e999", "1.1", "one", Integer.MAX_VALUE + "1"})
39      void testParseIntValueInvalidValues(final String value) {
40          assertThrows(IOException.class, () -> ParsingUtils.parseIntValue(value, 10));
41      }
42  
43      @ParameterizedTest
44      @ValueSource(strings = {Integer.MIN_VALUE + "", "-1", "1", "123456", Integer.MAX_VALUE + ""})
45      void testParseIntValueValidValues(final String value) throws Exception {
46          assertEquals(Long.parseLong(value), ParsingUtils.parseIntValue(value, 10));
47      }
48  
49      @ParameterizedTest
50      @ValueSource(strings = {Long.MIN_VALUE + "1", "x.x", "9e999", "1.1", "one", Long.MAX_VALUE + "1"})
51      void testParseLongValueInvalidValues(final String value) {
52          assertThrows(IOException.class, () -> ParsingUtils.parseLongValue(value, 10));
53      }
54  
55      @ParameterizedTest
56      @ValueSource(strings = {Long.MIN_VALUE + "", "-1", "1", "12345678901234", Long.MAX_VALUE + ""})
57      void testParseLongValueValidValues(final String value) throws Exception {
58          assertEquals(Long.parseLong(value), ParsingUtils.parseLongValue(value, 10));
59      }
60  
61  }