Merge pull request #3976 from asturcon/beforeAfterAnnotationsJunit

BAEL-1662 Before after annotations junit
This commit is contained in:
Tom Hombergs 2018-04-15 20:17:23 +02:00 committed by GitHub
commit b073255b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package com.baeldung.migration.junit4;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.After;
@ -23,21 +24,17 @@ public class BeforeAndAfterAnnotationsTest {
@Before
public void init() {
LOG.info("startup");
list = new ArrayList<>();
list.add("test1");
list.add("test2");
list = new ArrayList<>(Arrays.asList("test1", "test2"));
}
@After
public void finalize() {
LOG.info("finalize");
list.clear();
}
@Test
public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() {
public void whenCheckingListSize_ThenSizeEqualsToInit() {
LOG.info("executing test");
assertEquals(2, list.size());
@ -45,7 +42,7 @@ public class BeforeAndAfterAnnotationsTest {
}
@Test
public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() {
public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() {
LOG.info("executing another test");
assertEquals(2, list.size());

View File

@ -3,6 +3,7 @@ package com.baeldung.migration.junit5;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
@ -23,21 +24,17 @@ public class BeforeEachAndAfterEachAnnotationsTest {
@BeforeEach
public void init() {
LOG.info("startup");
list = new ArrayList<>();
list.add("test1");
list.add("test2");
list = new ArrayList<>(Arrays.asList("test1", "test2"));
}
@AfterEach
public void finalize() {
LOG.info("finalize");
list.clear();
}
@Test
public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() {
public void whenCheckingListSize_ThenSizeEqualsToInit() {
LOG.info("executing test");
assertEquals(2, list.size());
@ -45,7 +42,7 @@ public class BeforeEachAndAfterEachAnnotationsTest {
}
@Test
public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() {
public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() {
LOG.info("executing another test");
assertEquals(2, list.size());