Skip to content

Commit

Permalink
Update with string value
Browse files Browse the repository at this point in the history
  • Loading branch information
wsargent committed Apr 13, 2024
1 parent f48ab86 commit 72c06a7
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
public class ToStringValueTests {

@Test
public void testDurationValue() {
public void testString() {
Duration duration = Duration.ofDays(1);
var value = Value.string(duration.toString()); // PT24H in line and JSON
Attribute<String> stringAttribute = withToStringValue(formatDuration(duration));
var durationWithToString = value.withAttributes(Attributes.create(stringAttribute)); // 1 day in toString()
assertThat(durationWithToString).hasToString("1 day");
}

@Test
public void testArray() {
var one = Value.string("one");
var two = Value.string("two").withAttributes(Attributes.create(withToStringValue("dos")));
var three = Value.string("three");
var array = Value.array(one, two, three);
assertThat(array).hasToString("[one, dos, three]");
}

private static String formatDuration(Duration duration) {
List<String> parts = new ArrayList<>();
long days = duration.toDaysPart();
Expand Down

0 comments on commit 72c06a7

Please sign in to comment.