ProviderContext implements IProviderContext { public ProviderContext() { providerMap = new HashMap<>(); } ProviderContext(); @SuppressWarnings("unchecked") @Override T getProvider(Class<T> clazz); @Override void registerProvider(Class<? extends IProvider> clazz, IProvider provider);  }
@Test public void testProviderContext() throws Exception { try { context.getProvider(mockInterface); fail("Should throw IllegalArgumentException for get un-registered provider."); } catch (IllegalArgumentException ex) { } try { context.registerProvider(mockInterface, null); fail("Should throw IllegalArgumentException for registering null."); } catch (IllegalArgumentException ex) { } try { context.registerProvider(null, mockProvider); fail("Should throw IllegalArgumentException for registering null type."); } catch (IllegalArgumentException ex) { } try { context.registerProvider(mockProvider.getClass(), mockProvider); fail("Should throw IllegalArgumentException for registering class type."); } catch (IllegalArgumentException ex) { } try { context.registerProvider(IMockProvider2.class, mockProvider); fail("Should throw IllegalArgumentException for registering un-compatible provider."); } catch (IllegalArgumentException ex) { } context.registerProvider(mockInterface, mockProvider); try { context.registerProvider(mockInterface, mockProvider); fail("Should throw IllegalArgumentException for duplicate registration."); } catch (IllegalArgumentException ex) { } assertEquals("Should get the registered provider", context.getProvider(mockInterface), mockProvider); assertEquals("Should get the registered provider", context.getProvider(mockInterface), mockProvider); }