@Test public void testFormatChildMember() throws Exception { final int detailsNumber = 43; when(random.nextInt()).thenReturn(Integer.valueOf(detailsNumber)); final RecordStructureField childMember = mock(RecordStructureField.class); final String childFormatted = "i am the formatted child of a parent"; final String childName = "child_name"; when(childMember.getName()).thenReturn(childName); when(fieldFormatter.format(childMember)).thenReturn(childFormatted); final AbstractParentRecordStructureMember parent = mock(AbstractParentRecordStructureMember.class); final String parentName = "parent"; final String parentFormatted = "i am the formatted parent"; when(parent.getChildMember(0)).thenReturn(childMember); when(parent.getChildMemberCount()).thenReturn(Integer.valueOf(1)); when(parent.getName()).thenReturn(parentName); final StringWriter writer = mock(StringWriter.class); whenNew(StringWriter.class).withNoArguments().thenReturn(writer); when(writer.toString()).thenReturn(parentFormatted); final VelocityContext context = mock(VelocityContext.class); whenNew(VelocityContext.class).withNoArguments().thenReturn(context); assertThat(formatter.format(parent)).isEqualTo(parentFormatted + childFormatted); verify(context).put("member", parent); verify(context).put("detailsDivName", parentName + detailsNumber); verify(template).merge(context, writer); }
@Override public String format(final AbstractParentRecordStructureMember member) throws MavenReportException { final VelocityContext context = new VelocityContext(); context.put("member", member); context.put("detailsDivName", member.getName() + random.nextInt()); final StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to merge template.", e); } final StringBuilder listBuilder = new StringBuilder(writer.toString()); for (int i = 0, size = member.getChildMemberCount(); i < size; i++) { final RecordStructureMember childMember = member.getChildMember(i); if (childMember instanceof RecordStructureField) { listBuilder.append(fieldFormatter.format((RecordStructureField) childMember)); } else { listBuilder.append(format((AbstractParentRecordStructureMember) childMember)); } } return listBuilder.toString(); }
ParentalMemberFormatter implements MemberFormatter<AbstractParentRecordStructureMember> { @Override public String format(final AbstractParentRecordStructureMember member) throws MavenReportException { final VelocityContext context = new VelocityContext(); context.put("member", member); context.put("detailsDivName", member.getName() + random.nextInt()); final StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to merge template.", e); } final StringBuilder listBuilder = new StringBuilder(writer.toString()); for (int i = 0, size = member.getChildMemberCount(); i < size; i++) { final RecordStructureMember childMember = member.getChildMember(i); if (childMember instanceof RecordStructureField) { listBuilder.append(fieldFormatter.format((RecordStructureField) childMember)); } else { listBuilder.append(format((AbstractParentRecordStructureMember) childMember)); } } return listBuilder.toString(); } }
ParentalMemberFormatter implements MemberFormatter<AbstractParentRecordStructureMember> { @Override public String format(final AbstractParentRecordStructureMember member) throws MavenReportException { final VelocityContext context = new VelocityContext(); context.put("member", member); context.put("detailsDivName", member.getName() + random.nextInt()); final StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to merge template.", e); } final StringBuilder listBuilder = new StringBuilder(writer.toString()); for (int i = 0, size = member.getChildMemberCount(); i < size; i++) { final RecordStructureMember childMember = member.getChildMember(i); if (childMember instanceof RecordStructureField) { listBuilder.append(fieldFormatter.format((RecordStructureField) childMember)); } else { listBuilder.append(format((AbstractParentRecordStructureMember) childMember)); } } return listBuilder.toString(); } ParentalMemberFormatter(final VelocityEngine engine);  ParentalMemberFormatter(final FieldFormatter formatter, final Template template); }
ParentalMemberFormatter implements MemberFormatter<AbstractParentRecordStructureMember> { @Override public String format(final AbstractParentRecordStructureMember member) throws MavenReportException { final VelocityContext context = new VelocityContext(); context.put("member", member); context.put("detailsDivName", member.getName() + random.nextInt()); final StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to merge template.", e); } final StringBuilder listBuilder = new StringBuilder(writer.toString()); for (int i = 0, size = member.getChildMemberCount(); i < size; i++) { final RecordStructureMember childMember = member.getChildMember(i); if (childMember instanceof RecordStructureField) { listBuilder.append(fieldFormatter.format((RecordStructureField) childMember)); } else { listBuilder.append(format((AbstractParentRecordStructureMember) childMember)); } } return listBuilder.toString(); } ParentalMemberFormatter(final VelocityEngine engine);  ParentalMemberFormatter(final FieldFormatter formatter, final Template template); @Override String format(final AbstractParentRecordStructureMember member); }
ParentalMemberFormatter implements MemberFormatter<AbstractParentRecordStructureMember> { @Override public String format(final AbstractParentRecordStructureMember member) throws MavenReportException { final VelocityContext context = new VelocityContext(); context.put("member", member); context.put("detailsDivName", member.getName() + random.nextInt()); final StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (final Exception e) { throw new MavenReportException("Failed to merge template.", e); } final StringBuilder listBuilder = new StringBuilder(writer.toString()); for (int i = 0, size = member.getChildMemberCount(); i < size; i++) { final RecordStructureMember childMember = member.getChildMember(i); if (childMember instanceof RecordStructureField) { listBuilder.append(fieldFormatter.format((RecordStructureField) childMember)); } else { listBuilder.append(format((AbstractParentRecordStructureMember) childMember)); } } return listBuilder.toString(); } ParentalMemberFormatter(final VelocityEngine engine);  ParentalMemberFormatter(final FieldFormatter formatter, final Template template); @Override String format(final AbstractParentRecordStructureMember member);  }