PowerMockito抑制sqlj.runtime.ref.DefaultContext ConnectionContextImpl getExecutionContext方法

时间:2019-02-15 02:45:04

标签: java unit-testing mocking powermockito suppress

在进行单元测试时,我很难抑制方法调用。请看看我尝试过的内容。

测试类。

@RunWith(PowerMockRunner.class)
@PrepareForTest({SyncLog.class, ConnectionContext.class, ConnectionContextImpl.class, ExecutionContext.class, DefaultContext.class, LoggingConfigurator.class, DbProperties.class, StackoverFlow.class, EventBase.class, SQLJConnectionBase.class, RuntimeRefErrors.class})
public class StackoverFlowTest {

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(LoggingConfigurator.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(DbProperties.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(SQLJConnectionBase.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(EventBase.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(RuntimeRefErrors.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(ExecutionContext.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(DefaultContext.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(ConnectionContextImpl.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(ConnectionContext.class));
        PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(SyncLog.class));
        PowerMockito.suppress(PowerMockito.method(DefaultContext.class, "getExecutionContext"));
        PowerMockito.suppress(PowerMockito.method(ConnectionContextImpl.class, "getExecutionContext"));
        PowerMockito.suppress(PowerMockito.method(ConnectionContext.class, "getExecutionContext"));

        StackoverFlow spyTmp = spy(StackoverFlow.class);
        spyTmp.loadData("stackoverFlow.txt", false);
    }
}

好的,在那个loadData方法中,进行了以下方法调用(getExecutionContext()),我想通过抑制它来绕过它。

sqlj.runtime.ref.DefaultContext __sJT_cc = Ctx;
if (__sJT_cc == null)
    sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();

Object tmp2 = sqlj.runtime.ExecutionContext.raiseNullExecCtx();
ExecutionContext tmp1 = __sJT_cc.getExecutionContext();
Object tmp3 = __sJT_cc.getExecutionContext().getOracleContext();

我已经尽一切努力阻止__sJT_cc.getExecutionContext()语句的运行而没有任何运气。有人知道我在做什么错吗?该方法不断执行。

0 个答案:

没有答案