-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
Copy pathExerciseIntroductionTest.java
51 lines (42 loc) · 1.78 KB
/
ExerciseIntroductionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.bobocode.intro;
import lombok.SneakyThrows;
import org.junit.jupiter.api.*;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/**
* This is a {@link ExerciseIntroductionTest} that is meant to verify if you properly implement {@link ExerciseIntroduction}.
* It is a simple example that shows how each exercise is organized: todo section + tests.
* <p>
* A typical Java test uses JUnit framework to run the test, and may also use some other frameworks for assertions.
* In our exercises we use JUnit 5 + AssertJ
* <p>
* PLEASE NOTE:
* - annotation @{@link Order} is used to help you to understand which method should be implemented first.
* - annotation @{@link DisplayName} is used to provide you more detailed instructions.
*
* @author Taras Boychuk
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class ExerciseIntroductionTest {
private ExerciseIntroduction exerciseIntroduction = new ExerciseIntroduction();
private String EXPECTED_MESSAGE = "The key to efficient learning is practice!";
@Test
@Order(1)
@DisplayName("getWelcomeMessage method returns correct phrase")
void getWelcomeMessage() {
String message = exerciseIntroduction.getWelcomeMessage();
assertThat(message).isEqualTo(EXPECTED_MESSAGE);
}
@Test
@Order(2)
@DisplayName("encodeMessage returns correct encoded message")
@SneakyThrows
void encodeMessageReturnsCorrectPhrase() {
var encodeMessageMethod = Arrays.stream(ExerciseIntroduction.class.getDeclaredMethods())
.filter(method -> method.getName().equals("encodeMessage"))
.findAny()
.orElseThrow();
var encodedMessage = encodeMessageMethod.invoke(new ExerciseIntroduction(), EXPECTED_MESSAGE);
assertThat(encodedMessage).isEqualTo("VGhlIGtleSB0byBlZmZpY2llbnQgbGVhcm5pbmcgaXMgcHJhY3RpY2Uh");
}
}