Group testing modules (#3014)
* move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict
This commit is contained in:
committed by
GitHub
parent
b383d83bf4
commit
776a01429e
@@ -0,0 +1,81 @@
|
||||
package com.baeldung;
|
||||
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class NestedUnitTest {
|
||||
Stack<Object> stack;
|
||||
boolean isRun = false;
|
||||
|
||||
@Test
|
||||
@DisplayName("is instantiated with new Stack()")
|
||||
void isInstantiatedWithNew() {
|
||||
new Stack<Object>();
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("when new")
|
||||
class WhenNew {
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
stack = new Stack<Object>();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("is empty")
|
||||
void isEmpty() {
|
||||
Assertions.assertTrue(stack.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("throws EmptyStackException when popped")
|
||||
void throwsExceptionWhenPopped() {
|
||||
Assertions.assertThrows(EmptyStackException.class, () -> stack.pop());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("throws EmptyStackException when peeked")
|
||||
void throwsExceptionWhenPeeked() {
|
||||
Assertions.assertThrows(EmptyStackException.class, () -> stack.peek());
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("after pushing an element")
|
||||
class AfterPushing {
|
||||
|
||||
String anElement = "an element";
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
stack.push(anElement);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("it is no longer empty")
|
||||
void isEmpty() {
|
||||
Assertions.assertFalse(stack.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("returns the element when popped and is empty")
|
||||
void returnElementWhenPopped() {
|
||||
Assertions.assertEquals(anElement, stack.pop());
|
||||
Assertions.assertTrue(stack.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("returns the element when peeked but remains not empty")
|
||||
void returnElementWhenPeeked() {
|
||||
Assertions.assertEquals(anElement, stack.peek());
|
||||
Assertions.assertFalse(stack.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user