Package org.hibernate.validator.test.internal.constraintvalidators.bv.past

Source Code of org.hibernate.validator.test.internal.constraintvalidators.bv.past.PastValidatorForDateTest

/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.test.internal.constraintvalidators.bv.past;

import java.util.Date;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import org.hibernate.validator.internal.constraintvalidators.bv.past.PastValidatorForDate;

public class PastValidatorForDateTest {

  private static PastValidatorForDate constraint;

  @BeforeClass
  public static void init() {
    constraint = new PastValidatorForDate();
  }

  @Test
  public void testIsValid() {
    Date futureDate = getFutureDate();
    Date pastDate = getPastDate();
    assertTrue( constraint.isValid( null, null ) );
    assertTrue( constraint.isValid( pastDate, null ) );
    assertFalse( constraint.isValid( futureDate, null ) );
  }

  private Date getFutureDate() {
    Date date = new Date();
    long timeStamp = date.getTime();
    date.setTime( timeStamp + 31557600000L );
    return date;
  }

  private Date getPastDate() {
    Date date = new Date();
    long timeStamp = date.getTime();
    date.setTime( timeStamp - 31557600000L );
    return date;
  }

}
TOP

Related Classes of org.hibernate.validator.test.internal.constraintvalidators.bv.past.PastValidatorForDateTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.