@Test public void testFormat() throws Exception { final VelocityContext context = mock(VelocityContext.class); whenNew(VelocityContext.class).withNoArguments().thenReturn(context); final StringWriter writer = mock(StringWriter.class); final String formatted = "i am the formatted text"; when(writer.toString()).thenReturn(formatted); whenNew(StringWriter.class).withNoArguments().thenReturn(writer); final int detailsNumber = 7483; when(random.nextInt()).thenReturn(Integer.valueOf(detailsNumber)); final RecordStructureField member = mock(RecordStructureField.class); final String memberName = "member_name"; when(member.getName()).thenReturn(memberName); assertThat(formatter.format(member)).isEqualTo(formatted); verify(context).put("member", member); verify(context).put("detailsDivName", memberName + detailsNumber); verify(template).merge(context, writer); }
@Override public String format(final RecordStructureField 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 for member " + member.getName(), e); } return writer.toString(); }
FieldFormatter implements MemberFormatter<RecordStructureField> { @Override public String format(final RecordStructureField 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 for member " + member.getName(), e); } return writer.toString(); } }
FieldFormatter implements MemberFormatter<RecordStructureField> { @Override public String format(final RecordStructureField 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 for member " + member.getName(), e); } return writer.toString(); } FieldFormatter(final VelocityEngine engine); }
FieldFormatter implements MemberFormatter<RecordStructureField> { @Override public String format(final RecordStructureField 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 for member " + member.getName(), e); } return writer.toString(); } FieldFormatter(final VelocityEngine engine); @Override String format(final RecordStructureField member); }
FieldFormatter implements MemberFormatter<RecordStructureField> { @Override public String format(final RecordStructureField 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 for member " + member.getName(), e); } return writer.toString(); } FieldFormatter(final VelocityEngine engine); @Override String format(final RecordStructureField member);  }