Nelson Gomes
Nelson Gomes

Reputation: 1

Mock RequestContext to run a test

I have a class that uses Active Web - HttpSupport View - in a service class. I know that is wrong but I cannot change right now.

So, when I am running a test I receive a null pointer at this point:

enter image description here

Because request context.getValues() is null.

How I solve it? Is it possible to mock or anything?

Problems: RequestContext -> private constructor I am extending AppController -> HttpSupport

My env uses a @Guice(modules = TestModule.class) strategy to bind classes in test context.

Upvotes: 0

Views: 522

Answers (1)

ipolevoy
ipolevoy

Reputation: 5518

The class RequestContext is internal to the framework and is not designed to be mocked. Is simply carries a number of objects on a local thread for easy access by other framework classes. This page explains how to write various tests in ActiveWeb: https://javalite.io/testing

This page explains how to mock services that controllers use: https://javalite.io/dependency_injection

If you add more context to your question, that is: what exactly do you need, I will be in a better position to advice further

Additionally, the RequestContext.getValues() method is not public. Not even sure how you can compile this.

Upvotes: 0

Related Questions