Search in sources :

Example 16 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class AndroidAppPluginTest method assembleDebugIncrementalShouldntLeak.

@Test
public void assembleDebugIncrementalShouldntLeak() throws Exception {
    writeFile(buildFile, // language="Groovy"
    "buildscript {\n" + "    repositories {\n" + "        maven { url 'https://maven.google.com' }\n" + "        jcenter()\n" + "    }\n" + "    \n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "        classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'com.android.application'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    maven { url 'https://maven.google.com' }\n" + "    mavenCentral()\n" + "}\n" + "\n" + "android {\n" + "    compileSdkVersion 24\n" + "    buildToolsVersion '" + buildToolsVersion + "'\n" + "    \n" + "    defaultConfig {\n" + "        minSdkVersion 15\n" + "        targetSdkVersion 24\n" + "    }\n" + "}");
    File manifestFile = new File(rootDir, "src/main/AndroidManifest.xml");
    writeFile(manifestFile, // language="XML"
    "<manifest package=\"test.test\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + "    <application/>\n" + "</manifest>");
    File javaFile = new File(rootDir, "src/main/java/MainActivity.java");
    writeFile(javaFile, "package test;" + "import android.app.Activity;" + "import android.os.Bundle;" + "import android.util.Log;" + "public class MainActivity extends Activity {\n" + "    public void onCreate(Bundle savedInstanceState) {\n" + "        Runnable lambda = () -> Log.d(\"MainActivity\", \"Hello, Lambda!\");\n" + "        lambda.run();\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("assembleDebug", "--stacktrace", "-Pandroid.enableAapt2=false").forwardStdError(errorOutput).build();
    assertThat(result.task(":assembleDebug").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    File mainClassFile = findFile(rootDir, "MainActivity.class");
    File lambdaClassFile = findFile(rootDir, "MainActivity$$Lambda$1.class");
    assertThat(mainClassFile).exists();
    assertThat(lambdaClassFile).exists();
    // delete the java file
    if (!javaFile.delete()) {
        throw new Exception("Failed to delete file: " + javaFile);
    }
    errorOutput = new StringWriter();
    result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("assembleDebug", "--stacktrace", "-Pandroid.enableAapt2=false", "--debug").forwardStdError(errorOutput).build();
    assertThat(result.task(":assembleDebug").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertThat(mainClassFile).doesNotExist();
    assertThat(lambdaClassFile).doesNotExist();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 17 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class AndroidAppPluginTest method assembleDebug.

@Test
public void assembleDebug() throws Exception {
    writeFile(buildFile, // language="Groovy"
    "buildscript {\n" + "    System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'\n" + "    \n" + "    repositories {\n" + "        maven { url 'https://maven.google.com' }\n" + "        jcenter()\n" + "    }\n" + "    \n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "        classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'com.android.application'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    maven { url 'https://maven.google.com' }\n" + "    mavenCentral()\n" + "}\n" + "\n" + "android {\n" + "    compileSdkVersion 24\n" + "    buildToolsVersion '" + buildToolsVersion + "'\n" + "    \n" + "    defaultConfig {\n" + "        minSdkVersion 15\n" + "        targetSdkVersion 24\n" + "    }\n" + "}");
    File manifestFile = new File(rootDir, "src/main/AndroidManifest.xml");
    writeFile(manifestFile, // language="XML"
    "<manifest package=\"test.test\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + "    <application/>\n" + "</manifest>");
    File javaFile = new File(rootDir, "src/main/java/MainActivity.java");
    writeFile(javaFile, "package test;" + "import android.app.Activity;" + "import android.os.Bundle;" + "import android.util.Log;" + "public class MainActivity extends Activity {\n" + "    public void onCreate(Bundle savedInstanceState) {\n" + "        Runnable lambda = () -> Log.d(\"MainActivity\", \"Hello, Lambda!\");\n" + "        lambda.run();\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("assembleDebug", "--stacktrace", "-Pandroid.enableAapt2=false").forwardStdError(errorOutput).build();
    assertThat(result.task(":assembleDebug").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    File mainClassFile = findFile(rootDir, "MainActivity.class");
    File lambdaClassFile = findFile(rootDir, "MainActivity$$Lambda$1.class");
    assertThat(mainClassFile).exists();
    assertThat(lambdaClassFile).exists();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 18 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class AndroidLibPluginTest method unitTest.

@Test
public void unitTest() throws Exception {
    writeFile(buildFile, // language="Groovy"
    "buildscript {\n" + "    repositories {\n" + "        maven { url 'https://maven.google.com' }\n" + "        jcenter()\n" + "    }\n" + "    \n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "        classpath 'com.android.tools.build:gradle:" + androidVersion + "'\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'com.android.library'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    maven { url 'https://maven.google.com' }\n" + "    mavenCentral()\n" + "}\n" + "\n" + "android {\n" + "    compileSdkVersion " + compileSdkVersion + "\n" + "    buildToolsVersion '" + buildToolsVersion + "'\n" + "    \n" + "    defaultConfig {\n" + "        minSdkVersion 15\n" + "        targetSdkVersion 24\n" + "    }\n" + "}\n" + "\n" + "dependencies {\n" + "    testCompile 'junit:junit:4.12'\n" + "}");
    File manifestFile = new File(rootDir, "src/main/AndroidManifest.xml");
    writeFile(manifestFile, // language="XML"
    "<manifest package=\"test.test\" " + "xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + "    <application/>\n" + "</manifest>");
    File javaFile = new File(rootDir, "src/main/java/Main.java");
    writeFile(javaFile, "import java.util.concurrent.Callable;\n" + "\n" + "public class Main {\n" + "    public static Callable<String> f() {\n" + "        return () -> \"Hello, Lambda Test!\";\n" + "    }\n" + "}");
    File testJavaFile = new File(rootDir, "src/test/java/Test.java");
    writeFile(testJavaFile, "import org.junit.Assert;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.JUnit4;\n" + "\n" + "import java.util.concurrent.Callable;\n" + "\n" + "@RunWith(JUnit4.class)\n" + "public class Test {\n" + "    @org.junit.Test\n" + "    public void test() throws Exception {\n" + "        Runnable lambda = () -> Assert.assertTrue(true);\n" + "        lambda.run();\n" + "        Assert.assertEquals(\"Hello, Lambda Test!\", Main.f().call());\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("test", "--stacktrace").forwardStdError(errorOutput).build();
    assertThat(result.task(":test").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 19 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class GroovyPluginTest method run.

@Test
public void run() throws Exception {
    writeFile(buildFile, "buildscript {\n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'groovy'\n" + "apply plugin: 'application'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    mavenCentral()\n" + "}\n" + "\n" + "dependencies {\n" + "    compile 'org.codehaus.groovy:groovy-all:2.4.7'\n" + "}\n" + "\n" + "mainClassName = \"Main\"\n" + "\n" + "jar {\n" + "    manifest {\n" + "        attributes 'Main-Class': mainClassName\n" + "    }\n" + "}");
    File javaFile = new File(rootDir, "src/main/java/Main.java");
    writeFile(javaFile, "public class Main {\n" + "    public static void main(String[] args) {\n" + "        Runnable lambda = () -> System.out.println(\"Hello, Lambda Run!\");\n" + "        lambda.run();\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("run").forwardStdError(errorOutput).build();
    assertThat(result.task(":run").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertThat(result.getOutput()).contains("Hello, Lambda Run!");
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) TestHelpers.findFile(me.tatarka.TestHelpers.findFile) File(java.io.File) TestHelpers.writeFile(me.tatarka.TestHelpers.writeFile) Test(org.junit.Test)

Example 20 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project gradle-retrolambda by evant.

the class GroovyPluginTest method assemble.

@Test
public void assemble() throws Exception {
    writeFile(buildFile, "buildscript {\n" + "    dependencies {\n" + "        classpath files(" + getPluginClasspath() + ")\n" + "    }\n" + "}\n" + "\n" + "apply plugin: 'groovy'\n" + "apply plugin: 'me.tatarka.retrolambda'\n" + "\n" + "repositories {\n" + "    mavenCentral()\n" + "}\n" + "\n" + "dependencies {\n" + "    compile 'org.codehaus.groovy:groovy-all:2.4.7'\n" + "}");
    File javaFile = new File(rootDir, "src/main/java/Main.java");
    writeFile(javaFile, "public class Main {\n" + "    public static void main(String[] args) {\n" + "        Runnable lambda = () -> System.out.println(\"Hello, Lambda!\");\n" + "        lambda.run();\n" + "    }\n" + "}");
    StringWriter errorOutput = new StringWriter();
    BuildResult result = GradleRunner.create().withGradleVersion(gradleVersion).withProjectDir(rootDir).withArguments("assemble", "--stacktrace").forwardStdError(errorOutput).build();
    assertThat(result.task(":assemble").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    File mainClassFile = findFile(rootDir, "Main.class");
    File lambdaClassFile = findFile(rootDir, "Main$$Lambda$1.class");
    assertThat(mainClassFile).exists();
    assertThat(lambdaClassFile).exists();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) StringWriter(java.io.StringWriter) TestHelpers.findFile(me.tatarka.TestHelpers.findFile) File(java.io.File) TestHelpers.writeFile(me.tatarka.TestHelpers.writeFile) Test(org.junit.Test)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)149 File (java.io.File)65 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)21 StringWriter (java.io.StringWriter)19 GradleRunner (org.gradle.testkit.runner.GradleRunner)17 Test (org.testng.annotations.Test)10 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)8 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TestHelpers.findFile (me.tatarka.TestHelpers.findFile)6 TestHelpers.writeFile (me.tatarka.TestHelpers.writeFile)6 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 Path (java.nio.file.Path)5 BuildTask (org.gradle.testkit.runner.BuildTask)5