[java] Add test case for #2738

This commit is contained in:
Andreas Dangel
2020-09-11 16:59:16 +02:00
parent fedea535b5
commit 2d0d098d2c

View File

@ -0,0 +1,21 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import org.junit.Assert;
import org.junit.Test;
public class ASTSwitchStatementTest extends BaseParserTest {
@Test
public void exhaustiveEnumSwitchWithDefault() {
ASTSwitchStatement switchStatement = getNodes(ASTSwitchStatement.class,
"import java.nio.file.AccessMode; class Foo { void bar(AccessMode m) {"
+ "switch (m) { case READ: break; default: break; } } }")
.get(0);
Assert.assertFalse(switchStatement.isExhaustiveEnumSwitch()); // this should not throw a NPE...
Assert.assertTrue(switchStatement.hasDefaultCase());
}
}