Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
TestUtilities.java
Go to the documentation of this file.
1 package com.fermod.util;
2 
3 import static org.junit.Assume.assumeNoException;
4 import static org.junit.Assume.assumeNotNull;
5 
6 import java.time.LocalDate;
7 import java.time.ZoneId;
8 import java.util.Date;
9 
10 import org.junit.jupiter.api.TestInfo;
11 
12 public final class TestUtilities {
13 
14  private TestUtilities() {}
15 
25  public static Date parseToDate(LocalDate localDate) {
26  Date date = null;
27  try {
28  date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
29  } catch (Exception e) {
30  assumeNoException("Exception thrown when trying to parse date.", e);
31  }
32  assumeNotNull(date);
33  return date;
34  }
35 
43  public static String getFailMessage(Exception e, TestInfo testInfo) {
44  StringBuilder sb = new StringBuilder();
45  sb.append("Unexpected exception thrown");
46  if(testInfo.getTestMethod().isPresent()) {
47  sb.append(" in " + testInfo.getTestMethod().get().getName());
48  }
49  sb.append("\n\tCase: " + testInfo.getDisplayName());
50  return sb.toString();
51  }
52 
53 }
static Date parseToDate(LocalDate localDate)
Parse java.util.Date to java.time.LocalDate.
static String getFailMessage(Exception e, TestInfo testInfo)
Returns a formated error message with the exception information.