gpt4 book ai didi

java - 为什么有时在 Maven 中测试期间 public static AtomicBoolean 变量为 false?

转载 作者:行者123 更新时间:2023-11-28 21:23:43 25 4
gpt4 key购买 nike

为什么在 Maven 中测试时 public static AtomicBoolean 变量有时为 false?

也许,粗鲁的并发错误?

但在 Intellij 中工作正常。

public class MaintenanceFilterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private MaintenanceFilter target;

@Before
public void setUp() throws Exception {
target = new MaintenanceFilter();
MaintenanceFilter.isMaintenanceStarted.set(false);
}

@Test
public void doFilterException() throws Exception {
MaintenanceFilter.isMaintenanceStarted.set(true);
expectedException.expect(MaintenanceException.class);
expectedException.expectMessage
("Redeployment of application or restart of server is in progress.");

target.doFilter(null, null, null);
}

public static class MaintenanceFilter implements Filter {
public static final AtomicBoolean isMaintenanceStarted = new AtomicBoolean();

@Override
public void doFilter(
ServletRequest input,
ServletResponse output,
FilterChain chain
) throws IOException,
ServletException {
if (isMaintenanceStarted.get()) {
throw new MaintenanceException
("Redeployment of application or restart of server is in progress.");
}
}//..
}
}

最佳答案

没有注意到

                <parallel>methods</parallel>

在我的 maven-surefire-plugin 中。

关于java - 为什么有时在 Maven 中测试期间 public static AtomicBoolean 变量为 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com