Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit docs code snippets line length to max 60 chars (#317 / #318) #318

Merged
merged 17 commits into from
Sep 29, 2020
Merged
41 changes: 27 additions & 14 deletions docs/default-locale-timezone.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ The default `Locale` can be specified using an https://docs.oracle.com/javase/8/
@Test
@DefaultLocale("zh-Hant-TW")
void test_with_lanuage() {
assertThat(Locale.getDefault()).isEqualTo(Locale.forLanguageTag("zh-Hant-TW"));
assertThat(Locale.getDefault()).
isEqualTo(Locale.forLanguageTag("zh-Hant-TW"));
}
----

Expand All @@ -29,19 +30,25 @@ Alternatively the default `Locale` can be specified according to https://docs.or
@Test
@DefaultLocale(language = "en")
void test_with_lanuage() {
assertThat(Locale.getDefault()).isEqualTo(new Locale("en"));
assertThat(Locale.getDefault()).
isEqualTo(new Locale("en"));
}

@Test
@DefaultLocale(language = "en", country = "EN")
@DefaultLocale(language = "en",
country = "EN")
void test_with_lanuage_and_country() {
assertThat(Locale.getDefault()).isEqualTo(new Locale("en", "EN"));
assertThat(Locale.getDefault()).
isEqualTo(new Locale("en", "EN"));
}

@Test
@DefaultLocale(language = "en", country = "EN", variant = "gb")
@DefaultLocale(language = "en",
country = "EN",
variant = "gb")
void test_with_lanuage_and_country_and_vairant() {
assertThat(Locale.getDefault()).isEqualTo(new Locale("en", "EN", "gb"));
assertThat(Locale.getDefault()).
isEqualTo(new Locale("en", "EN", "gb"));
}
----

Expand All @@ -58,13 +65,15 @@ class MyLocaleTests {

@Test
void test_with_class_level_configuration() {
assertThat(Locale.getDefault()).isEqualTo(new Locale("fr"));
assertThat(Locale.getDefault()).
isEqualTo(new Locale("fr"));
}

@Test
@DefaultLocale(language = "en")
void test_with_method_level_configuration() {
assertThat(Locale.getDefault()).isEqualTo(new Locale("en"));
assertThat(Locale.getDefault()).
isEqualTo(new Locale("en"));
}
}
----
Expand All @@ -78,13 +87,15 @@ The default `TimeZone` is specified according to the https://docs.oracle.com/jav
@Test
@DefaulTimeZone("CET")
void test_with_short_zone_id() {
assertThat(TimeZone.getDefault()).isEqualTo(TimeZone.getTimeZone("CET"));
assertThat(TimeZone.getDefault()).
isEqualTo(TimeZone.getTimeZone("CET"));
}

@Test
@DefaultTimeZone("America/Los_Angeles")
@DefaultTimeZone("Africa/Juba")
void test_with_long_zone_id() {
assertThat(TimeZone.getDefault()).isEqualTo(TimeZone.getTimeZone("America/Los_Angeles"));
assertThat(TimeZone.getDefault()).
isEqualTo(TimeZone.getTimeZone("Africa/Juba"));
}
----

Expand All @@ -97,13 +108,15 @@ class MyTimeZoneTests {

@Test
void test_with_class_level_configuration() {
assertThat(TimeZone.getDefault()).isEqualTo(TimeZone.getTimeZone("CET"));
assertThat(TimeZone.getDefault()).
isEqualTo(TimeZone.getTimeZone("CET"));
}

@Test
@DefaultTimeZone("America/Los_Angeles")
@DefaultTimeZone("Africa/Juba")
void test_with_method_level_configuration() {
assertThat(TimeZone.getDefault()).isEqualTo(TimeZone.getTimeZone("America/Los_Angeles"));
assertThat(TimeZone.getDefault()).
isEqualTo(TimeZone.getTimeZone("Africa/Juba"));
}
}
----
Expand Down
41 changes: 23 additions & 18 deletions docs/disable-if-display-name.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ As a consequence, instead of disabling the entire set of parameterized tests, ea
@DisableIfDisplayName(contains = "disable")
@ParameterizedTest(name = "See if enabled with {0}")
@ValueSource(
strings = {
"disable who", // ~> disabled
"you, disable you", // ~> disabled
"why am I disabled", // ~> disabled
"what has been disabled must stay disabled", // ~> disabled
"fine disable me all you want", // ~> disabled
"not those one, though!" // ~> NOT disabled
}
// Disabled: 1,2,3, 4,5
// Not disabled: 6
strings = {
"disable who", // 1
"you, disable you", // 2
"why am I disabled", // 3
"what has been disabled must stay disabled", // 4
"fine disable me all you want", // 5
"not those one, though!" // 6
}
)
void testExecutionDisabled(String reason) {
if (reason.contains("disable"))
Expand All @@ -44,18 +46,21 @@ If substrings are not powerful enough, you can also use regular expressions:

[source,java]
----
// disable invocations whose display name contains "disable " or "disabled "
// disable invocations whose display name
// contains "disable " or "disabled "
@DisableIfDisplayName(matches = ".*disabled?\\s.*")
@ParameterizedTest(name = "See if enabled with {0}")
@ValueSource(
strings = {
"disable who", // ~> disabled
"you, disable you", // ~> disabled
"why am I disabled", // ~> NOT disabled
"what has been disabled must stay disabled", // ~> disabled
"fine disable me all you want", // ~> disabled
"not those one, though!" // ~> NOT disabled
}
// Disabled: 1,2,4,5
// Not disabled: 3,6
strings = {
"disable who", // 1
"you, disable you", // 2
"why am I disabled", // 3
"what has been disabled must stay disabled", // 4
"fine disable me all you want", // 5
"not those one, though!" // 6
}
)
void single(String reason) {
// ...
Expand All @@ -73,4 +78,4 @@ void containsAndMatches_containsAndMatches(int number) {
if (number != 100)
fail("Test should've been disabled for " + number);
}
----
----
24 changes: 16 additions & 8 deletions docs/environment-variables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ And setting a environment variable for a test execution:
[source,java]
----
@Test
@SetEnvironmentVariable(key = "some variable", value = "new value")
@SetEnvironmentVariable(key = "some variable",
value = "new value")
void test() {
assertThat(System.getenv("some variable")).isEqualTo("new value");
assertThat(System.getenv("some variable")).
isEqualTo("new value");
}
----

Expand All @@ -40,11 +42,15 @@ As mentioned before, both annotations are repeatable and they can also be combin
@Test
@ClearEnvironmentVariable(key = "1st variable")
@ClearEnvironmentVariable(key = "2nd variable")
@SetEnvironmentVariable(key = "3rd variable", value = "new value")
@SetEnvironmentVariable(key = "3rd variable",
value = "new value")
void test() {
assertThat(System.getenv("1st variable")).isNull();
assertThat(System.getenv("2nd variable")).isNull();
assertThat(System.getenv("3rd variable")).isEqualTo("new value");
assertThat(System.getenv("1st variable")).
isNull();
assertThat(System.getenv("2nd variable")).
isNull();
assertThat(System.getenv("3rd variable")).
isEqualTo("new value");
}
----

Expand All @@ -55,9 +61,11 @@ Note that class level configurations are overwritten by method level configurati
@ClearEnvironmentVariable(key = "some variable")
class MyEnvironmentVariableTest {
@Test
@SetEnvironmentVariable(key = "some variable", value = "new value")
@SetEnvironmentVariable(key = "some variable",
value = "new value")
void test() {
assertThat(System.getenv("some variable")).isEqualTo("new value");
assertThat(System.getenv("some variable")).
isEqualTo("new value");
}
}
----
Expand Down
6 changes: 3 additions & 3 deletions docs/range-sources.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ It can be positive or negative:
@ParameterizedTest
@DoubleRangeSource(from = -0.1, to = -10, step = -0.1)
void howColdIsIt(double d) {
System.out.println(d + " degrees Celsius is cold");
System.out.println(d + " degrees Fahrenheit is REALY cold");
System.out.println(d + " degrees Kelvin is too cold to be true");
System.out.println(d + " °C is cold");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, non-ASCII chars in code snippets? 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Extended) ASCII-Code 248 :p http://www.asciitable.com/

I havn't come up with the short limit of 60 chars where about 40 are for intenden and System.out.println(..); 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every day's a school say. 👍

System.out.println(d + " °F is REALY cold");
System.out.println(d + " K is too cold to be true");
}
----

Expand Down
10 changes: 7 additions & 3 deletions docs/report-entries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ Just like `TestReporter::publishEntry` accepts a single string as value or a key
[source,java]
----
@Test
@ReportEntry(key = "line1", value = "Once upon a midnight dreary")
@ReportEntry(key = "line2", value = "While I pondered weak and weary")
@ReportEntry(key = "line1",
value = "Once upon a midnight dreary")
@ReportEntry(key = "line2",
value = "While I pondered weak and weary")
void edgarAllanPoe() {
// YOUR TEST CODE HERE
}
Expand All @@ -89,7 +91,9 @@ Just so:
[source,java]
----
@Test
@ReportEntry(key = "line", value = "success entry", when = ReportEntry.PublishCondition.ON_SUCCESS)
@ReportEntry(key = "line",
value = "success entry",
when = ReportEntry.PublishCondition.ON_SUCCESS)
void sufferingFromSuccess() {
// YOUR TEST CODE HERE
}
Expand Down
3 changes: 2 additions & 1 deletion docs/retrying-test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ The first two executions are marked as ignored/aborted, while the last as failed
```java
@RetryingTest(3)
void aborted() {
// test code that is aborted e.g. because of an Assumption.
// test code that is aborted,
// e.g. because of an Assumption.
}
```

Expand Down
16 changes: 11 additions & 5 deletions docs/standard-input-output.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ExampleConsoleReader {
private List<String> lines = new ArrayList<>();

public void readLines() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(is);
for (int i = 0; i < 2; i++) {
String line = reader.readLine();
lines.add(line);
Expand All @@ -158,17 +159,22 @@ This is the unit test for this class, using `StdIoExtension`:

[source, java]
----
class ExampleConsoleReaderTest {
class ConsoleReaderTest {

@Test
@StdIo({ "line1", "line2", "line3" })
void testReadLines(StdIn in) {
ExampleConsoleReader consoleReader = new ExampleConsoleReader();
ConsoleReader consoleReader = new ConsoleReader();

consoleReader.readLines();

// assertEquals(in.capturedLines(), "line1", "line2"); // This is failing
// assertEquals(in.capturedLines(), "line1", "line2", "line3"); // This is passing
String[] lines = in.capturedLines();

// This failing
// assertEquals(lines, "line1", "line2");
Bukama marked this conversation as resolved.
Show resolved Hide resolved

// This is passing
// assertEquals(lines, "line1", "line2", "line3");
Bukama marked this conversation as resolved.
Show resolved Hide resolved
}

}
Expand Down
27 changes: 18 additions & 9 deletions docs/system-properties.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ For example, clearing a system property for a test execution can be done as foll
@Test
@ClearSystemProperty(key = "some property")
void test() {
assertThat(System.getProperty("some property")).isNull();
assertThat(System.getProperty("some property")).
isNull();
Bukama marked this conversation as resolved.
Show resolved Hide resolved
}
----

Expand All @@ -22,9 +23,11 @@ And setting a system property for a test execution:
[source,java]
----
@Test
@SetSystemProperty(key = "some property", value = "new value")
@SetSystemProperty(key = "some property",
value = "new value")
void test() {
assertThat(System.getProperty("some property")).isEqualTo("new value");
assertThat(System.getProperty("some property")).
isEqualTo("new value");
}
----

Expand All @@ -35,11 +38,15 @@ As mentioned before, both annotations are repeatable and they can also be combin
@Test
@ClearSystemProperty(key = "1st property")
@ClearSystemProperty(key = "2nd property")
@SetSystemProperty(key = "3rd property", value = "new value")
@SetSystemProperty(key = "3rd property",
value = "new value")
void test() {
assertThat(System.getProperty("1st property")).isNull();
assertThat(System.getProperty("2nd property")).isNull();
assertThat(System.getProperty("3rd property")).isEqualTo("new value");
assertThat(System.getProperty("1st property")).
isNull();
assertThat(System.getProperty("2nd property")).
isNull();
Bukama marked this conversation as resolved.
Show resolved Hide resolved
assertThat(System.getProperty("3rd property")).
isEqualTo("new value");
}
----

Expand All @@ -50,9 +57,11 @@ Note that class level configurations are overwritten by method level configurati
@ClearSystemProperty(key = "some property")
class MySystemPropertyTest {
@Test
@SetSystemProperty(key = "some property", value = "new value")
@SetSystemProperty(key = "some property",
value = "new value")
void test() {
assertThat(System.getProperty("some property")).isEqualTo("new value");
assertThat(System.getProperty("some property")).
isEqualTo("new value");
}
}
----
Expand Down