It's very easy to create a custom Repository implementation for testing purposes and to plug it in as the default repository. This example below creates a mock repository with a single mock participant to setup some specific configuration settings that might be needed for testing. The following class is all that is needed:
public class MockRepository implements Repository
{
class MockParticipant extends SingleObjectParticipant
{
public Object getObject()
{
Config config = new Config();
config.setParameter("key", "value");
return config;
}
}
private Map mParticipants = new HashMap();
public MockRepository()
{
mParticipants.put("ParticipantConfig", new MockParticipant());
}
public boolean hasParticipant(String name)
{
return mParticipants.containsKey(name);
}
public Participant getParticipant(String name)
{
return (Participant)mParticipants.get(name);
}
public Collection getParticipants(String name)
{
return mParticipants.values();
}
public Object getContext() { return null; }
public boolean isFinished() { return true; }
public void cleanup() {}
public Properties getProperties()
{
return System.getProperties();
}
}
Whenever you need to use this repository instead of the current default one, you just have to add this line of code:
Rep.setDefaultRepository(new MockRepository());
If you want to restore the previously active repository afterwards, you can retrieve it beforehand with
Rep.getDefaultRepository();
and set it back later.