Skip to content

Commit 255e17c

Browse files
Alexander Kiselyovzoewangg
Alexander Kiselyov
authored andcommitted
Ensure build works for Windows aws#986
Adding convenience method that allows to replace '\n' characters with the platform-dependent ones and applying it to affected test data. Supplementing CHANGELOG.MD with changes' description. Clarifying necessity of using the new-change script for such actions.
1 parent ae7b6fd commit 255e17c

File tree

5 files changed

+90
-56
lines changed

5 files changed

+90
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"description": "Code Generator test failures on Windows systems were fixed.",
3+
"type": "bugfix",
4+
"category": "AWS SDK for Java v2"
5+
}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ checklist below:
123123
* [ ] If the change is related to an existing Bug Report or Feature Request,
124124
the issue number is referenced
125125
* [ ] A short description of the change added to
126-
[CHANGELOG.md](./CHANGELOG.md). Adding a new entry can be accomplished by
126+
[CHANGELOG.md](./CHANGELOG.md). Adding a new entry must be accomplished by
127127
running the `scripts/new-change` script and following the instructions.
128128
Commit the new file created by the script in `.changes/next-release` with
129129
your changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package software.amazon.awssdk.codegen;
2+
3+
import software.amazon.awssdk.codegen.internal.Constant;
4+
5+
/**
6+
* Various convenience methods for strings manipulation required in Code Generator tests.
7+
*/
8+
public final class TestStringUtils {
9+
10+
/**
11+
* Not intended to be constructed directly.
12+
*/
13+
private TestStringUtils() {
14+
}
15+
16+
/**
17+
* Replaces all the newline (line feed/LF) characters ('\u000A' or '\n') with the platform-dependent line separator char
18+
* (e.g. "\u000D\u000A" or "\r\n" on Windows systems).
19+
*
20+
* @param str string, containing '\n' chars to be replaced
21+
* @return original string with '\n' chars replaced with platform-dependent line separator chars
22+
* @see Constant#LF
23+
*/
24+
public static String toPlatformLfs(String str) {
25+
return str.replaceAll("\n", Constant.LF);
26+
}
27+
28+
}

codegen/src/test/java/software/amazon/awssdk/codegen/emitters/PoetGeneratorTaskIntegrationTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.hamcrest.CoreMatchers.startsWith;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222
import static org.hamcrest.core.CombinableMatcher.both;
23+
import static software.amazon.awssdk.codegen.TestStringUtils.toPlatformLfs;
2324
import static software.amazon.awssdk.utils.FunctionalUtils.safeConsumer;
2425

