#41 - Added PluginRegistry.getRequiredPlugin(…).
Added aforementioned method for clients to look up a required plugin with the registry throwing a default exception if none is found. An overload taking a Supplier<String> is available to customize the exception message if needed.
This commit is contained in:
@@ -25,7 +25,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Unit test for {@link SimplePluginRegistry}.
|
||||
@@ -38,6 +40,8 @@ public class SimplePluginRegistryUnitTest {
|
||||
|
||||
SimplePluginRegistry<SamplePlugin, String> registry;
|
||||
|
||||
public @Rule ExpectedException o_O = ExpectedException.none();
|
||||
|
||||
/**
|
||||
* Initializes a {@code PluginRegistry} and equips it with an {@code EmailNotificationProvider}.
|
||||
*/
|
||||
@@ -142,4 +146,29 @@ public class SimplePluginRegistryUnitTest {
|
||||
|
||||
registry.getPluginFor("FOO", () -> new IllegalStateException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #41
|
||||
*/
|
||||
public void throwsExceptionIfRequiredPluginIsNotFound() {
|
||||
|
||||
registry = SimplePluginRegistry.create(Collections.emptyList());
|
||||
|
||||
o_O.expect(IllegalArgumentException.class);
|
||||
|
||||
registry.getRequiredPluginFor("FOO");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #41
|
||||
*/
|
||||
public void throwsExceptionWithMessafeIfRequiredPluginIsNotFound() {
|
||||
|
||||
registry = SimplePluginRegistry.create(Collections.emptyList());
|
||||
|
||||
o_O.expect(IllegalArgumentException.class);
|
||||
o_O.expectMessage("message");
|
||||
|
||||
registry.getRequiredPluginFor("FOO", () -> "message");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user