Search in sources :

Example 1 with MethodNamePredicate

use of abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate in project abstools by abstools.

the class ABSUnitTestCaseTranslator method createTestSuiteForClassMethod.

/**
 * Create a test suite for testing a method.
 *
 * @param testCases
 * @param testInterface
 * @param className
 * @param methodName
 */
private void createTestSuiteForClassMethod(List<TestCase> testCases, InterfaceDecl testInterface, String className, String methodName) {
    // create test class ([Suite])
    final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
    module.addDecl(testClass);
    // find class under test.
    ClassDecl classUnderTest = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(className));
    assert classUnderTest != null : "It should not be possible to not " + "find class under test";
    // find method under test.
    MethodImpl methodUnderTest = findMethodImpl(classUnderTest, new MethodNamePredicate(methodName));
    assert methodUnderTest != null : "It should not be possible to not " + "find method under test";
    // find interface of class under test.
    InterfaceDecl interfaceOfClassUnderTest = findInterfaceUnderTest(methodName, classUnderTest);
    if (interfaceOfClassUnderTest == null) {
    // this method is not exposed by any interface!
    }
    // return type
    MethodSig signature = methodUnderTest.getMethodSig();
    final Access access = signature.getReturnType();
    // add imports of class/interface under test
    importModules.add(classUnderTest.getModuleDecl().getName());
    importModules.add(interfaceOfClassUnderTest.getModuleDecl().getName());
    /*
		 * Test methods and Test cases are ordered that is,
		 * test case 1 is implemented by test method 1 and so on...
		 */
    for (int i = 0; i < testCases.size(); i++) {
        console("Generating test case " + i + "...");
        TestCase testCase = testCases.get(i);
        MethodImpl method = testClass.getMethod(i);
        methodBuilder.buildTestCase(testCase, testClass, method, access, methodName);
    }
}
Also used : MethodSig(abs.frontend.ast.MethodSig) AbsASTBuilderUtil.findMethodSig(abs.backend.tests.AbsASTBuilderUtil.findMethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) MethodNamePredicate(abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

MethodNamePredicate (abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 AbsASTBuilderUtil.findMethodSig (abs.backend.tests.AbsASTBuilderUtil.findMethodSig)1 Access (abs.frontend.ast.Access)1 ClassDecl (abs.frontend.ast.ClassDecl)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MethodImpl (abs.frontend.ast.MethodImpl)1 MethodSig (abs.frontend.ast.MethodSig)1 TestCase (apet.testCases.TestCase)1