ResourceInjector { static void emitHumanDescription(StringBuilder builder, List<FieldBinding> bindings) { switch (bindings.size()) { case 1: builder.append(bindings.get(0).getDescription()); break; case 2: builder.append(bindings.get(0).getDescription()) .append(" and ") .append(bindings.get(1).getDescription()); break; default: for (int i = 0, count = bindings.size(); i < count; i++) { FieldBinding requiredField = bindings.get(i); if (i != 0) { builder.append(", "); } if (i == count - 1) { builder.append("and "); } builder.append(requiredField.getDescription()); } break; } } ResourceInjector(String classPackage, String className, String targetClass);   }
@Test public void humanDescriptionJoinWorks() { FieldBinding one = new FieldBinding("one", new FakeTypeMirror()); FieldBinding two = new FieldBinding("two", new FakeTypeMirror()); FieldBinding three = new FieldBinding("three", new FakeTypeMirror()); StringBuilder builder1 = new StringBuilder(); emitHumanDescription(builder1, asList(one)); assertThat(builder1.toString()).isEqualTo("field 'one'"); StringBuilder builder2 = new StringBuilder(); emitHumanDescription(builder2, asList(one, two)); assertThat(builder2.toString()).isEqualTo("field 'one' and field 'two'"); StringBuilder builder3 = new StringBuilder(); emitHumanDescription(builder3, asList(one, two, three)); assertThat(builder3.toString()).isEqualTo("field 'one', field 'two', and field 'three'"); }