1 19 20 package org.netbeans.modules.junit; 21 22 import java.io.IOException ; 23 import java.util.Collections ; 24 import java.util.EnumSet ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import javax.lang.model.element.ExecutableElement; 29 import javax.lang.model.element.Modifier; 30 import javax.lang.model.element.TypeElement; 31 import org.netbeans.api.java.source.CompilationInfo; 32 import org.netbeans.api.java.source.ElementHandle; 33 import org.netbeans.api.java.source.JavaSource; 34 import org.netbeans.api.java.source.ModificationResult; 35 import org.netbeans.modules.junit.plugin.JUnitPlugin.CreateTestParam; 36 37 41 public final class TestCreator implements TestabilityJudge { 42 43 48 static final Set <Modifier> ACCESS_MODIFIERS 49 = EnumSet.of(Modifier.PUBLIC, 50 Modifier.PROTECTED, 51 Modifier.PRIVATE); 52 53 54 private final TestGeneratorSetup setup; 55 56 57 TestCreator(boolean loadDefaults) { 58 setup = new TestGeneratorSetup(loadDefaults); 59 } 60 61 62 TestCreator(Map <CreateTestParam, Object > params) { 63 setup = new TestGeneratorSetup(params); 64 } 65 66 68 public void createEmptyTest(final JavaSource tstSource) throws IOException { 69 AbstractTestGenerator testGenerator 70 = new JUnit3TestGenerator(setup); 71 ModificationResult result = tstSource.runModificationTask(testGenerator); 72 result.commit(); 73 } 74 75 79 public void createSimpleTest(ElementHandle<TypeElement> topClassToTest, 80 JavaSource tstSource, 81 boolean isNewTestClass) throws IOException { 82 AbstractTestGenerator testGenerator 83 = new JUnit3TestGenerator(setup, 84 Collections.singletonList(topClassToTest), 85 null, 86 isNewTestClass); 87 ModificationResult result = tstSource.runModificationTask(testGenerator); 88 result.commit(); 89 } 90 91 93 public List <String > createTestSuite(List <String > suiteMembers, 94 JavaSource tstSource, 95 boolean isNewTestClass) throws IOException { 96 AbstractTestGenerator testGenerator 97 = new JUnit3TestGenerator(setup, 98 null, 99 suiteMembers, 100 isNewTestClass); 101 ModificationResult result = tstSource.runModificationTask(testGenerator); 102 result.commit(); 103 104 return testGenerator.getProcessedClassNames(); 105 } 106 107 public TestabilityResult isClassTestable(CompilationInfo compInfo, 108 TypeElement classElem) { 109 return setup.isClassTestable(compInfo, classElem); 110 } 111 112 public boolean isMethodTestable(ExecutableElement method) { 113 return setup.isMethodTestable(method); 114 } 115 116 } 117 | Popular Tags |