### Question:
AuroraTableNameServiceImpl implements AuroraTableNameService<T> { @Override public Try<TableName> resolveTableNameByHint(T hint) { Validate.notNull(hint); TableName tableName = tableNameResolver.apply(hint); if (tableNames != null && !containsInTableNames(tableName)) { return Try.ofFailure(new IllegalArgumentException(String.format("hint(%s) is not found.", hint))); } else { return Try.ofSuccess(tableName); } } AuroraTableNameServiceImpl(TableNameResolver<T> tableNameResolver, File configFile);   AuroraTableNameServiceImpl(TableNameResolver<T> tableNameResolver, Config config);   AuroraTableNameServiceImpl(TableNameResolver<T> tableNameResolver, Set<TableName> tableNames);   AuroraTableNameServiceImpl(TableNameResolver<T> tableNameResolver); @Override Try<TableName> resolveTableNameByHint(T hint);  }### Answer:
@Test public void test_バリデーションなし() { AuroraTableNameService<Integer> atns = AuroraTableNameServiceFactory.create(new AbstractTableNameResolver<Integer>("user") { @Override protected String getSuffixName(Integer hint) { return Integer.toString(hint % 2); } }); TableName tableName1 = atns.resolveTableNameByHint(0).get(); assertThat(tableName1.getName(), is("user0")); TableName tableName2 = atns.resolveTableNameByHint(1).get(); assertThat(tableName2.getName(), is("user1")); TableName tableName3 = atns.resolveTableNameByHint(2).get(); assertThat(tableName3.getName(), is("user0")); }
@Test public void test_バリデーションあり_正規表現なし() { HashSet<TableName> tableNames = new HashSet<>(); tableNames.add(TableNameFactory.create("user0", false)); tableNames.add(TableNameFactory.create("user1", false)); AuroraTableNameService<Integer> atns = AuroraTableNameServiceFactory.create(new AbstractTableNameResolver<Integer>("user") { @Override protected String getSuffixName(Integer hint) { return Integer.toString(hint % 2); } }, tableNames); TableName tableName1 = atns.resolveTableNameByHint(0).get(); assertThat(tableName1.getName(), is("user0")); TableName tableName2 = atns.resolveTableNameByHint(1).get(); assertThat(tableName2.getName(), is("user1")); TableName tableName3 = atns.resolveTableNameByHint(2).get(); assertThat(tableName3.getName(), is("user0")); }
@Test public void test_バリデーションあり_正規表現あり() { HashSet<TableName> tableNames = new HashSet<>(); tableNames.add(TableNameFactory.create("user[0-1]", true)); AuroraTableNameService<Integer> atns = AuroraTableNameServiceFactory.create(new AbstractTableNameResolver<Integer>("user") { @Override protected String getSuffixName(Integer hint) { return Integer.toString(hint % 2); } }, tableNames); TableName tableName1 = atns.resolveTableNameByHint(0).get(); assertThat(tableName1.getName(), is("user0")); TableName tableName2 = atns.resolveTableNameByHint(1).get(); assertThat(tableName2.getName(), is("user1")); TableName tableName3 = atns.resolveTableNameByHint(2).get(); assertThat(tableName3.getName(), is("user0")); }
@Test public void test_設定ファイル() { AuroraTableNameService<Integer> atns = AuroraTableNameServiceFactory.create(new AbstractTableNameResolver<Integer>("user") { @Override protected String getSuffixName(Integer hint) { return Integer.toString(hint % 2); } }, new File("./conf/application.conf")); TableName tableName1 = atns.resolveTableNameByHint(0).get(); assertThat(tableName1.getName(), is("user0")); TableName tableName2 = atns.resolveTableNameByHint(1).get(); assertThat(tableName2.getName(), is("user1")); TableName tableName3 = atns.resolveTableNameByHint(2).get(); assertThat(tableName3.getName(), is("user0")); }