11package 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
89import java .text .SimpleDateFormat ;
910import java .util .ArrayList ;
1011import java .util .Date ;
1112import java .util .List ;
1213import 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
2020public 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 ());
@@ -80,6 +78,35 @@ public void shouldBuildThirdPartyAttributeExtensionWithGivenValues() {
8078 assertThat (definitions .get (0 ).getName (), is (SOME_DEFINITION ));
8179 }
8280
81+ @ Test
82+ public void shouldBuildThirdPartyAttributeExtensionWithCorrectlyFormattedDateString () {
83+ TimeZone .setDefault (TimeZone .getTimeZone ("America/New_York" ));
84+ Date date = new Date ();
85+
86+ Extension <ThirdPartyAttributeContent > extension = new SimpleThirdPartyAttributeExtensionBuilder ()
87+ .withExpiryDate (date )
88+ .withDefinition (SOME_DEFINITION )
89+ .build ();
90+
91+ String formattedTestDate = formatDateToString (date );
92+
93+ assertEquals (formattedTestDate , extension .getContent ().getExpiryDate ());
94+ }
95+
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 ());
108+ }
109+
83110 @ Test
84111 public void shouldBuildThirdPartyAttributeExtensionWithMultipleDefinitions () {
85112 List <String > theDefinitions = new ArrayList <>();
@@ -119,4 +146,10 @@ public void shouldOverwriteSingularlyAddedDefinition() {
119146 assertThat (definitions .get (1 ).getName (), is ("secondDefinition" ));
120147 }
121148
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+
122155}
0 commit comments