brianm/jdbi — pull request #14 by oschrenk (2011-12-30 16:17:35+00:00)
Title: Locate resources when using JUnit

I had some problems writing Unit tests when using the ClasspathStatementLocator

```
public interface AttributeDaoJdbi extends AttributeDao {

@Override
@SqlQuery("/sql/base/attribute/select-all")
@RegisterMapper(AttributeSetMapper.class)
public Set all();
```

When I ran the follwing test

```
@Test
public void test() {
final DBI dbi=new DBI(dataSource);
final Handle h=dbi.open();
h.attach(AttributeDaoJdbi.class);

final AttributeDaoJdbi dao=dbi.open(AttributeDaoJdbi.class);

final Set attributes=dao.all();

assertNotNull(attributes);
assertTrue(attributes.size()>0);

dao.close();
}
```

the statement locator wouldn't find the sql file `/src/main/resources/sql/base/attribute/select-all`. I'm not that familiar with the ClassLoader in Java but my guess is that the JUnit tests are run from a different thread, so that `Thread.currentThread().getContextClassLoader()` (which is used) fails to find the files via `loader.getResourceAsStream(name)` or `loader.getResourceAsStream(name +".sql")`

I added the attached code as a workaround. I don't really like it as it seems to correct behavior that no one uses in production code. But as I said I'm not an expert on ClassLoader issues. Maybe somebody else has knowledge input on this?