#19 - Exceptions on plugin lookup can now be submitted lazily.

Introduced overloads on PluginRegistry which instead of taking an exception instance immediately (which requires instance creation beforehand) now accept a Supplier<E> so that the exception creation can actually be delayed until it's really needed.

Deprecated the old methods taking exception instances directly.
This commit is contained in:
Oliver Gierke
2016-01-28 10:24:15 +01:00
parent 46d36ec85d
commit ad017e83cd
3 changed files with 95 additions and 10 deletions

View File

@@ -21,10 +21,12 @@ import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.plugin.core.PluginRegistry.Supplier;
/**
* Unit test for {@link SimplePluginRegistry}.
@@ -130,4 +132,21 @@ public class SimplePluginRegistryUnitTest {
assertThat(registry.countPlugins(), is(0));
}
/**
* @see #19
*/
@Test(expected = IllegalStateException.class)
public void testname() throws Exception {
registry = SimplePluginRegistry.create(Collections.<SamplePlugin> emptyList());
registry.getPluginFor("FOO", new Supplier<Exception>() {
@Override
public Exception get() {
return new IllegalStateException();
}
});
}
}