use of com.google.api.generator.engine.ast.TryCatchStatement in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeTryCatchStatement_withResources.
@Test
public void writeTryCatchStatement_withResources() {
Reference exceptionReference = ConcreteReference.withClazz(IllegalArgumentException.class);
TypeNode type = TypeNode.withReference(exceptionReference);
VariableExpr variableExpr = VariableExpr.builder().setVariable(createVariable("e", type)).setIsDecl(true).build();
TryCatchStatement tryCatch = TryCatchStatement.builder().setTryResourceExpr(createAssignmentExpr("aBool", "false", TypeNode.BOOLEAN)).setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("y", "4", TypeNode.INT)))).addCatch(variableExpr, Arrays.asList(ExprStatement.withExpr(createAssignmentExpr("foobar", "123", TypeNode.INT)))).build();
tryCatch.accept(writerVisitor);
assertEquals(String.format("%s%s%s%s%s", "try (boolean aBool = false) {\n", "int y = 4;\n", "} catch (IllegalArgumentException e) {\n", "int foobar = 123;\n", "}\n"), writerVisitor.write());
}
Aggregations