Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
@NotBlank(message = "timesheet.cadastro.horainicio.obrigatorio")
@Temporal(TemporalType.TIME)
@Column(name = "INICIO", nullable = false)
private Date horaInicio;
And, in my test (groovy) I put null to "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())
but I have error:
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.
Anybody can help me ?
thanks
As also said in documentation, @NotBlank is for String type. There is no concept of java.util.Date being blank. It can be null or not null.
Validate that the annotated string is not null or empty. The
difference to NotEmpty is that trailing whitespaces are getting
ignored.
If goal is to check is value not null, @NotNull should be used. According documentation:
The annotated element must not be null. Accepts any type.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.