`void isInstantiatedWithNew() {new Stack<>();}` 中 new 运算符赋值给哪个变量? *(来自 JUnit 5 用户指南示例)*

Which variable is the result of new operator assigned to in `void isInstantiatedWithNew() {new Stack<>();}`? *(from a JUnit 5 User Guide example)*

JUnit 5 用户指南在 Nested Tests section 中包含一个示例: 特别地,它包含以下代码:

@DisplayName("A stack")
class TestingAStackDemo {

    Stack<Object> stack;

    @Test
    @DisplayName("is instantiated with new Stack()")
    void isInstantiatedWithNew() {
        new Stack<>();
    }

    @Nested
    @DisplayName("when new")
    class WhenNew { 

        @BeforeEach
        void createNewStack() {
            stack = new Stack<>();
        }

        @Test
        @DisplayName("is empty")
        void isEmpty() {
            assertTrue(stack.isEmpty());
        }...

我想知道,方法void isInstantiatedWithNew()中new运算符new Stack<>()的结果赋值给了哪个变量?

唯一的作业发生在

    @BeforeEach
    void createNewStack() {
        stack = new Stack<>();
    }

因此,只有嵌套class WhenNew(或嵌套在其中的classes)中的测试才能使用它。外部的任何测试都会看到一个具有 null 值的变量。

该代码的两个合理解释是:

打错了,本来是 stack = new Stack<>();,但这不是一个很合理的解释。

比较合理的一种是测试无参数构造函数不抛出异常。它适合测试的功能,甚至名称也暗示了它。

嵌套的 WhenNew 依赖于能够在 @BeforeEach 中创建 new Stack<>(),因此这验证了在尝试嵌套测试之前是否满足依赖关系。