Skip to content

Commit

Permalink
Fix failing unit tests when run locally
Browse files Browse the repository at this point in the history
  • Loading branch information
mwodahl committed Dec 4, 2024
1 parent 489b3a3 commit 0cce739
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.trihydro.library.helpers;

import static java.lang.Math.toIntExact;

import java.io.IOException;
import static java.lang.Math.toIntExact;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
Expand All @@ -14,13 +13,14 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.TimeZone;

import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.trihydro.library.model.Coordinate;
import com.trihydro.library.model.Milepost;

import org.springframework.stereotype.Component;

@Component
public class Utility {
private DateFormat utcFormatMilliSec = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Expand All @@ -35,14 +35,22 @@ public Date convertDate(String incomingDate) {
Date convertedDate = null;
try {
if (incomingDate != null) {
if (incomingDate.contains("UTC"))
if (incomingDate.contains("UTC")) {
utcTextFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
convertedDate = utcTextFormat.parse(incomingDate);
else if (incomingDate.contains("."))
}
else if (incomingDate.contains(".")) {
utcFormatMilliSec.setTimeZone(TimeZone.getTimeZone("UTC"));
convertedDate = utcFormatMilliSec.parse(incomingDate);
else if (incomingDate.length() == 17)
}
else if (incomingDate.length() == 17) {
utcFormatMin.setTimeZone(TimeZone.getTimeZone("UTC"));
convertedDate = utcFormatMin.parse(incomingDate);
else
}
else {
utcFormatSec.setTimeZone(TimeZone.getTimeZone("UTC"));
convertedDate = utcFormatSec.parse(incomingDate);
}
}
} catch (ParseException e1) {
e1.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.trihydro.library.helpers;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
Expand All @@ -15,6 +16,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;

import com.google.gson.Gson;
import com.trihydro.library.model.ActiveTim;
Expand Down Expand Up @@ -42,6 +44,8 @@
import com.trihydro.library.service.SdwService;
import com.trihydro.library.service.TimGenerationProps;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -91,6 +95,16 @@ public class TimGenerationHelperTest {
@Captor
private ArgumentCaptor<WydotTravelerInputData> timCaptor;

@Before
public void setup() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}

@After
public void teardown() {
TimeZone.setDefault(TimeZone.getTimeZone(java.time.ZoneId.systemDefault()));
}

@Test
public void resubmitToOde_EmptyList() {
// Arrange
Expand Down Expand Up @@ -587,6 +601,7 @@ public void resubmitToOde_usesOldStartTime() {
tum.setRoute("I 80");
tum.setSatRecordId("satRecordId");
tum.setStartDateTime("");
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

// Given a TIM with a durationTime of an hour
var originalStartTime = Instant.parse("2021-01-01T00:00:00.000Z");
Expand All @@ -596,7 +611,7 @@ public void resubmitToOde_usesOldStartTime() {

doReturn(new String[] { "1234" }).when(mockDataFrameService).getItisCodesForDataFrameId(any());
doReturn("").when(mockOdeService).updateTimOnSdw(any());
doReturn(60).when(mockUtility).getMinutesDurationBetweenTwoDates("2021-01-01T00:00:00.000Z", "2021-01-01T01:00:00.000Z");
doReturn(60).when(mockUtility).getMinutesDurationBetweenTwoDates(anyString(), anyString());

doReturn(new Coordinate(BigDecimal.valueOf(1), BigDecimal.valueOf(2))).when(mockUtility).calculateAnchorCoordinate(any(), any());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public void getMinutesDurationBetweenTwoDates_SUCCESS_YyMmDdDate() {
@Test
public void getMinutesDurationBetweenTwoDates_SUCCESS_different_formats() {
// Arrange
String startDateTime = "2024-03-22T07:36:15.711Z";
String endDateTime = "2024-03-22 07:41:00";
String startDateTime = "2024-03-22T07:36:15.711Z[UTC]";
String endDateTime = "2024-03-22T07:41:00.000Z";

// Act
var duration = uut.getMinutesDurationBetweenTwoDates(startDateTime, endDateTime);
Expand Down

0 comments on commit 0cce739

Please sign in to comment.