forked from gradle/gradle-java-modules
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from TheMrMilchmann/master
Add support for TestNG
- Loading branch information
Showing
9 changed files
with
328 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2017 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 com.zyxist.chainsaw.tests; | ||
|
||
import com.zyxist.chainsaw.ChainsawPlugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class TestNG implements TestEngine { | ||
private static final Logger LOGGER = Logging.getLogger(ChainsawPlugin.class); | ||
|
||
private static final String TESTNG_GROUP = "org.testng"; | ||
private static final String TESTNG_ARTIFACT = "testng"; | ||
|
||
private static final String TESTNG_MODULE_NAME = "testng"; | ||
|
||
@Override | ||
public boolean accepts(Project project) { | ||
return TestEngine.checkTestDependencies(project, dep -> dep.getGroup().equals(TESTNG_GROUP) && dep.getName().equals(TESTNG_ARTIFACT)); | ||
} | ||
|
||
@Override | ||
public List<String> getTestEngineModules() { | ||
return Arrays.asList(TESTNG_MODULE_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...st/groovy/com/zyxist/chainsaw/builder/factory/TestNGExportedTestPackageTestFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2017 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 com.zyxist.chainsaw.builder.factory | ||
|
||
import com.zyxist.chainsaw.builder.JavaCodeFactory | ||
import com.zyxist.chainsaw.builder.JigsawProjectBuilder | ||
|
||
class TestNGExportedTestPackageTestFactory implements JavaCodeFactory { | ||
boolean mocks; | ||
|
||
static def exportedTestPackageTest() { | ||
def factory = new TestNGExportedTestPackageTestFactory() | ||
factory.mocks = false | ||
return factory | ||
} | ||
|
||
static def exportedTestPackageTestWithMocks() { | ||
def factory = new TestNGExportedTestPackageTestFactory() | ||
factory.mocks = true | ||
return factory | ||
} | ||
|
||
@Override | ||
String getFilename(JigsawProjectBuilder builder) { | ||
return builder.getPackageName().replace(".", "/") + "/test/AClassTest.java" | ||
} | ||
|
||
@Override | ||
String generateCode(JigsawProjectBuilder builder) { | ||
def mockitoImport = "" | ||
def mockitoUsage = "" | ||
if (mocks) { | ||
mockitoImport = "import static org.mockito.Mockito.mock;" | ||
mockitoUsage = "Object obj = mock(Object.class);" | ||
} | ||
return """ | ||
package ${builder.getPackageName()}.test; | ||
import ${builder.getPackageName()}.AClass; | ||
${mockitoImport} | ||
import org.testng.annotations.Test; | ||
import static org.testng.Assert.assertTrue; | ||
public class AClassTest { | ||
@Test | ||
public void isAnInstanceOfAClass() { | ||
${mockitoUsage} | ||
assertTrue(new AImplementation() instanceof AClass); | ||
} | ||
static class AImplementation extends AClass { | ||
@Override | ||
public void aMethod(String aString) { | ||
// Do nothing | ||
} | ||
} | ||
} | ||
""" | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/test/groovy/com/zyxist/chainsaw/builder/factory/TestNGSampleTestFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2017 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 com.zyxist.chainsaw.builder.factory | ||
|
||
import com.zyxist.chainsaw.builder.JavaCodeFactory | ||
import com.zyxist.chainsaw.builder.JigsawProjectBuilder | ||
|
||
class TestNGSampleTestFactory implements JavaCodeFactory { | ||
boolean mocks; | ||
|
||
static def testngTest() { | ||
def factory = new TestNGSampleTestFactory() | ||
factory.mocks = false | ||
return factory | ||
} | ||
|
||
static def testngTestWithMocks() { | ||
def factory = new TestNGSampleTestFactory() | ||
factory.mocks = true | ||
return factory | ||
} | ||
|
||
@Override | ||
String getFilename(JigsawProjectBuilder builder) { | ||
return builder.getPackageName().replace(".", "/") + "/AClassTest.java" | ||
} | ||
|
||
@Override | ||
String generateCode(JigsawProjectBuilder builder) { | ||
def mockitoImport = "" | ||
def mockitoUsage = "" | ||
if (mocks) { | ||
mockitoImport = "import static org.mockito.Mockito.mock;" | ||
mockitoUsage = "Object obj = mock(Object.class);" | ||
} | ||
return """ | ||
package ${builder.getPackageName()}; | ||
${mockitoImport} | ||
import org.testng.annotations.Test; | ||
import static org.testng.Assert.assertTrue; | ||
public class AClassTest { | ||
@Test | ||
public void isAnInstanceOfAClass() { | ||
${mockitoUsage} | ||
assertTrue(new AImplementation() instanceof AClass); | ||
} | ||
static class AImplementation extends AClass { | ||
@Override | ||
public void aMethod(String aString) { | ||
// Do nothing | ||
} | ||
} | ||
} | ||
""" | ||
} | ||
} |
Oops, something went wrong.