View Javadoc

1   package se.citerus.dddsample.application.util;
2   
3   import java.text.ParseException;
4   import java.text.SimpleDateFormat;
5   import java.util.Date;
6   
7   /**
8    * A few utils for working with Date in tests.
9    *
10   */
11  public final class DateTestUtil {
12  
13    /**
14     * @param date date string as yyyy-MM-dd
15     * @return Date representation
16     */
17    public static Date toDate(final String date) {
18      return toDate(date, "00:00.00.000");
19    }
20  
21    /**
22     * @param date date string as yyyy-MM-dd
23     * @param time time string as HH:mm
24     * @return Date representation
25     */
26    public static Date toDate(final String date, final String time) {
27      try {
28        return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date + " " + time);
29      } catch (ParseException e) {
30        throw new RuntimeException(e);
31      }
32    }
33  
34    /**
35     * Prevent instantiation.
36     */
37    private DateTestUtil() {
38    }
39  }