want to mock the DynamoHttpServletRequest to pass the test attributes in junit /mockito

79 Views Asked by At

I want to configure attributes inside the mock dynamo http servlet request which can be used by the function under test to get those attributes and perform function accordingly. how can I achieve this?

1

There are 1 best solutions below

0
pantuptus On

I am afraid the only way to do that is to override DynamoHttpServletRequest within test package:

static class MockDynamoRequest extends DynamoHttpServletRequest {

    private Map<String, Object> params = new HashMap<>();

    @Override
    public void setParameter(String pName, Object pValue) {
        params.put(pName, pValue);
    }

    public Map<String, Object> getParams() {
        return params;
    }

    @Override
    public String[] getParameterValues(String pName) {
        return (String[]) params.get(pName);
    }
}