Skip to content

Commit

Permalink
Refactor IdentifierValue (#33744)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 20, 2024
1 parent 8722823 commit 195c6a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ public enum QuoteCharacter {
* @return value of quote character
*/
public static QuoteCharacter getQuoteCharacter(final String value) {
if (Strings.isNullOrEmpty(value)) {
return NONE;
}
return BY_FIRST_CHAR.getOrDefault(value.charAt(0), NONE);
return Strings.isNullOrEmpty(value) ? NONE : BY_FIRST_CHAR.getOrDefault(value.charAt(0), NONE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public String getValueWithQuoteCharacters() {
* @return quote content
*/
public static String getQuotedContent(final String text) {
if (Strings.isNullOrEmpty(text)) {
return text;
}
QuoteCharacter quoteCharacter = QuoteCharacter.getQuoteCharacter(text);
if (QuoteCharacter.NONE == quoteCharacter) {
return text.trim();
}
return text.substring(1, text.length() - 1);
return Strings.isNullOrEmpty(text) ? text : QuoteCharacter.getQuoteCharacter(text).unwrap(text).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

class IdentifierValueTest {

Expand Down Expand Up @@ -53,4 +54,26 @@ void assertGetIdentifierValueWithReservedBracket() {
String text = "ds_${[1,2]}.t_order";
assertThat(new IdentifierValue(text, "[]").getValue(), is("ds_${[1,2]}.t_order"));
}

@Test
void assertGetValueWithQuoteCharactersWithNullValue() {
assertThat(new IdentifierValue(null).getValueWithQuoteCharacters(), is(""));
}

@Test
void assertGetValueWithQuoteCharactersWithValue() {
String text = "[foo]";
assertThat(new IdentifierValue(text).getValueWithQuoteCharacters(), is("[foo]"));
}

@Test
void assertGetQuotedContentWithNullValue() {
assertNull(IdentifierValue.getQuotedContent(null));
}

@Test
void assertGetQuotedContent() {
assertThat(IdentifierValue.getQuotedContent(" foo "), is("foo"));
assertThat(IdentifierValue.getQuotedContent("`foo`"), is("foo"));
}
}

0 comments on commit 195c6a9

Please sign in to comment.