All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.peachapisecurity.tg.junit4.PeachInvokeMethod Maven / Gradle / Ivy

The newest version!

/*
 * Copyright 2017 Peach Tech
 * 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.peachapisecurity.tg.junit4;

import com.peachapisecurity.api.PeachState;
import com.peachapisecurity.api.PeachApiException;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

public class PeachInvokeMethod extends Statement {
    private final FrameworkMethod testMethod;
    private final Object target;
    private final PeachContext context;
    private final String name;

    public PeachInvokeMethod(PeachContext context, String name, FrameworkMethod testMethod, Object target) {
        this.testMethod = testMethod;
        this.target = target;
        this.context = context;
        this.name = name;
    }

    @Override
    public void evaluate() throws Throwable
    {
        try
        {
            context.proxy.testCase(name);
            context.state = PeachState.Unknown;
            
            try
            {
                testMethod.invokeExplosively(target);
            }
            catch(Exception ex)
            {
                // Ignore any test exceptions
            }
            
            context.state = context.proxy.testTeardown();
        }
        catch(PeachApiException ex)
        {
            if(context.debug)
                System.out.println(String.format("PeachInvokeMethod.evaluate: Error: %s", ex.toString()));
            
            context.state = PeachState.Error;
            context.ex = ex;
            
            throw ex;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy