/*
 * Copyright 2010-2019 The jdependency developers.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.vafer.jdependency;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;
import org.vafer.jdependency.utils.DependencyUtils;

public final class DependencyUtilsTestCase {

    public static int getJavaVersion() {
        String version = System.getProperty("java.version");
        if (version.startsWith("1.")) {
            version = version.substring(2);
            final int dotPos = version.indexOf('.');
            final int dashPos = version.indexOf('-');
            return Integer.parseInt(version.substring(0, dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1));
        }
        return Integer.parseInt(version);
    }

    @Test
    public void testShouldFindDependenciesOfClassObject() throws Exception {
        final Set<String> dependencies = DependencyUtils.getDependenciesOfClass(Object.class);
        final Set<String> expectedDependencies = new HashSet<String>(Arrays.asList(
                "java.lang.String",
                "java.lang.IllegalArgumentException",
                "java.lang.CloneNotSupportedException",
                "java.lang.Class",
                "java.lang.InterruptedException",
                "java.lang.Integer",
                "java.lang.Object",
                "java.lang.StringBuilder",
                "java.lang.Throwable"
                ));

        if (getJavaVersion() >= 9) {
            expectedDependencies.add("java.lang.Deprecated");
            expectedDependencies.add("jdk.internal.HotSpotIntrinsicCandidate");
        }

        assertEquals(expectedDependencies, dependencies);
    }
}

@@ -937,25 +937,28 @@
     
-String v
+return parseV
 ersion
- = 
+(
 Syst
@@ -991,111 +991,78 @@
 on%22)
+)
 ;%0A    
+%7D%0A%0A
     
-if (version.startsWith(%221.%22)) %7B%0A            version = version.substring(2);%0A            final
+public static int parseVersion(String version) %7B%0A       
  int
@@ -1101,26 +1101,16 @@
         
- 
-   final 
 int dash
@@ -1149,36 +1149,59 @@
     
-    return Integer.parseInt(
+int len = version.length();%0A        String major = 
 vers
@@ -1269,10 +1269,11 @@
 s : 
-1)
+len
 );%0A 
@@ -1283,49 +1283,232 @@
     
-%7D
+return Integer.parseInt(major);
 %0A    
+%7D%0A%0A
     
-return Integer.parseInt(version
+@Test%0A    public void testVersions() %7B%0A        assertEquals(11, parseVersion(%2211%22));%0A        assertEquals(11, parseVersion(%2211-ea%22));%0A        assertEquals(11, parseVersion(%2211.0.2%22)
 );%0A 

fix the version parsing, added tests