Search in sources :

Example 1 with JUnitTestShortener

use of de.dagere.peass.testtransformation.JUnitTestShortener in project peass by DaGeRe.

the class TestShortening method testShorteningJUnit5Parameterized_methodItself.

@Test
public void testShorteningJUnit5Parameterized_methodItself() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTestJUnit5Parameterized.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.ExampleTestJUnit5Parameterized", ""), "testMe")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
        try (FileInputStream inputStream = new FileInputStream(testClazz)) {
            String fileContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            System.out.println(fileContent);
            int matches = StringUtils.countMatches(fileContent, "@Test");
            Assert.assertEquals(0, matches);
            int matchesParameterized = StringUtils.countMatches(fileContent, "@ParameterizedTest");
            Assert.assertEquals(1, matchesParameterized);
        }
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) FileInputStream(java.io.FileInputStream) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Example 2 with JUnitTestShortener

use of de.dagere.peass.testtransformation.JUnitTestShortener in project peass by DaGeRe.

the class TestShortening method testSubclassShortening.

@Test
public void testSubclassShortening() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTest.java");
    final File subClazz = new File(test, "SubTest.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.SubTest", ""), "test3")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile, testClazz));
        Assert.assertFalse(FileUtils.contentEquals(subTestFile, subClazz));
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile, testClazz));
    Assert.assertTrue(FileUtils.contentEquals(subTestFile, subClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Example 3 with JUnitTestShortener

use of de.dagere.peass.testtransformation.JUnitTestShortener in project peass by DaGeRe.

the class TestShortening method testShorteningJUnit5Parameterized.

@Test
public void testShorteningJUnit5Parameterized() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTestJUnit5Parameterized.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.ExampleTestJUnit5Parameterized", ""), "checkSomething")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
        try (FileInputStream inputStream = new FileInputStream(testClazz)) {
            String fileContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            System.out.println(fileContent);
            int matches = StringUtils.countMatches(fileContent, "@Test");
            Assert.assertEquals(1, matches);
            int matchesParameterized = StringUtils.countMatches(fileContent, "@ParameterizedTest");
            Assert.assertEquals(0, matchesParameterized);
        }
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile5Parameterized, testClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) FileInputStream(java.io.FileInputStream) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Example 4 with JUnitTestShortener

use of de.dagere.peass.testtransformation.JUnitTestShortener in project peass by DaGeRe.

the class KoPeMeExecutor method runMethod.

protected void runMethod(final File logFolder, final TestCase test, final File moduleFolder, final long timeout) {
    try (final JUnitTestShortener shortener = new JUnitTestShortener(testTransformer, moduleFolder, test.toEntity(), test.getMethod())) {
        LOG.info("Cleaning...");
        final File cleanFile = getCleanLogFile(logFolder, test);
        clean(cleanFile);
        final File methodLogFile = getMethodLogFile(logFolder, test);
        runTest(moduleFolder, methodLogFile, test, test.getClazz(), timeout);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : File(java.io.File) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener)

Example 5 with JUnitTestShortener

use of de.dagere.peass.testtransformation.JUnitTestShortener in project peass by DaGeRe.

the class TestShortening method testShorteningJUnit5.

@Test
public void testShorteningJUnit5() throws Exception {
    final File test = new File(folder, "src/test/java/de");
    test.mkdirs();
    final File testClazz = new File(test, "ExampleTestJUnit5.java");
    try (JUnitTestShortener shortener = new JUnitTestShortener(transformer, folder, new ChangedEntity("de.ExampleTestJUnit5", ""), "checkSomething")) {
        Assert.assertFalse(FileUtils.contentEquals(exampleTestFile5, testClazz));
        try (FileInputStream inputStream = new FileInputStream(testClazz)) {
            String fileContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            int matches = StringUtils.countMatches(fileContent, "@Test");
            Assert.assertEquals(1, matches);
        }
    }
    Assert.assertTrue(FileUtils.contentEquals(exampleTestFile5, testClazz));
}
Also used : ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) FileInputStream(java.io.FileInputStream) JUnitTestShortener(de.dagere.peass.testtransformation.JUnitTestShortener) Test(org.junit.jupiter.api.Test)

Aggregations

JUnitTestShortener (de.dagere.peass.testtransformation.JUnitTestShortener)6 File (java.io.File)6 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)5 Test (org.junit.jupiter.api.Test)5 FileInputStream (java.io.FileInputStream)3