如何在Java中模拟使用Map Struct的类?

时间:2017-06-15 18:26:12

标签: java mockito powermock mapstruct

使用MAPSTRUCT的Java类我们在接口内部有静态变量INSTANCE,这个接口实现是在运行时创建的。那么,如何在Java中模拟使用Map Struct的类?

    @Mapper 1
    public interface CarMapper {

        CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); 3

        @Mapping(source = "numberOfSeats", target = "seatCount")
        CarDto carToCarDto(Car car); 2
    }


    public class A
    {
        public CarDto getCardto()
        {
            CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
            return carDto;
        }

    }

如何为A类创建模拟?

1 个答案:

答案 0 :(得分:0)

如果您想模拟课程A,那么您可以Mockito.mock(A.class)