Skip to content

Commit

Permalink
Updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ssathiah committed Apr 22, 2024
1 parent 517ce25 commit 4527b4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public static Timestamp getCurrentTimeStamp() {
public static Instant getInstantNow() {
return Instant.now();
}
@SuppressWarnings("java:S2696")
@Value("${app.timezone}")
public void setEnvTimeZone(String envTimeZone){
timeZone=envTimeZone;
}
public String getEnvTimeZone(){
return timeZone;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gov.cdc.dataingestion.share.helper;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -10,36 +12,15 @@

class TimeStampHelperTest {

@Test
void testGetCurrentTimeStampWithEnvTimeZone() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//TimeStampHelper
@ParameterizedTest
@ValueSource(strings = {"UTC", ""})
@NullSource
void testGetCurrentTimeStampWithEnvTimeZone(String timeStamp) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Constructor<TimeStampHelper> pcc = TimeStampHelper.class.getDeclaredConstructor();
pcc.setAccessible(true);
TimeStampHelper privateConstructorInstance = pcc.newInstance();
privateConstructorInstance.setEnvTimeZone("UTC");
assertEquals("UTC", privateConstructorInstance.getEnvTimeZone());
assertNotNull(TimeStampHelper.getCurrentTimeStamp());
}

@Test
void testGetCurrentTimeStampWithEmptyEnvTimeZone() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//TimeStampHelper
Constructor<TimeStampHelper> pcc = TimeStampHelper.class.getDeclaredConstructor();
pcc.setAccessible(true);
TimeStampHelper privateConstructorInstance = pcc.newInstance();
privateConstructorInstance.setEnvTimeZone("");
assertEquals("", privateConstructorInstance.getEnvTimeZone());
assertNotNull(TimeStampHelper.getCurrentTimeStamp());
}

@Test
void testGetCurrentTimeStampWithNullEnvTimeZone() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//TimeStampHelper
Constructor<TimeStampHelper> pcc = TimeStampHelper.class.getDeclaredConstructor();
pcc.setAccessible(true);
TimeStampHelper privateConstructorInstance = pcc.newInstance();
privateConstructorInstance.setEnvTimeZone(null);
assertEquals(null, privateConstructorInstance.getEnvTimeZone());
privateConstructorInstance.setEnvTimeZone(timeStamp);
assertEquals(timeStamp, privateConstructorInstance.getEnvTimeZone());
assertNotNull(TimeStampHelper.getCurrentTimeStamp());
}
}

0 comments on commit 4527b4f

Please sign in to comment.