mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 15:52:06 +01:00
Add INSTANCE shortcut to SmackTestUtil
This commit is contained in:
parent
3ee4dd7b3a
commit
cf48f12565
1 changed files with 11 additions and 2 deletions
|
@ -125,10 +125,19 @@ public class SmackTestUtil {
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private static <E extends Element, P extends Provider<E>> P providerClassToProvider(Class<P> providerClass) {
|
private static <E extends Element, P extends Provider<E>> P providerClassToProvider(Class<P> providerClass) {
|
||||||
P provider;
|
P provider;
|
||||||
// TODO: Consider adding a shortcut in case there is a static INSTANCE field holding an instance of the
|
|
||||||
// requested provider.
|
try {
|
||||||
|
provider = (P) providerClass.getDeclaredField("INSTANCE").get(null);
|
||||||
|
return provider;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// Continue with the next approach.
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider = providerClass.getDeclaredConstructor().newInstance();
|
provider = providerClass.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue