### Question:
Strings { @NotNull public static String ensureEndsWith(@NotNull final String str, final char c) { final int n = str.length(); if (n > 0 && str.charAt(n - 1) == c) { return str; } else { return str + c; } }  @SuppressWarnings({"StringEquality", "SimplifiableIfStatement"}) static boolean eq(final String str1, final String str2); @SuppressWarnings({"StringEquality", "SimplifiableIfStatement"}) static boolean eq(final String str1, final String str2, final boolean caseSensitive); @NotNull static String ensureStartsWith(@NotNull final String str, final char c); @NotNull static String ensureEndsWith(@NotNull final String str, final char c); @NotNull static String removeEnding(@NotNull final String str, @NotNull final String ending); @NotNull static String rtrim(@NotNull final String str); @NotNull static String replace(@NotNull final String where, @NotNull final String what, @NotNull final String with); @NotNull static String repeat(@NotNull final String what, @Nullable final String delimiter, int count); @Contract("null,_->false") static boolean matches(@Nullable final CharSequence string, @NotNull final Pattern pattern); @Contract("null,_,_->false") static boolean matches(@Nullable final CharSequence string, @NotNull final String pattern, boolean caseSensitive); @Contract("!null->!null; null->null") static String upper(@Nullable final String string); @Contract("!null->!null; null->null") static String lower(@Nullable final String string); @Contract("!null->!null; null->null") static String minimizeSpaces(@Nullable final String string); @Contract("!null,_->!null; null,_->null") static String lastPart(@Nullable final String string, final char delimiter);  }### Answer:
@Test public void ensureEndsWith_basic() { assertThat(ensureEndsWith("AAAA", 'C')).isEqualTo("AAAAC"); assertThat(ensureEndsWith("AAAAC", 'C')).isEqualTo("AAAAC"); assertThat(ensureEndsWith("", 'C')).isEqualTo("C"); }
@Test public void ensureEndsWith_dontMakeNewInstanceIfAlreadyEnds() { final String str = "AAAC"; final String ensured = ensureEndsWith(str, 'C'); assertThat(ensured).isSameAs(str); }