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();
}
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();
}
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);
}
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!");
}
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();
}
Aggregations