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