如何使用Mockito填充POJO

我有一个POJO课:

@Data @Document
public class RoomPreferences{
    private TypeEnum         roomType;
    private BigDecimal       minLen;
    private BigDecimal       maxLen;
    private List<BigDecimal> defaultPrices;
}

I want to populate a RoomPreferences object at test and I am using Mockito, but my RoomPreferences object's fields are always null.

public class TestingClass {
   @Mock private RoomPreferences roomPreferences;
   @InjectMocks public RoomServiceImpl roomService;

   @Before
   public void init() {
       MockitoAnnotations.initMocks(this);
   }

   @Test
   public void test() {
       when(roomPreferences.getMinLen()).thenReturn(BigDecimal.valueOf(10));
       ...
   }
}
评论