#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:
Oliver Gierke
2017-04-21 08:01:43 +02:00
parent 605b22ed82
commit 856f662cf9
3 changed files with 75 additions and 0 deletions

View File

@@ -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");
}
}