BAEL-5905 move article
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.spoon;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import spoon.Launcher;
|
||||
import spoon.SpoonAPI;
|
||||
|
||||
public class AddCopyrightProcessorUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenAddCopyright_thenSuccess() {
|
||||
|
||||
SpoonAPI spoon = new Launcher();
|
||||
spoon.addProcessor(new AddCopyrightProcessor());
|
||||
spoon.addInputResource("src/test/resources/spoon/SpoonClassToTest.java");
|
||||
spoon.setSourceOutputDirectory("./target/spoon-processed");
|
||||
spoon.buildModel();
|
||||
spoon.process();
|
||||
spoon.prettyprint();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.spoon;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AddCopyrightTransformerUnitTest {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenAddCopyright_thenSuccess() {
|
||||
|
||||
AddCopyrightTransformer transformer = new AddCopyrightTransformer();
|
||||
transformer.addCopyright("src/test/resources/spoon/SpoonClassToTest.java");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.spoon;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.spoon.ClassReporter.MethodSummary;
|
||||
|
||||
public class ClassReporterUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenBrokenClass_whenGenerateReport_thenSuccess() {
|
||||
ClassReporter reporter = new ClassReporter();
|
||||
MethodSummary report = reporter.generateMethodSummaryReport("src/test/resources/spoon/BrokenClass.java");
|
||||
|
||||
assertThat(report).isNotNull();
|
||||
assertThat(report.getPrivateMethodCount()).isEqualTo(0);
|
||||
assertThat(report.getPublicMethodCount()).isEqualTo(1);
|
||||
assertThat(report.getProtectedMethodCount()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGenerateReport_thenSuccess() {
|
||||
|
||||
ClassReporter reporter = new ClassReporter();
|
||||
MethodSummary report = reporter.generateMethodSummaryReport("src/test/resources/spoon/SpoonClassToTest.java");
|
||||
assertThat(report).isNotNull();
|
||||
assertThat(report.getPackagePrivateMethodCount()).isEqualTo(1);
|
||||
assertThat(report.getPublicMethodCount()).isEqualTo(1);
|
||||
assertThat(report.getPrivateMethodCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package spoon;
|
||||
public class BrokenClass {
|
||||
|
||||
// Syntax error
|
||||
pluvic void brokenMethod() {}
|
||||
|
||||
// Syntax error
|
||||
protected void protectedMethod() thraws Exception {}
|
||||
|
||||
// Public method
|
||||
public void publicMethod() {}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package spoon;
|
||||
|
||||
import some.superduper.HelperClass;
|
||||
import some.superduper.SomeVO;
|
||||
|
||||
public class SpoonClassToTest {
|
||||
|
||||
private static HelperClass helper;
|
||||
|
||||
public SpoonClassToTest() {}
|
||||
|
||||
public int publicMethod() {}
|
||||
|
||||
private int internalStuff() {}
|
||||
|
||||
protected SomeVO protectedMethod() {
|
||||
return new SomeVO();
|
||||
}
|
||||
|
||||
void packageProtectedMethod() {
|
||||
|
||||
try {
|
||||
HelperClass.callSomeMethodThatThrows();
|
||||
}
|
||||
catch(Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user