Вы можете создать реализацию интерфейса Props
на основе Properties
:
private static class MockProps implements Props {
private Properties properties = new Properties();
MockProps addProperty( String key, String value ) {
properties.setProperty( key, value );
return this;
}
@Override
public boolean contains( String key ) {
return properties.containsKey( key );
}
@Override
public String get( String key ) {
return properties.getProperty( key );
}
@Override
public String get( String key, Filter filter ) {
throw new UnsupportedOperationException( "not needed by mock" );
}
@Override
public String[] getArray( String key ) {
throw new UnsupportedOperationException( "not needed by mock" );
}
@Override
public String[] getArray( String key, Filter filter ) {
throw new UnsupportedOperationException( "not needed by mock" );
}
@Override
public Properties getProperties() {
return properties;
}
@Override
public Properties getProperties( String prefix, boolean removePrefix ) {
return PropertiesUtil.getProperties( properties, prefix, removePrefix );
}
}
Затем использовать @BeforeClass
для его настройки:
@BeforeClass
public static void init() {
PropsUtil.setProps( new MockProps()
.addProperty( "key1", "silly" )
.addProperty( "key2", "silly again" ) );
}