我的朋友,
我和...上课
@NotBlank(message = "timesheet.cadastro.horainicio.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "INICIO", nullable = false)
private Date horaInicio;
而且,在我的测试(groovy)中,我将 null 放入 "horaInicio" :
def "Salvar um timesheet sem hora inicio"() {
given:"um timesheet sem data"
def usuario = sessionFactory.getCurrentSession().get(Usuario.class,1L) as Usuario
def dias = sessionFactory.getCurrentSession().get(Dias.class,1L) as Dias
def timeSheet = criarTimeSheet(usuario,dias) as TimeSheet
timeSheet.horaInicio = null
when:"buscar na base"
def timeSheetPersistido = timeSheetService.salvar(timeSheet)
then:"retorna uma lista de timesheet"
def erro = thrown(ConstraintViolationException)
"timesheet.cadastro.horainicio.obrigatorio".equals(erro.getConstraintViolations().asList().get(0).getMessage())
}
但我有错误:
Expected exception javax.validation.ConstraintViolationException, but got javax.validation.UnexpectedTypeException
at org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:79)
at br.com.infowhere.service.TimeSheetServiceIt.Salvar um timesheet sem hora inicio(TimeSheetServiceIt.groovy:80)
Caused by: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.util.Date.
任何人都可以帮助我吗?
谢谢