CommonMethodsImpl implements CommonMethods { @Override public void appendType(DAType type) throws IOException { append(useQualifiedReference(type) ? type.getQualifiedName() : type.getSimpleName()); if (type.getExtendsBound() != null) { append(" extends "); appendType(type.getExtendsBound()); } else if (type.getSuperBound() != null) { append(" super "); appendType(type.getExtendsBound()); } appendTypeArgs(type.getTypeArgs()); if (type.isArray()) { append("[]"); } } CommonMethodsImpl(@Nonnull FileContext fileContext, int indentOffset); @Override FileContext getFileContext(); @Override int getIndentOffset(); @Override void appendIndent(); @Override void appendModifiers(@Nullable DAModifier[] modifiers); @Override void appendAnnotations(Collection<DAAnnotation> annotations); @Override void appendInlineAnnotations(Collection<DAAnnotation> annotations); @Override void appendType(DAType type); @Override void appendTypeArgs(List<DAType> typeArgs); @Override void newLine(); @Override void flush(); @Override void close(); @Override Writer append(CharSequence csq); @Override Writer append(CharSequence csq, int start, int end); @Override Writer append(char c);  }
@Test(dataProvider = "array_or_declared_DP") public void appendType_type_from_current_package_without_import_uses_simple_reference(DAType type) throws Exception { FileContextTestImpl fileContext = fileContext("com.acme", false, false); CommonMethods commonMethods = new CommonMethodsImpl(fileContext, 0); commonMethods.appendType(type); assertThat(fileContext.getRes()).isEqualTo(type.isArray() ? "Name[]" : "Name"); }
@Test(dataProvider = "array_or_declared_DP") public void appendType_type_from_current_package_with_import_uses_simple_reference(DAType type) throws Exception { FileContextTestImpl fileContext = fileContext("com.foo", true, false); CommonMethods commonMethods = new CommonMethodsImpl(fileContext, 0); commonMethods.appendType(type); assertThat(fileContext.getRes()).isEqualTo(type.isArray() ? "Name[]" : "Name"); }
@Test(dataProvider = "array_or_declared_DP", expectedExceptions = IllegalArgumentException.class) public void appendType_type_from_other_package_without_import_is_invalid(DAType type) throws Exception { FileContextTestImpl fileContext = fileContext("com.foo", false, false); CommonMethods commonMethods = new CommonMethodsImpl(fileContext, 0); commonMethods.appendType(type); }
@Test(dataProvider = "array_or_declared_DP") public void appendType_type_from_other_package_with_import_uses_simple_reference(DAType type) throws Exception { FileContextTestImpl fileContext = fileContext("com.foo", true, false); CommonMethods commonMethods = new CommonMethodsImpl(fileContext, 0); commonMethods.appendType(type); assertThat(fileContext.getRes()).isEqualTo(type.isArray() ? "Name[]" : "Name"); }
@Test(dataProvider = "array_or_declared_DP") public void appendType_type_from_other_package_without_import_but_with_homonymous_uses_qualified_reference( DAType type) throws Exception { FileContextTestImpl fileContext = fileContext("com.foo", false, true); CommonMethods commonMethods = new CommonMethodsImpl(fileContext, 0); commonMethods.appendType(type); assertThat(fileContext.getRes()).isEqualTo(type.isArray() ? "com.acme.Name[]" : "com.acme.Name"); }