test/jdk/tools/jpackage/junit/jdk/jpackage/internal/DottedVersionTest.java
branchJDK-8200758-branch
changeset 58890 6539ad1d90aa
parent 58696 61c44899b4eb
equal deleted inserted replaced
58889:f04c0704a006 58890:6539ad1d90aa
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 package jdk.jpackage.internal;
    23 package jdk.jpackage.internal;
    24 
    24 
       
    25 import java.util.Collections;
       
    26 import java.util.List;
       
    27 import java.util.function.Function;
    25 import java.util.stream.Stream;
    28 import java.util.stream.Stream;
    26 import org.junit.Assert;
       
    27 import org.junit.Rule;
    29 import org.junit.Rule;
    28 import org.junit.Test;
    30 import org.junit.Test;
    29 import org.junit.rules.ExpectedException;
    31 import org.junit.rules.ExpectedException;
    30 import static org.junit.Assert.*;
    32 import static org.junit.Assert.*;
       
    33 import org.junit.runner.RunWith;
       
    34 import org.junit.runners.Parameterized;
    31 
    35 
       
    36 @RunWith(Parameterized.class)
    32 public class DottedVersionTest {
    37 public class DottedVersionTest {
       
    38 
       
    39     public DottedVersionTest(boolean greedy) {
       
    40         this.greedy = greedy;
       
    41         if (greedy) {
       
    42             createTestee = DottedVersion::greedy;
       
    43         } else {
       
    44             createTestee = DottedVersion::lazy;
       
    45         }
       
    46     }
       
    47 
       
    48     @Parameterized.Parameters
       
    49     public static List<Object[]> data() {
       
    50         return List.of(new Object[] { true }, new Object[] { false });
       
    51     }
    33 
    52 
    34     @Rule
    53     @Rule
    35     public ExpectedException exceptionRule = ExpectedException.none();
    54     public ExpectedException exceptionRule = ExpectedException.none();
    36 
    55 
    37     @Test
    56     @Test
    38     public void testValid() {
    57     public void testValid() {
    39         Stream.of(
    58         final List<String> validStrings = List.of(
    40             "1.0",
    59             "1.0",
    41             "1",
    60             "1",
    42             "2.234.045",
    61             "2.234.045",
    43             "2.234.0",
    62             "2.234.0",
    44             "0",
    63             "0",
    45             "0.1"
    64             "0.1"
    46         ).forEach(value -> {
    65         );
    47             DottedVersion version = new DottedVersion(value);
    66 
       
    67         final List<String> validLazyStrings;
       
    68         if (greedy) {
       
    69             validLazyStrings = Collections.emptyList();
       
    70         } else {
       
    71             validLazyStrings = List.of(
       
    72                 "1.-1",
       
    73                 "5.",
       
    74                 "4.2.",
       
    75                 "3..2",
       
    76                 "2.a",
       
    77                 "0a",
       
    78                 ".",
       
    79                 " ",
       
    80                 " 1",
       
    81                 "1. 2",
       
    82                 "+1",
       
    83                 "-1",
       
    84                 "-0",
       
    85                 "1234567890123456789012345678901234567890"
       
    86             );
       
    87         }
       
    88 
       
    89         Stream.concat(validStrings.stream(), validLazyStrings.stream())
       
    90         .forEach(value -> {
       
    91             DottedVersion version = createTestee.apply(value);
    48             assertEquals(version.toString(), value);
    92             assertEquals(version.toString(), value);
    49         });
    93         });
    50     }
    94     }
    51 
    95 
    52     @Test
    96     @Test
    53     public void testNull() {
    97     public void testNull() {
    54         exceptionRule.expect(NullPointerException.class);
    98         exceptionRule.expect(NullPointerException.class);
    55         new DottedVersion(null);
    99         createTestee.apply(null);
    56     }
   100     }
    57 
   101 
    58     @Test
   102     @Test
    59     public void testEmpty() {
   103     public void testEmpty() {
    60         exceptionRule.expect(IllegalArgumentException.class);
   104         if (greedy) {
    61         exceptionRule.expectMessage("Version may not be empty string");
   105             exceptionRule.expect(IllegalArgumentException.class);
    62         new DottedVersion("");
   106             exceptionRule.expectMessage("Version may not be empty string");
       
   107             createTestee.apply("");
       
   108         } else {
       
   109             assertTrue(0 == createTestee.apply("").compareTo(""));
       
   110             assertTrue(0 == createTestee.apply("").compareTo("0"));
       
   111         }
    63     }
   112     }
       
   113 
       
   114     private final boolean greedy;
       
   115     private final Function<String, DottedVersion> createTestee;
    64 }
   116 }