2526
import com.squareup.javapoet.ClassName;
@@ -43,7 +44,7 @@ public final class PoetGeneratorTaskIntegrationTest {
4344
public void canGenerateJavaClass() throws Exception {
4445
String randomBaseDirectory = Files.createTempDirectory(getClass().getSimpleName()).toString();
4546
tempDirectories.add(randomBaseDirectory);
46-
String fileHeader = "/*\n * this is the file header\n */";
47+
String fileHeader = toPlatformLfs("/*\n * this is the file header\n */");
4748
ClassSpec classSpec = dummyClass();
4849

4950
PoetGeneratorTask sut = new PoetGeneratorTask(randomBaseDirectory, fileHeader, classSpec);

codegen/src/test/java/software/amazon/awssdk/codegen/model/intermediate/DocumentationBuilderTest.java

+54-54
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@
1717

1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static software.amazon.awssdk.codegen.TestStringUtils.toPlatformLfs;
2021

2122
import org.junit.Test;
2223
import software.amazon.awssdk.codegen.docs.DocumentationBuilder;
2324

24-
2525
public class DocumentationBuilderTest {
2626

2727
@Test
2828
public void javadocFormattedCorrectly() {
2929
String docs = new DocumentationBuilder()
30-
.description("Some service docs")
31-
.param("paramOne", "param one docs")
32-
.param("paramTwo", "param two docs")
33-
.returns("This returns something")
34-
.syncThrows("FooException", "Thrown when foo happens")
35-
.syncThrows("BarException", "Thrown when bar happens")
36-
.tag("sample", "FooService.FooOperation")
37-
.see("this thing")
38-
.see("this other thing")
39-
.build();
40-
assertThat(docs).isEqualTo("Some service docs\n" +
41-
"\n" +
42-
"@param paramOne param one docs\n" +
43-
"@param paramTwo param two docs\n" +
44-
"@return This returns something\n" +
45-
"@throws FooException Thrown when foo happens\n" +
46-
"@throws BarException Thrown when bar happens\n" +
47-
"@sample FooService.FooOperation\n" +
48-
"@see this thing\n" +
49-
"@see this other thing\n");
30+
.description("Some service docs")
31+
.param("paramOne", "param one docs")
32+
.param("paramTwo", "param two docs")
33+
.returns("This returns something")
34+
.syncThrows("FooException", "Thrown when foo happens")
35+
.syncThrows("BarException", "Thrown when bar happens")
36+
.tag("sample", "FooService.FooOperation")
37+
.see("this thing")
38+
.see("this other thing")
39+
.build();
40+
assertThat(docs).isEqualTo(toPlatformLfs("Some service docs\n" +
41+
"\n" +
42+
"@param paramOne param one docs\n" +
43+
"@param paramTwo param two docs\n" +
44+
"@return This returns something\n" +
45+
"@throws FooException Thrown when foo happens\n" +
46+
"@throws BarException Thrown when bar happens\n" +
47+
"@sample FooService.FooOperation\n" +
48+
"@see this thing\n" +
49+
"@see this other thing\n"));
5050
}
5151

5252
/**
@@ -57,55 +57,55 @@ public void javadocFormattedCorrectly() {
5757
@Test
5858
public void asyncReturns_FormatsExceptionsInUnorderedList() {
5959
String docs = new DocumentationBuilder()
60-
.description("Some service docs")
61-
.param("paramOne", "param one docs")
62-
.returns("CompletableFuture of success")
63-
.asyncThrows("FooException", "Foo docs")
64-
.asyncThrows("BarException", "Bar docs")
65-
.build();
66-
assertThat(docs).isEqualTo("Some service docs\n" +
67-
"\n" +
68-
"@param paramOne param one docs\n" +
69-
"@return CompletableFuture of success<br/>\n" +
70-
"The CompletableFuture returned by this method can be completed exceptionally with the following exceptions.\n" +
71-
"<ul>\n" +
72-
"<li>FooException Foo docs</li>\n" +
73-
"<li>BarException Bar docs</li>\n" +
74-
"</ul>\n");
60+
.description("Some service docs")
61+
.param("paramOne", "param one docs")
62+
.returns("CompletableFuture of success")
63+
.asyncThrows("FooException", "Foo docs")
64+
.asyncThrows("BarException", "Bar docs")
65+
.build();
66+
assertThat(docs).isEqualTo(toPlatformLfs("Some service docs\n" +
67+
"\n" +
68+
"@param paramOne param one docs\n" +
69+
"@return CompletableFuture of success<br/>\n" +
70+
"The CompletableFuture returned by this method can be completed exceptionally with the following exceptions.\n" +
71+
"<ul>\n" +
72+
"<li>FooException Foo docs</li>\n" +
73+
"<li>BarException Bar docs</li>\n" +
74+
"</ul>\n"));
7575

7676
}
7777

7878
@Test
7979
public void asyncReturnsWithoutDocsForSuccessReturn_FormatsExceptionsInUnorderedList() {
8080
String docs = new DocumentationBuilder()
81-
.description("Some service docs")
82-
.param("paramOne", "param one docs")
83-
.asyncThrows("FooException", "Foo docs")
84-
.asyncThrows("BarException", "Bar docs")
85-
.build();
86-
assertThat(docs).isEqualTo("Some service docs\n" +
87-
"\n" +
88-
"@param paramOne param one docs\n" +
89-
"@return A CompletableFuture indicating when result will be completed.<br/>\n" +
90-
"The CompletableFuture returned by this method can be completed exceptionally with the following exceptions.\n" +
91-
"<ul>\n" +
92-
"<li>FooException Foo docs</li>\n" +
93-
"<li>BarException Bar docs</li>\n" +
94-
"</ul>\n");
81+
.description("Some service docs")
82+
.param("paramOne", "param one docs")
83+
.asyncThrows("FooException", "Foo docs")
84+
.asyncThrows("BarException", "Bar docs")
85+
.build();
86+
assertThat(docs).isEqualTo(toPlatformLfs("Some service docs\n" +
87+
"\n" +
88+
"@param paramOne param one docs\n" +
89+
"@return A CompletableFuture indicating when result will be completed.<br/>\n" +
90+
"The CompletableFuture returned by this method can be completed exceptionally with the following exceptions.\n" +
91+
"<ul>\n" +
92+
"<li>FooException Foo docs</li>\n" +
93+
"<li>BarException Bar docs</li>\n" +
94+
"</ul>\n"));
9595
}
9696

9797
@Test
9898
public void missingValuesAreNotPresent() {
9999
String docs = new DocumentationBuilder()
100-
.description("Some service docs")
101-
.build();
102-
assertThat(docs).isEqualTo("Some service docs\n\n");
100+
.description("Some service docs")
101+
.build();
102+
assertThat(docs).isEqualTo(toPlatformLfs("Some service docs\n\n"));
103103
}
104104

105105
@Test
106106
public void allValuesMissing_ProducesEmptyDocString() {
107107
String docs = new DocumentationBuilder()
108-
.build();
108+
.build();
109109
assertThat(docs).isEqualTo("");
110110
}
111111

0 commit comments

Comments
 (0)