* upgrade to spring boot 1.5.2 * add full update to REST API * modify ratings controller * upgrade herold * fix integration test * fix integration test * minor fix * fix integration test * fix integration test * minor cleanup * minor cleanup * remove log4j properties * use standard logbook.xml * remove log4j dependencies * remove commons-logging * merge * fix conflict * exclude commons-logging dependency * cleanup * minor fix * minor fix * fix dependency issues * Revert "fix dependency issues" This reverts commit 83bf1f9fd2e1a9a55f9cacb085669568b06b49ec. * fix dependency issues * minor fix * minor fix * minor fix * cleanup generated files * fix commons-logging issue * add parent to pom * cleanup parent dependencies * cleanup pom * cleanup pom * add missing parent * fix logging issue * fix test names
82 lines
2.2 KiB
Java
82 lines
2.2 KiB
Java
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());
|
|
}
|
|
}
|
|
}
|
|
}
|