|
58 | 58 | import com.google.common.base.Function;
|
59 | 59 | import com.google.common.base.Strings;
|
60 | 60 | import java.io.File;
|
| 61 | +import java.io.FileNotFoundException; |
61 | 62 | import java.io.FileOutputStream;
|
62 | 63 | import java.io.IOException;
|
63 | 64 | import java.util.ArrayList;
|
@@ -475,6 +476,42 @@ public void writeThrowExprImports_messageExpr() {
|
475 | 476 | writerVisitor.write());
|
476 | 477 | }
|
477 | 478 |
|
| 479 | + @Test |
| 480 | + public void writeThrowExprImports_messageAndCauseExpr() { |
| 481 | + TypeNode npeType = TypeNode.withExceptionClazz(NullPointerException.class); |
| 482 | + Expr messageExpr = |
| 483 | + MethodInvocationExpr.builder() |
| 484 | + .setStaticReferenceType( |
| 485 | + TypeNode.withReference(ConcreteReference.withClazz(IfStatement.class))) |
| 486 | + .setMethodName("conditionExpr") |
| 487 | + .setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))) |
| 488 | + .build(); |
| 489 | + |
| 490 | + messageExpr = |
| 491 | + MethodInvocationExpr.builder() |
| 492 | + .setExprReferenceExpr(messageExpr) |
| 493 | + .setMethodName("foobar") |
| 494 | + .setReturnType(TypeNode.STRING) |
| 495 | + .build(); |
| 496 | + ThrowExpr throwExpr = |
| 497 | + ThrowExpr.builder() |
| 498 | + .setType(npeType) |
| 499 | + .setMessageExpr(messageExpr) |
| 500 | + .setCauseExpr( |
| 501 | + NewObjectExpr.builder() |
| 502 | + .setType(TypeNode.withExceptionClazz(FileNotFoundException.class)) |
| 503 | + .build()) |
| 504 | + .build(); |
| 505 | + |
| 506 | + throwExpr.accept(writerVisitor); |
| 507 | + assertEquals( |
| 508 | + LineFormatter.lines( |
| 509 | + "import com.google.api.generator.engine.ast.Expr;\n", |
| 510 | + "import com.google.api.generator.engine.ast.IfStatement;\n", |
| 511 | + "import java.io.FileNotFoundException;\n\n"), |
| 512 | + writerVisitor.write()); |
| 513 | + } |
| 514 | + |
478 | 515 | @Test
|
479 | 516 | public void writeInstanceofExprImports_basic() {
|
480 | 517 | TypeNode exprType = TypeNode.withReference(ConcreteReference.withClazz(Expr.class));
|
|
0 commit comments