@@ -0,0 +1,2519 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.jdbi.v3.sqlobject.locator;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Aimport java.util.List;%0A%0Aimport org.jdbi.v3.core.Jdbi;%0Aimport org.jdbi.v3.core.Something;%0Aimport org.jdbi.v3.core.config.JdbiConfig;%0Aimport org.jdbi.v3.core.rule.PgDatabaseRule;%0Aimport org.jdbi.v3.sqlobject.SqlObjectPlugin;%0Aimport org.jdbi.v3.sqlobject.SqlObjects;%0Aimport org.jdbi.v3.sqlobject.config.RegisterBeanMapper;%0Aimport org.jdbi.v3.sqlobject.statement.SqlQuery;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0A%0Apublic class TestSqlLocator %7B%0A  @Rule%0A  public PgDatabaseRule dbRule = new PgDatabaseRule().withPlugin(new SqlObjectPlugin());%0A%0A  @Test%0A  public void testLocateConfigDriven() %7B%0A    Jdbi jdbi = dbRule.getJdbi();%0A    jdbi.useHandle(h -%3E %7B%0A      h.execute(%22create table something (id int, name text)%22);%0A%0A      h.execute(%22insert into something (id, name) values (?, ?)%22, 2, %22Alice%22);%0A      h.execute(%22insert into something (id, name) values (?, ?)%22, 1, %22Bob%22);%0A    %7D);%0A%0A    jdbi.getConfig(SqlObjects.class).setSqlLocator(%0A        (type, method, config) -%3E config.get(TestConfig.class).sql);%0A%0A    jdbi.getConfig(TestConfig.class).sql = %22select * from something order by id%22;%0A    assertThat(jdbi.withExtension(TestDao.class, TestDao::list))%0A      .containsExactly(new Something(1, %22Bob%22), new Something(2, %22Alice%22));%0A%0A    jdbi.getConfig(TestConfig.class).sql = %22select * from something order by name%22;%0A    assertThat(jdbi.withExtension(TestDao.class, TestDao::list))%0A      .containsExactly(new Something(2, %22Alice%22), new Something(1, %22Bob%22));%0A  %7D%0A%0A  public static class TestConfig implements JdbiConfig%3CTestConfig%3E %7B%0A    String sql;%0A%0A    public TestConfig() %7B%7D%0A%0A    private TestConfig(TestConfig that) %7B%0A      this.sql = that.sql;%0A    %7D%0A%0A    @Override%0A    public TestConfig createCopy() %7B%0A      return new TestConfig(this);%0A    %7D%0A  %7D%0A%0A  @RegisterBeanMapper(Something.class)%0A  public interface TestDao %7B%0A    @SqlQuery%0A    List%3CSomething%3E list();%0A  %7D%0A%0A%7D%0A

Add test for SQL Locator using config registry