use of com.github.javaparser.ast.type.UnionType in project javaparser by javaparser.
the class Java7ValidatorTest method multiCatchWithoutElements.
@Test
public void multiCatchWithoutElements() {
UnionType unionType = new UnionType();
List<Problem> problems = new ArrayList<>();
new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
assertProblems(problems, "UnionType.elements can not be empty.");
}
use of com.github.javaparser.ast.type.UnionType in project javaparser by javaparser.
the class Java7ValidatorTest method multiCatchWithOneElement.
@Test
public void multiCatchWithOneElement() {
UnionType unionType = new UnionType();
unionType.getElements().add(new ClassOrInterfaceType());
List<Problem> problems = new ArrayList<>();
new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
assertProblems(problems, "Union type (multi catch) must have at least two elements.");
}
use of com.github.javaparser.ast.type.UnionType in project javaparser by javaparser.
the class LexicalPreservingPrinterTest method printUnionType.
@Test
public void printUnionType() {
String code = "class A {{try { doit(); } catch (Exception | AssertionError e) {}}}";
considerCode(code);
InitializerDeclaration initializerDeclaration = (InitializerDeclaration) cu.getType(0).getMembers().get(0);
TryStmt tryStmt = (TryStmt) initializerDeclaration.getBody().getStatements().get(0);
CatchClause catchClause = tryStmt.getCatchClauses().get(0);
UnionType unionType = (UnionType) catchClause.getParameter().getType();
assertEquals("Exception | AssertionError", LexicalPreservingPrinter.print(unionType));
}
Aggregations