Now I get an error at the next statement: java.lang.IllegalStateException: Repository already exists

Can you use new TestRepository(Repository repository) instead? You have created an instance of FileRepository before.