IndexBuilder { public <T> JdbcIndex<T> buildIndex(Class<T> model) { JdbcIndex<T> index = new JdbcIndex<>(); index.setModelClass(model); index.setName(indexNameTranslator.translate(model)); index.setFields(buildFields(index)); return index; } IndexBuilder(ClassNameTranslator indexNameTranslator); JdbcIndex<T> buildIndex(Class<T> model); String[] getExcludedProperties(); ClassNameTranslator getIndexNameTranslator(); void setIndexNameTranslator(ClassNameTranslator indexNameTranslator); static final String[] EXCLUDED_PROPERTIES; }
@Test public void buildIndex_works() throws Exception { JdbcIndex<TestModel> index = builder.buildIndex(TestModel.class); assertEquals(TestModel.class.getCanonicalName(), index.getName()); assertEquals(3, index.getFields().size()); IndexField[] fields = index.getFields().toArray(new IndexField[3]); Arrays.sort(fields, new Comparator<IndexField>() { @Override public int compare(IndexField o1, IndexField o2) { return o1.getName().compareTo(o2.getName()); } }); assertEquals("subModel", fields[0].getName()); assertEquals(SubTestModel.class, fields[0].getType()); assertEquals("testId", fields[1].getName()); assertEquals(String.class, fields[1].getType()); assertEquals("testInteger", fields[2].getName()); assertEquals(Integer.class, fields[2].getType()); }