1515import java .util .HashMap ;
1616import java .util .Map ;
1717
18+ import static org .hamcrest .Matchers .endsWith ;
1819import static org .hamcrest .Matchers .equalTo ;
1920import static org .hamcrest .Matchers .hasLength ;
2021import static org .hamcrest .Matchers .not ;
@@ -36,15 +37,8 @@ public void testTruncatingStepInfo() {
3637 + randomAlphanumericOfLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH + 100 )
3738 + "\" }" ;
3839 LifecycleExecutionState newState = LifecycleExecutionState .builder (state ).setStepInfo (longStepInfo ).build ();
39- assertThat (newState .stepInfo ().length (), equalTo (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH ));
40- assertThat (
41- newState .stepInfo ()
42- .substring (
43- LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH - 28 ,
44- LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH
45- ),
46- equalTo ("... (~111 chars truncated)\" }" )
47- );
40+ assertThat (newState .stepInfo (), hasLength (LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH ));
41+ assertThat (newState .stepInfo (), endsWith ("... (~111 chars truncated)\" }" ));
4842 }
4943
5044 public void testEmptyValuesAreNotSerialized () {
@@ -154,11 +148,13 @@ public void testGetCurrentStepKey() {
154148 assertNull (error6 .getMessage ());
155149 }
156150
157- public void testPotentiallyTruncateLongJsonWithExplanationNotTruncated () {
151+ /** test that strings with length less than or equal to maximum string length are not truncated and returned as-is */
152+ public void testPotentiallyTruncateLongJsonWithExplanationNoNeedToTruncate () {
158153 final String input = randomAlphaOfLengthBetween (0 , LifecycleExecutionState .MAXIMUM_STEP_INFO_STRING_LENGTH );
159154 assertSame (input , LifecycleExecutionState .potentiallyTruncateLongJsonWithExplanation (input ));
160155 }
161156
157+ /** test that string with length one character over the max limit has truncation applied to it and has correct explanation */
162158 public void testPotentiallyTruncateLongJsonWithExplanationOneCharTruncated () {
163159 final String jsonBaseFormat = "{\" key\" : \" %s\" }" ;
164160 final int baseLength = Strings .format (jsonBaseFormat , "" ).length ();
@@ -175,6 +171,7 @@ public void testPotentiallyTruncateLongJsonWithExplanationOneCharTruncated() {
175171 assertEquals (expectedOutput , actualOutput );
176172 }
177173
174+ /** test that string with length two characters over the max limit has truncation applied to it and has correct explanation */
178175 public void testPotentiallyTruncateLongJsonWithExplanationTwoCharsTruncated () {
179176 final String jsonBaseFormat = "{\" key\" : \" %s\" }" ;
180177 final int baseLength = Strings .format (jsonBaseFormat , "" ).length ();
0 commit comments