Skip to content

Commit 11c6a61

Browse files
committed
Hotfix 2.7.1: Add test for Date created with timestamp
1 parent a1180a5 commit 11c6a61

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

yoti-sdk-impl/src/test/java/com/yoti/api/client/shareurl/extension/SimpleThirdPartyAttributeExtensionBuilderTest.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.yoti.api.client.shareurl.extension;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.yoti.api.client.AttributeDefinition;
5-
import com.yoti.api.client.spi.remote.call.YotiConstants;
6-
import org.junit.Test;
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.containsString;
5+
import static org.hamcrest.Matchers.is;
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assert.fail;
78

89
import java.text.SimpleDateFormat;
910
import java.util.ArrayList;
1011
import java.util.Date;
1112
import java.util.List;
1213
import java.util.TimeZone;
1314

14-
import static org.hamcrest.MatcherAssert.assertThat;
15-
import static org.hamcrest.Matchers.containsString;
16-
import static org.hamcrest.Matchers.is;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.fail;
15+
import com.yoti.api.client.AttributeDefinition;
16+
import com.yoti.api.client.spi.remote.call.YotiConstants;
17+
18+
import org.junit.Test;
1919

2020
public class SimpleThirdPartyAttributeExtensionBuilderTest {
2121

@@ -68,9 +68,7 @@ public void shouldBuildThirdPartyAttributeExtensionWithGivenValues() {
6868
.withDefinition(SOME_DEFINITION)
6969
.build();
7070

71-
SimpleDateFormat sdf = new SimpleDateFormat(YotiConstants.RFC3339_PATTERN_MILLIS);
72-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
73-
String formattedTestDate = sdf.format(SOME_DATE);
71+
String formattedTestDate = formatDateToString(SOME_DATE);
7472

7573
assertEquals(ExtensionConstants.THIRD_PARTY_ATTRIBUTE, extension.getType());
7674
assertEquals(formattedTestDate, extension.getContent().getExpiryDate());
@@ -81,7 +79,7 @@ public void shouldBuildThirdPartyAttributeExtensionWithGivenValues() {
8179
}
8280

8381
@Test
84-
public void shouldBuildThirdPartyAttributeExtensionWithCorrectDateValue() {
82+
public void shouldBuildThirdPartyAttributeExtensionWithCorrectlyFormattedDateString() {
8583
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
8684
Date date = new Date();
8785

@@ -90,16 +88,23 @@ public void shouldBuildThirdPartyAttributeExtensionWithCorrectDateValue() {
9088
.withDefinition(SOME_DEFINITION)
9189
.build();
9290

93-
SimpleDateFormat sdf = new SimpleDateFormat(YotiConstants.RFC3339_PATTERN_MILLIS);
94-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
95-
String formattedTestDate = sdf.format(date);
91+
String formattedTestDate = formatDateToString(date);
9692

97-
assertEquals(ExtensionConstants.THIRD_PARTY_ATTRIBUTE, extension.getType());
9893
assertEquals(formattedTestDate, extension.getContent().getExpiryDate());
94+
}
9995

100-
List<AttributeDefinition> definitions = extension.getContent().getDefinitions();
101-
assertThat(definitions.size(), is(1));
102-
assertThat(definitions.get(0).getName(), is(SOME_DEFINITION));
96+
@Test
97+
public void shouldWorkCorrectlyWithDateCreatedFromTimestamp() {
98+
Date date = new Date(1586252260);
99+
100+
Extension<ThirdPartyAttributeContent> extension = new SimpleThirdPartyAttributeExtensionBuilder()
101+
.withExpiryDate(date)
102+
.withDefinition(SOME_DEFINITION)
103+
.build();
104+
105+
String formattedTestDate = formatDateToString(date);
106+
107+
assertEquals(formattedTestDate, extension.getContent().getExpiryDate());
103108
}
104109

105110
@Test
@@ -141,4 +146,10 @@ public void shouldOverwriteSingularlyAddedDefinition() {
141146
assertThat(definitions.get(1).getName(), is("secondDefinition"));
142147
}
143148

149+
private String formatDateToString(Date date) {
150+
SimpleDateFormat sdf = new SimpleDateFormat(YotiConstants.RFC3339_PATTERN_MILLIS);
151+
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
152+
return sdf.format(date);
153+
}
154+
144155
}

0 commit comments

Comments
 (0)