In the mean time (yes I am a little bored right now and your problem
seems interesting :) )
This should create a new DB Instance for every test.
I don't know if this works but you could give it a try:
Also note the persistService.start and stop as well as the
UnitOfWork.begin and end method calls in @Before and @After
The @Before and @After methods (and the TemporaryFolder) could be moved
to a new TestRule which would be reusable for different test classes
@RunWith(JukitoRunner.class)
public class InjectionTest {
private static final String PERSISTENCE_UNIT_NAME = "votingTest";
private static final String TEST_DB_PROPS = "testDbProps";
public static class Module extends JukitoModule {
@Override
protected void configureTest() {
final Properties testDbProps = new Properties();
bind(VotingService.class).to(VotingServiceProducer.class).in(
TestSingleton.class);
bind(Properties.class).annotatedWith(Names.named(TEST_DB_PROPS)).toInstance(testDbProps);
final JpaPersistModule persistModule = new JpaPersistModule(PERSISTENCE_UNIT_NAME);
persistModule.properties(testDbProps);
install(persistModule);
}
}
@Rule
public TemporaryFolder tf = new TemporaryFolder();
@Before
public void createAndStartDB(PersistService perService, UnitOfWork unitOfWork, @Named(TEST_DB_PROPS) Properties testDbProps) throws IOException {
final File dbFile = tf.newFile();
testDbProps.clear();
testDbProps.setProperty("javax.persistence.jdbc.url", "jdbc:derby:" + dbFile + ";create=true");
perService.start();
unitOfWork.begin();
}
@After
public void tearDownDB(PersistService perService, UnitOfWork unitOfWork) {
unitOfWork.end();
perService.stop();