@Test public void shouldCreateReadableUsage() { String samples = ConfigurationHelp.getSamples(); assertTrue("samples are not empty", !samples.isEmpty()); assertTrue("samples contains \"<?\"", samples.contains("<?")); assertTrue("samples contains \"user-defined\"", samples.contains("user-defined")); }
public static String getSamples() throws RuntimeException { Configuration conf = new Configuration(); Class<?> klass = conf.getClass(); StringBuilder b = new StringBuilder(); LinesBuilder h = new LinesBuilder(); b.append("Configuration examples:\n"); b.append("\n"); String sample = conf.getXMLRepresentationAsString(); b.append("<!-- Sample empty configuration.xml -->\n"); b.append(sample); b.append("\n"); List<Method> mthds = getSetters(klass); for (Method mthd : mthds) { conf = new Configuration(); Object defaultValue = getDefaultValue(klass, mthd, conf); conf = new Configuration(); Object sampleValue = getSampleValue(mthd, defaultValue); if (sampleValue == null) { continue; } try { mthd.invoke(conf, sampleValue); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("error setting sample value for " + mthd); } sample = conf.getXMLRepresentationAsString(); sample = sample.replaceFirst( "(?sx)^<\\?xml.*Configuration\\d*\">\\n", ""); sample = sample.replaceFirst("</object>\\n</java>", ""); h.clear(); h.append(XML_COMMENT_START); h.append("Sample for "); h.append(mthd.getName()); h.append(". Default is "); h.appendWords(defaultValue); h.appendWords(" -->"); h.appendLine(); b.append(h); b.append(sample); } return b.toString(); }
ConfigurationHelp { public static String getSamples() throws RuntimeException { Configuration conf = new Configuration(); Class<?> klass = conf.getClass(); StringBuilder b = new StringBuilder(); LinesBuilder h = new LinesBuilder(); b.append("Configuration examples:\n"); b.append("\n"); String sample = conf.getXMLRepresentationAsString(); b.append("<!-- Sample empty configuration.xml -->\n"); b.append(sample); b.append("\n"); List<Method> mthds = getSetters(klass); for (Method mthd : mthds) { conf = new Configuration(); Object defaultValue = getDefaultValue(klass, mthd, conf); conf = new Configuration(); Object sampleValue = getSampleValue(mthd, defaultValue); if (sampleValue == null) { continue; } try { mthd.invoke(conf, sampleValue); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("error setting sample value for " + mthd); } sample = conf.getXMLRepresentationAsString(); sample = sample.replaceFirst( "(?sx)^<\\?xml.*Configuration\\d*\">\\n", ""); sample = sample.replaceFirst("</object>\\n</java>", ""); h.clear(); h.append(XML_COMMENT_START); h.append("Sample for "); h.append(mthd.getName()); h.append(". Default is "); h.appendWords(defaultValue); h.appendWords(" -->"); h.appendLine(); b.append(h); b.append(sample); } return b.toString(); } }
ConfigurationHelp { public static String getSamples() throws RuntimeException { Configuration conf = new Configuration(); Class<?> klass = conf.getClass(); StringBuilder b = new StringBuilder(); LinesBuilder h = new LinesBuilder(); b.append("Configuration examples:\n"); b.append("\n"); String sample = conf.getXMLRepresentationAsString(); b.append("<!-- Sample empty configuration.xml -->\n"); b.append(sample); b.append("\n"); List<Method> mthds = getSetters(klass); for (Method mthd : mthds) { conf = new Configuration(); Object defaultValue = getDefaultValue(klass, mthd, conf); conf = new Configuration(); Object sampleValue = getSampleValue(mthd, defaultValue); if (sampleValue == null) { continue; } try { mthd.invoke(conf, sampleValue); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("error setting sample value for " + mthd); } sample = conf.getXMLRepresentationAsString(); sample = sample.replaceFirst( "(?sx)^<\\?xml.*Configuration\\d*\">\\n", ""); sample = sample.replaceFirst("</object>\\n</java>", ""); h.clear(); h.append(XML_COMMENT_START); h.append("Sample for "); h.append(mthd.getName()); h.append(". Default is "); h.appendWords(defaultValue); h.appendWords(" -->"); h.appendLine(); b.append(h); b.append(sample); } return b.toString(); } private  ConfigurationHelp(); }
ConfigurationHelp { public static String getSamples() throws RuntimeException { Configuration conf = new Configuration(); Class<?> klass = conf.getClass(); StringBuilder b = new StringBuilder(); LinesBuilder h = new LinesBuilder(); b.append("Configuration examples:\n"); b.append("\n"); String sample = conf.getXMLRepresentationAsString(); b.append("<!-- Sample empty configuration.xml -->\n"); b.append(sample); b.append("\n"); List<Method> mthds = getSetters(klass); for (Method mthd : mthds) { conf = new Configuration(); Object defaultValue = getDefaultValue(klass, mthd, conf); conf = new Configuration(); Object sampleValue = getSampleValue(mthd, defaultValue); if (sampleValue == null) { continue; } try { mthd.invoke(conf, sampleValue); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("error setting sample value for " + mthd); } sample = conf.getXMLRepresentationAsString(); sample = sample.replaceFirst( "(?sx)^<\\?xml.*Configuration\\d*\">\\n", ""); sample = sample.replaceFirst("</object>\\n</java>", ""); h.clear(); h.append(XML_COMMENT_START); h.append("Sample for "); h.append(mthd.getName()); h.append(". Default is "); h.appendWords(defaultValue); h.appendWords(" -->"); h.appendLine(); b.append(h); b.append(sample); } return b.toString(); } private  ConfigurationHelp(); static String getSamples(); }
ConfigurationHelp { public static String getSamples() throws RuntimeException { Configuration conf = new Configuration(); Class<?> klass = conf.getClass(); StringBuilder b = new StringBuilder(); LinesBuilder h = new LinesBuilder(); b.append("Configuration examples:\n"); b.append("\n"); String sample = conf.getXMLRepresentationAsString(); b.append("<!-- Sample empty configuration.xml -->\n"); b.append(sample); b.append("\n"); List<Method> mthds = getSetters(klass); for (Method mthd : mthds) { conf = new Configuration(); Object defaultValue = getDefaultValue(klass, mthd, conf); conf = new Configuration(); Object sampleValue = getSampleValue(mthd, defaultValue); if (sampleValue == null) { continue; } try { mthd.invoke(conf, sampleValue); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("error setting sample value for " + mthd); } sample = conf.getXMLRepresentationAsString(); sample = sample.replaceFirst( "(?sx)^<\\?xml.*Configuration\\d*\">\\n", ""); sample = sample.replaceFirst("</object>\\n</java>", ""); h.clear(); h.append(XML_COMMENT_START); h.append("Sample for "); h.append(mthd.getName()); h.append(". Default is "); h.appendWords(defaultValue); h.appendWords(" -->"); h.appendLine(); b.append(h); b.append(sample); } return b.toString(); } private  ConfigurationHelp(); static String getSamples();  }