Skip to content

Commit 172b4ee

Browse files
authored
Update log levels to use test runner v3 features (#2491)
* Update log levels to use test runner v3 features * fixed typo in display name
1 parent 430de85 commit 172b4ee

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

exercises/concept/log-levels/build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
apply plugin: "java"
2-
apply plugin: "eclipse"
3-
apply plugin: "idea"
4-
5-
// set default encoding to UTF-8
6-
compileJava.options.encoding = "UTF-8"
7-
compileTestJava.options.encoding = "UTF-8"
1+
plugins {
2+
id "java"
3+
}
84

95
repositories {
106
mavenCentral()
117
}
128

139
dependencies {
14-
testImplementation "junit:junit:4.13"
10+
testImplementation platform("org.junit:junit-bom:5.10.0")
11+
testImplementation "org.junit.jupiter:junit-jupiter"
1512
testImplementation "org.assertj:assertj-core:3.15.0"
1613
}
1714

1815
test {
16+
useJUnitPlatform()
17+
1918
testLogging {
20-
exceptionFormat = 'full'
19+
exceptionFormat = "full"
2120
showStandardStreams = true
2221
events = ["passed", "failed", "skipped"]
2322
}

exercises/concept/log-levels/src/test/java/LogLevelsTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,86 @@
1-
import org.junit.Test;
1+
import org.junit.jupiter.api.DisplayName;
2+
import org.junit.jupiter.api.Tag;
3+
import org.junit.jupiter.api.Test;
24

35
import static org.assertj.core.api.Assertions.*;
46

57
public class LogLevelsTest {
68
@Test
9+
@Tag("task:1")
10+
@DisplayName("The message method returns the log line's message of an error log")
711
public void error_message() {
812
assertThat(LogLevels.message("[ERROR]: Stack overflow")).isEqualTo("Stack overflow");
913
}
1014

1115
@Test
16+
@Tag("task:1")
17+
@DisplayName("The message method returns the log line's message of a warning log")
1218
public void warning_message() {
1319
assertThat(LogLevels.message("[WARNING]: Disk almost full")).isEqualTo("Disk almost full");
1420
}
1521

1622
@Test
23+
@Tag("task:1")
24+
@DisplayName("The message method returns the log line's message of an info log")
1725
public void info_message() {
1826
assertThat(LogLevels.message("[INFO]: File moved")).isEqualTo("File moved");
1927
}
2028

2129
@Test
30+
@Tag("task:1")
31+
@DisplayName("The message method returns the log line's message after removing leading and trailing spaces")
2232
public void message_with_leading_and_trailing_white_space() {
2333
assertThat(LogLevels.message("[WARNING]: \tTimezone not set \r\n")).isEqualTo("Timezone not set");
2434
}
2535

2636
@Test
37+
@Tag("task:2")
38+
@DisplayName("The logLevel method returns the log level of an error log line")
2739
public void error_log_level() {
2840
assertThat(LogLevels.logLevel("[ERROR]: Disk full")).isEqualTo("error");
2941
}
3042

3143
@Test
44+
@Tag("task:2")
45+
@DisplayName("The logLevel method returns the log level of a warning log line")
3246
public void warning_log_level() {
3347
assertThat(LogLevels.logLevel("[WARNING]: Unsafe password")).isEqualTo("warning");
3448
}
3549

3650
@Test
51+
@Tag("task:2")
52+
@DisplayName("The logLevel method returns the log level of an info log line")
3753
public void info_log_level() {
3854
assertThat(LogLevels.logLevel("[INFO]: Timezone changed")).isEqualTo("info");
3955
}
4056

4157
@Test
58+
@Tag("task:3")
59+
@DisplayName("The reformat method correctly reformats an error log line")
4260
public void error_reformat() {
4361
assertThat(LogLevels.reformat("[ERROR]: Segmentation fault"))
4462
.isEqualTo("Segmentation fault (error)");
4563
}
4664

4765
@Test
66+
@Tag("task:3")
67+
@DisplayName("The reformat method correctly reformats a warning log line")
4868
public void warning_reformat() {
4969
assertThat(LogLevels.reformat("[WARNING]: Decreased performance"))
5070
.isEqualTo("Decreased performance (warning)");
5171
}
5272

5373
@Test
74+
@Tag("task:3")
75+
@DisplayName("The reformat method correctly reformats an info log line")
5476
public void info_reformat() {
5577
assertThat(LogLevels.reformat("[INFO]: Disk defragmented"))
5678
.isEqualTo("Disk defragmented (info)");
5779
}
5880

5981
@Test
82+
@Tag("task:3")
83+
@DisplayName("The reformat method correctly reformats an error log line removing spaces")
6084
public void reformat_with_leading_and_trailing_white_space() {
6185
assertThat(LogLevels.reformat("[ERROR]: \t Corrupt disk\t \t \r\n"))
6286
.isEqualTo("Corrupt disk (error)");

0 commit comments

Comments
 (0)