StringFieldFactory extends AbstractFieldFactory<String> { @Override public String newInstance(int uniqueId) { StringBuilder buffer = new StringBuilder(); long tokenPointer = uniqueId * tokensPerField; int id = (int) tokenPointer % tokens.length; buffer.append(tokens[id]); for(int i = 1; i < tokensPerField; i++) { int index = (id + i) % tokens.length; buffer.append(StringUtils.SPACE).append(tokens[index]); } return buffer.toString(); } StringFieldFactory(int numOfTokens, String... tokens);  StringFieldFactory(int numOfTokens, Collection<String> tokens); @Override String newInstance(int uniqueId);  }
@Test public void newInstanceCase01() { StringFieldFactory factory = new StringFieldFactory(3, A_F); assertEquals(factory.newInstance(0), "A B C"); assertEquals(factory.newInstance(1), "D E F"); assertEquals(factory.newInstance(2), "A B C"); assertEquals(factory.newInstance(3), "D E F"); }
@Test public void newInstanceCase02() { StringFieldFactory factory = new StringFieldFactory(4, A_F); assertEquals(factory.newInstance(0), "A B C D"); assertEquals(factory.newInstance(1), "E F A B"); assertEquals(factory.newInstance(2), "C D E F"); assertEquals(factory.newInstance(3), "A B C D"); }
@Test public void newInstanceCase03() { StringFieldFactory factory = new StringFieldFactory(3, A_D); assertEquals(factory.newInstance(0), "A B C"); assertEquals(factory.newInstance(1), "D A B"); assertEquals(factory.newInstance(2), "C D A"); assertEquals(factory.newInstance(3), "B C D"); assertEquals(factory.newInstance(4), "A B C"); }