/
AssertionTests.java
51 lines (41 loc) · 1.52 KB
/
AssertionTests.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 edu.psu.swe.testing.junit5.presentation.tests;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import edu.psu.swe.testing.junit5.presentation.supportingcode.SampleStudents;
import edu.psu.swe.testing.junit5.presentation.supportingcode.affiliates.models.Student;
@DisplayName("Simple Assertion Tests ☺♫")
public class AssertionTests {
@Test
@DisplayName("assertEquals test")
void checkStudentLastName() {
assertEquals("Builder", SampleStudents.getFullTimeStudent().getLastName(), "not Bob");
}
@Test
@DisplayName("assertTrue test")
void checkStudentFirstName() {
assertTrue("Bob".equals(SampleStudents.getFullTimeStudent().getFirstName()));
}
@Test
@DisplayName("assertTrue test - with λ")
void checkforCourses() {
Student newStudent = SampleStudents.getNewFreshman();
assertTrue(newStudent.getCourses().size() == 0,
() -> "new student has " + newStudent.getCourses().size()+ " courses.");
}
/*
* all assertions are evaluated even if one fails in the middle
*/
@Test
@DisplayName("grouped test")
void groupedAssertion() {
Student newStudent = SampleStudents.getNewFreshman();
assertAll("newStudent",
()-> assertEquals(0, newStudent.getCourses().size()),
() -> assertEquals("John", newStudent.getFirstName()),
() -> assertEquals("Blutarsky", newStudent.getLastName())
);
}
}