samedi 23 mai 2020

How to use Mockito to populate POJO

I have a POJO class:

@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));
       ...
   }
}

Aucun commentaire:

Enregistrer un commentaire