|
49 | 49 | import java.util.Set; |
50 | 50 | import java.util.UUID; |
51 | 51 | import java.util.stream.Collectors; |
| 52 | +import java.util.stream.Stream; |
52 | 53 | import org.apache.commons.io.FileUtils; |
53 | 54 | import org.apache.commons.lang.UnhandledException; |
54 | 55 | import org.hamcrest.Matchers; |
55 | 56 | import org.jetbrains.annotations.NotNull; |
56 | 57 | import org.junit.jupiter.api.BeforeAll; |
57 | 58 | import org.junit.jupiter.api.Test; |
58 | 59 | import org.junit.jupiter.params.ParameterizedTest; |
| 60 | +import org.junit.jupiter.params.provider.Arguments; |
59 | 61 | import org.junit.jupiter.params.provider.CsvSource; |
| 62 | +import org.junit.jupiter.params.provider.MethodSource; |
60 | 63 | import org.openapitools.codegen.CliOption; |
61 | 64 | import org.openapitools.codegen.ClientOptInput; |
62 | 65 | import org.openapitools.codegen.CodegenOperation; |
@@ -98,56 +101,18 @@ void newLineIndent() throws IOException { |
98 | 101 | assertThat(output.toString(), equalTo(String.format("__%n__Good%n__ morning,%n__ Dave%n"))); |
99 | 102 | } |
100 | 103 |
|
101 | | - @Test |
102 | | - void unwrapEscapedQuotes_withNullInput_shouldWriteNothing() throws IOException { |
103 | | - final BoatSpringCodeGen.UnwrapEscapedQuotes lambda = new BoatSpringCodeGen.UnwrapEscapedQuotes(); |
104 | | - final StringWriter output = new StringWriter(); |
105 | | - final Fragment frag = mock(Fragment.class); |
106 | | - |
107 | | - when(frag.execute()).thenReturn(null); |
108 | | - |
109 | | - lambda.execute(frag, output); |
110 | | - |
111 | | - assertThat(output.toString(), equalTo("")); |
112 | | - } |
113 | | - |
114 | | - @Test |
115 | | - void unwrapEscapedQuotes_withWrappedEscapedQuotes_shouldRemoveOuterEscapedQuotes() throws IOException { |
116 | | - final BoatSpringCodeGen.UnwrapEscapedQuotes lambda = new BoatSpringCodeGen.UnwrapEscapedQuotes(); |
117 | | - final StringWriter output = new StringWriter(); |
118 | | - final Fragment frag = mock(Fragment.class); |
119 | | - |
120 | | - when(frag.execute()).thenReturn("\\\"{\\\"message\\\":\\\"Bad Request\\\"}\\\""); |
121 | | - |
122 | | - lambda.execute(frag, output); |
123 | | - |
124 | | - assertThat(output.toString(), equalTo("{\\\"message\\\":\\\"Bad Request\\\"}")); |
125 | | - } |
126 | | - |
127 | | - @Test |
128 | | - void unwrapEscapedQuotes_withDoubleEscapedQuotesAndNoWrapper_shouldOnlyNormalize() throws IOException { |
129 | | - final BoatSpringCodeGen.UnwrapEscapedQuotes lambda = new BoatSpringCodeGen.UnwrapEscapedQuotes(); |
130 | | - final StringWriter output = new StringWriter(); |
131 | | - final Fragment frag = mock(Fragment.class); |
132 | | - |
133 | | - when(frag.execute()).thenReturn("prefix\\\\\"quoted\\\\\"suffix"); |
134 | | - |
135 | | - lambda.execute(frag, output); |
136 | | - |
137 | | - assertThat(output.toString(), equalTo("prefix\\\"quoted\\\"suffix")); |
138 | | - } |
139 | | - |
140 | | - @Test |
141 | | - void unwrapEscapedQuotes_withShortEscapedQuoteToken_shouldNotUnwrap() throws IOException { |
| 104 | + @ParameterizedTest |
| 105 | + @MethodSource("unwrapEscapedQuotesCases") |
| 106 | + void unwrapEscapedQuotes_execute_shouldHandleAllScenarios(String input, String expectedOutput) throws IOException { |
142 | 107 | final BoatSpringCodeGen.UnwrapEscapedQuotes lambda = new BoatSpringCodeGen.UnwrapEscapedQuotes(); |
143 | 108 | final StringWriter output = new StringWriter(); |
144 | 109 | final Fragment frag = mock(Fragment.class); |
145 | 110 |
|
146 | | - when(frag.execute()).thenReturn("\\\""); |
| 111 | + when(frag.execute()).thenReturn(input); |
147 | 112 |
|
148 | 113 | lambda.execute(frag, output); |
149 | 114 |
|
150 | | - assertThat(output.toString(), equalTo("\\\"")); |
| 115 | + assertThat(output.toString(), equalTo(expectedOutput)); |
151 | 116 | } |
152 | 117 |
|
153 | 118 | @Test |
@@ -644,4 +609,12 @@ private static void assertMethodCollectionReturnType(MethodDeclaration method, S |
644 | 609 | .getTypeArguments().get().getFirst().get(); |
645 | 610 | assertEquals(itemType, collectionItemType.getName().toString()); |
646 | 611 | } |
| 612 | + |
| 613 | + static Stream<Arguments> unwrapEscapedQuotesCases() { |
| 614 | + return Stream.of( |
| 615 | + Arguments.of((String) null, ""), |
| 616 | + Arguments.of("\\\"{\\\"message\\\":\\\"Bad Request\\\"}\\\"", "{\\\"message\\\":\\\"Bad Request\\\"}"), |
| 617 | + Arguments.of("prefix\\\\\"quoted\\\\\"suffix", "prefix\\\"quoted\\\"suffix"), |
| 618 | + Arguments.of("\\\"", "\\\"")); |
| 619 | + } |
647 | 620 | } |
0 commit comments