From 4a44d07e95b799492f3696188eb0189976e83f40 Mon Sep 17 00:00:00 2001 From: Zhiyang Yu <50703949+rgseyvie@users.noreply.github.com> Date: Mon, 25 Apr 2022 00:17:07 +0800 Subject: [PATCH] add 5 test cases for #405 current date, modify days and hours --- .../test/base/AbstractAssertJTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java b/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java index 7bad5b3bf..560b5ed9b 100644 --- a/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java +++ b/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java @@ -410,6 +410,36 @@ void shouldAssertObjectJson() { void shouldAssertContainsEntry() { assertThatJson("{\"a\":{\"b\": 1}}").node("a").isObject().contains(entry("b", valueOf(1))); } + + //date issue + @Test + void shouldReplaceDate() { + assertThatJson("{\"root\":{\"test\":1, \"date\": \"2022-04-24: 15\"}}").isEqualTo("{\"root\":{\"test\":1, \"date\": \"${json-unit.current-date.format:yyyy-MM-dd: HH}\"}}"); + } + + //date issue + @Test + void shouldReplaceDaysAdded() { + assertThatJson("{\"root\":{\"test\":1, \"date\": \"2022-04-25\"}}").isEqualTo("{\"root\":{\"test\":1, \"date\": \"${json-unit.current-date.DAYS#+1.format:yyyy-MM-dd}\"}}"); + } + + //date issue + @Test + void shouldReplaceDaysDeducted() { + assertThatJson("{\"root\":{\"test\":1, \"date\": \"2022-04-22\"}}").isEqualTo("{\"root\":{\"test\":1, \"date\": \"${json-unit.current-date.DAYS#-2.format:yyyy-MM-dd}\"}}"); + } + + //date issue + @Test + void shouldReplaceHoursAdded() { + assertThatJson("{\"root\":{\"test\":1, \"date\": \"2022-04-24: 16\"}}").isEqualTo("{\"root\":{\"test\":1, \"date\": \"${json-unit.current-date.HOURS#+1.format:yyyy-MM-dd: HH}\"}}"); + } + + //date issue + @Test + void shouldReplaceHoursDeducted() { + assertThatJson("{\"root\":{\"test\":1, \"date\": \"2022-04-24: 11\"}}").isEqualTo("{\"root\":{\"test\":1, \"date\": \"${json-unit.current-date.HOURS#-4.format:yyyy-MM-dd: HH}\"}}"); + } @Test void shouldAssertContainsJsonError() {