From 12ffaab09687925b6fddf720dfd65facd63395f0 Mon Sep 17 00:00:00 2001 From: jwilson Date: Sun, 5 Jul 2015 10:20:55 -0400 Subject: [PATCH] Test conflicting simple names in the same file. See https://github.com/square/wire/issues/184 See https://github.com/square/javapoet/issues/298 --- .../com/squareup/javapoet/JavaFileTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/java/com/squareup/javapoet/JavaFileTest.java b/src/test/java/com/squareup/javapoet/JavaFileTest.java index 0f8eeb672..16e063db8 100644 --- a/src/test/java/com/squareup/javapoet/JavaFileTest.java +++ b/src/test/java/com/squareup/javapoet/JavaFileTest.java @@ -17,6 +17,7 @@ import java.util.Date; import javax.lang.model.element.Modifier; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -116,6 +117,43 @@ public final class JavaFileTest { + "}\n"); } + @Ignore("https://github.com/square/javapoet/issues/298") + @Test public void conflictingSimpleNames() throws Exception { + String source = JavaFile.builder("com.squareup.tacos", + TypeSpec.classBuilder("A") + .addType(TypeSpec.classBuilder("B") + .addType(TypeSpec.classBuilder("Twin").build()) + .addType(TypeSpec.classBuilder("C") + .addField(ClassName.get("com.squareup.tacos", "A", "Twin", "D"), "d") + .build()) + .build()) + .addType(TypeSpec.classBuilder("Twin") + .addType(TypeSpec.classBuilder("D") + .build()) + .build()) + .build()) + .build() + .toString(); + assertThat(source).isEqualTo("" + + "package com.squareup.tacos;\n" + + "\n" + + "class A {\n" + + " class B {\n" + + " class Twin {\n" + + " }\n" + + "\n" + + " class C {\n" + + " A.Twin.D d;\n" + + " }\n" + + " }\n" + + "\n" + + " class Twin {\n" + + " class D {\n" + + " }\n" + + " }\n" + + "}\n"); + } + @Test public void defaultPackage() throws Exception { String source = JavaFile.builder("", TypeSpec.classBuilder("HelloWorld")