<commit_before>/*
 * Copyright 2014 the original author or authors.
 *
 * 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.gradle.java

import org.gradle.api.JavaVersion
import org.gradle.integtests.fixtures.AvailableJavaHomes
import org.gradle.integtests.fixtures.MultiVersionIntegrationSpec
import org.gradle.integtests.fixtures.TargetVersions
import org.gradle.internal.jvm.JavaInfo
import org.gradle.util.TextUtil
import org.junit.Assume

@TargetVersions(["1.5", "1.6", "1.7", "1.8"])
class JavaCrossCompilationIntegrationTest extends MultiVersionIntegrationSpec {
    def JavaInfo getTarget() {
        return AvailableJavaHomes.getJdk(JavaVersion.toVersion(version))
    }

    def "can compile source and run tests using target java version"() {
        Assume.assumeTrue(target != null)
        def java = TextUtil.escapeString(target.getJavaExecutable())
        def javac = TextUtil.escapeString(target.getExecutable("javac"))

        buildFile << """
apply plugin: 'java'
repositories { mavenCentral() }
dependencies { testCompile 'junit:junit:4.11' }
tasks.withType(JavaCompile) {
    options.with {
        fork = true
        forkOptions.executable = "$javac"
    }
}
tasks.withType(Test) {
    executable = "$java"
}
"""

        file("src/main/java/Thing.java") << """
class Thing { }
"""
        file("src/test/java/ThingTest.java") << """
import org.junit.Test;
import static org.junit.Assert.*;

public class ThingTest {
    @Test
    public void verify() {
        assertTrue(System.getProperty("java.version").startsWith("${version}."));
    }
}
"""

        expect:
        succeeds 'test'
    }
}<commit_msg>Added some test coverage for testng execution under different java versions.<commit_after>/*
 * Copyright 2014 the original author or authors.
 *
 * 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.gradle.java

import org.gradle.api.JavaVersion
import org.gradle.integtests.fixtures.AvailableJavaHomes
import org.gradle.integtests.fixtures.MultiVersionIntegrationSpec
import org.gradle.integtests.fixtures.TargetVersions
import org.gradle.internal.jvm.JavaInfo
import org.gradle.util.TextUtil
import org.junit.Assume

@TargetVersions(["1.5", "1.6", "1.7", "1.8"])
class JavaCrossCompilationIntegrationTest extends MultiVersionIntegrationSpec {
    def JavaInfo getTarget() {
        return AvailableJavaHomes.getJdk(JavaVersion.toVersion(version))
    }

    def setup() {
        Assume.assumeTrue(target != null)
        def java = TextUtil.escapeString(target.getJavaExecutable())
        def javac = TextUtil.escapeString(target.getExecutable("javac"))

        buildFile << """
apply plugin: 'java'
sourceCompatibility = ${version}
targetCompatibility = ${version}
repositories { mavenCentral() }
tasks.withType(JavaCompile) {
    options.with {
        fork = true
        forkOptions.executable = "$javac"
    }
}
tasks.withType(Test) {
    executable = "$java"
}
"""

        file("src/main/java/Thing.java") << """
class Thing { }
"""
    }

    def "can compile source and run JUnit tests using target Java version"() {
        given:
        buildFile << """
dependencies { testCompile 'junit:junit:4.11' }
"""

        file("src/test/java/ThingTest.java") << """
import org.junit.Test;
import static org.junit.Assert.*;

public class ThingTest {
    @Test
    public void verify() {
        assertTrue(System.getProperty("java.version").startsWith("${version}."));
    }
}
"""

        expect:
        succeeds 'test'
    }

    def "can compile source and run TestNG tests using target Java version"() {
        given:
        buildFile << """
dependencies { testCompile 'org.testng:testng:6.8.8' }
"""

        file("src/test/java/ThingTest.java") << """
import org.testng.annotations.Test;

public class ThingTest {
    @Test
    public void verify() {
        assert System.getProperty("java.version").startsWith("${version}.");
    }
}
"""

        expect:
        succeeds 'test'
    }
}
{'fraction_non_alphanumeric': 0.1168909419562161, 'fraction_numerical': 0.008234585258083953, 'mean_word_length': 3.510869565217391, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6749065', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1420, 'n_words': 395}