How to taunt a private inner class

I have a spring application and I want to create a unitary test on a controller like this. The problem is that the Wrapper class is a private inner class, so Wrapper is not understood in the test. Is it possible to mock him with Mockito without changing the controller class. I can use prepareData () to get an instance of an object, but I don't know if this can be used to mock this object.

thank

@Controller
public class Controller {

    private class Wrapper {
        private Object1 field1;
        private Object2 field2;
        private Object1 method1(){
           ...
        }
        private Object2 method1(){
           ...
        }
    }

    @ModelAttribute("data")
    public Wrapper prepareData() {
            return new Wrapper ();
}

    public String save(@ModelAttribute("data") Wrapper wrapper, BindingResult result, Model model){
        ...
    }
}

So in my test, I would have something like this

@Test
public void usernameEmpty(){

    BindingResult result = Mockito.mock(BindingResult.class);
    Model model = Mockito.mock(Model.class);
    Wrapper data = //how to mock it
    when(data.method1()).then(new Foo1());
    when(data.method2()).then(new Foo2());
    String returned = controller.save(data, result, model);
    ....
}
+5
source share
1 answer

, . , . -, . , , , .

, : ... ( ), - ? . Test Driven Development , . , , .

. !

+8

All Articles