Skip to content

Commit b073255

Browse files
authored
Merge pull request eugenp#3976 from asturcon/beforeAfterAnnotationsJunit
BAEL-1662 Before after annotations junit
2 parents 20307a7 + 6b0a022 commit b073255

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

‎testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsTest.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.assertEquals;
44

55
import java.util.ArrayList;
6+
import java.util.Arrays;
67
import java.util.List;
78

89
import org.junit.After;
@@ -23,29 +24,25 @@ public class BeforeAndAfterAnnotationsTest {
2324
@Before
2425
public void init() {
2526
LOG.info("startup");
26-
27-
list = new ArrayList<>();
28-
list.add("test1");
29-
list.add("test2");
27+
list = new ArrayList<>(Arrays.asList("test1", "test2"));
3028
}
3129

3230
@After
3331
public void finalize() {
3432
LOG.info("finalize");
35-
3633
list.clear();
3734
}
3835

3936
@Test
40-
public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() {
37+
public void whenCheckingListSize_ThenSizeEqualsToInit() {
4138
LOG.info("executing test");
4239
assertEquals(2, list.size());
4340

4441
list.add("another test");
4542
}
4643

4744
@Test
48-
public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() {
45+
public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() {
4946
LOG.info("executing another test");
5047
assertEquals(2, list.size());
5148

‎testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsTest.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.assertEquals;
44

55
import java.util.ArrayList;
6+
import java.util.Arrays;
67
import java.util.List;
78

89
import org.junit.jupiter.api.AfterEach;
@@ -23,29 +24,25 @@ public class BeforeEachAndAfterEachAnnotationsTest {
2324
@BeforeEach
2425
public void init() {
2526
LOG.info("startup");
26-
27-
list = new ArrayList<>();
28-
list.add("test1");
29-
list.add("test2");
27+
list = new ArrayList<>(Arrays.asList("test1", "test2"));
3028
}
3129

3230
@AfterEach
3331
public void finalize() {
3432
LOG.info("finalize");
35-
3633
list.clear();
3734
}
3835

3936
@Test
40-
public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() {
37+
public void whenCheckingListSize_ThenSizeEqualsToInit() {
4138
LOG.info("executing test");
4239
assertEquals(2, list.size());
4340

4441
list.add("another test");
4542
}
4643

4744
@Test
48-
public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() {
45+
public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() {
4946
LOG.info("executing another test");
5047
assertEquals(2, list.size());
5148

0 commit comments

Comments
 (0)