BitstampUtils { public static Date parseDate(String dateString) { try { if (dateString == null) { return null; } final Instant instant = LocalDateTime.parse(dateString, BITSTAMP_DATE_TIME_PATTERN) .atZone(BITSTAMP_DATE_TIME_ZONE_ID) .toInstant(); return Date.from(instant); } catch (DateTimeParseException e) { throw new ExchangeException("Illegal date/time format", e); } } private  BitstampUtils(); static Date parseDate(String dateString); static final int MAX_TRANSACTIONS_PER_QUERY; }
@Test public void testParseDateWithMillis() { final String strDateFromBitstamp = "2020-09-01 05:55:04.399000"; final long epochMillis = 1598939704399L; final Date convertedDate = BitstampUtils.parseDate(strDateFromBitstamp); assertThat(convertedDate).isNotNull(); assertThat(convertedDate.getTime()).isEqualTo(epochMillis); }
@Test public void testParseDateWithoutMillis() { final String strDateFromBitstamp = "2020-09-01 05:55:04"; final long epochMillis = 1598939704000L; final Date convertedDate = BitstampUtils.parseDate(strDateFromBitstamp); assertThat(convertedDate).isNotNull(); assertThat(convertedDate.getTime()).isEqualTo(epochMillis); }
@Test public void testParseDateWithInvalidFormat() { final String strDateWithInvalidFormat = "2020-09-01T05:55:04.399000"; assertThatThrownBy(() -> BitstampUtils.parseDate(strDateWithInvalidFormat)) .isInstanceOf(ExchangeException.class) .hasMessage("Illegal date/time format"); }
@Test public void testParseDateNull() { final Date convertedDate = BitstampUtils.parseDate(null); assertThat(convertedDate).isNull(); }