CenturyLinkCloud / mdw

https://centurylinkcloud.github.io/mdw/
MIT License
46 stars 10 forks source link

Unit testing using MockRuntimeContext is broken #846

Closed jbrojdeCTL closed 4 years ago

jbrojdeCTL commented 4 years ago

In BaseActivity.java, "prepare" method used for unit testing is referencing private variable "_runtimeContext" which is null/not initialized in the context of running unit tests.

This code:

public void prepare(ActivityRuntimeContext runtimeContext) {
        if (!(logger instanceof ActivityLogger))
            logger = new ActivityLogger(_runtimeContext);

Needs to be changed to this:

public void prepare(ActivityRuntimeContext runtimeContext) {
        if (!(logger instanceof ActivityLogger))
            logger = new ActivityLogger(runtimeContext);

Also, in ActivityLogger.java, the constructor needs to change from this:

public ActivityLogger(ActivityRuntimeContext runtimeContext) {
        this.runtimeContext = runtimeContext;
        if (runtimeContext.getPerformanceLevel() < 9)
            this.runtimeContext.setLogPersister(ActivityLogger::persist);
    }

To this:

public ActivityLogger(ActivityRuntimeContext runtimeContext) {
        this.runtimeContext = runtimeContext;
        if (runtimeContext.getPerformanceLevel() < 9 && !(runtimeContext instanceof MockRuntimeContext))
            this.runtimeContext.setLogPersister(ActivityLogger::persist);
    }