I'm testing method and have a problem that my entity has a field that is null, but i need it not to be empty. I have this:
class MyClass { void myMethod() { Entity entity = new Entity(); String str = entity.getField(); // It's null now if (str == null) { //always true //do something } } } Now in test i need my field not to be null.
I tried to do the following in test:
Entity entity = mock(Entity.class); when(entity.getField()).thenReturn("text"); But it seems, that it doesn't work. The problem is that I can't use PowerMock or refactor original class.
Is there any way I can return text or set field before if statement?
Entityinstance?ifstatement, which means, thatstris stillnull.