| 34 | interface Subtype extends Supertype {} |
| 35 | |
| 36 | @Test |
| 37 | public void castTo() { |
| 38 | TypeMirror subtype = type(Subtype.class); |
| 39 | TypeMirror supertype = type(Supertype.class); |
| 40 | Expression expression = Expression.create(subtype, "new $T() {}", subtype); |
| 41 | |
| 42 | Expression castTo = expression.castTo(supertype); |
| 43 | |
| 44 | assertThat(castTo.type()).isSameAs(supertype); |
| 45 | assertThat(castTo.codeBlock().toString()) |
| 46 | .isEqualTo( |
| 47 | "(dagger.internal.codegen.ExpressionTest.Supertype) " |
| 48 | + "new dagger.internal.codegen.ExpressionTest.Subtype() {}"); |
| 49 | } |
| 50 | |
| 51 | private TypeMirror type(Class<?> clazz) { |
| 52 | return compilationRule.getElements().getTypeElement(clazz.getCanonicalName()).asType(); |