DependencyMap { @SuppressWarnings("unchecked") <T, V extends T> void put( DependencyKey<T> key, V value, @Nullable DependencyValidator dependencyValidator) { if (mDependencies.containsKey(key)) { throw new RepeatedDependencyDefinedException(key); } mDependencies.put(key, new InstanceContainer(value, dependencyValidator)); } DependencyMap();   }
@Test(expected = RepeatedDependencyDefinedException.class) public void testCantOverwrite() { DependencyMap dependencyMap = new DependencyMap(); DependencyKey<TestClass> key = DependencyKey.of(TestClass.class); TestClass value1 = new TestClass(); TestClass value2 = new TestClass(); dependencyMap.put(key, value1, mPutValidator); dependencyMap.put(key, value2, mPutValidator); }