Junit 当实际方法更改值时,Assert null不起作用

Junit 当实际方法更改值时,Assert null不起作用,junit,Junit,我试图为一段代码编写一个Junit,用于将值断言为null。但实际调用的值正在变化 主类代码 我想为catch块编写测试。所以尝试在下面编写测试用例 @Test public void testapplyConfigUpdate() throws GlobalTableException { exception.expect(ServiceNotAvailableException.class); globalTableRetriever.set

我试图为一段代码编写一个Junit,用于将值断言为null。但实际调用的值正在变化

主类代码 我想为catch块编写测试。所以尝试在下面编写测试用例

 @Test
    public void testapplyConfigUpdate() throws GlobalTableException
    {
        exception.expect(ServiceNotAvailableException.class);
        globalTableRetriever.set(null);
        tableFetcher = globalTableRetriever.get();
        assertThat(tableFetcher).isNull();
        myTableHandler.activate(myOsgiComponentContext);
        verify(myCounterRegistratorService, times(1)).incrementCounter(any(CounterInstance.class));
    }

但一旦进入GetGlobalTableRetriever方法,断言空值将更改为原始值。

为什么还要断言它

        exception.expect(ServiceNotAvailableException.class);
已经暗示tableFetcher为空

试试这个:

@Test
public void testapplyConfigUpdate() throws GlobalTableException
{
    exception.expect(ServiceNotAvailableException.class);
    globalTableRetriever.set(null);
    tableFetcher = globalTableRetriever.get();
}
@Test
public void testapplyConfigUpdate() throws GlobalTableException
{
    exception.expect(ServiceNotAvailableException.class);
    globalTableRetriever.set(null);
    tableFetcher = globalTableRetriever.get();
}