### Question:
TypeChecker { public T check(Object object) throws ClassCastException { return clazz.cast(object); } protected  TypeChecker(Class<T> clazz); @SuppressWarnings ("unchecked") // Conversion from TypeChecker<SpecificType> to TypeChecker<T> can only be unchecked. Type checking is done with clazz == SpecificType.class beforehand. static TypeChecker<T> tSimple(Class<T> type); static TypeChecker<Collection<? extends T>> tCollection(Class<? extends T> elementType); static TypeChecker<Collection<? extends T>> tCollection(TypeChecker<? extends T> elementChecker); static TypeChecker<List<? extends T>> tList(Class<? extends T> elementType); static TypeChecker<List<? extends T>> tList(TypeChecker<? extends T> elementChecker); static TypeChecker<Set<? extends T>> tSet(Class<? extends T> elementType); static TypeChecker<Set<? extends T>> tSet(TypeChecker<? extends T> elementChecker); static TypeChecker<Queue<? extends T>> tQueue(Class<? extends T> elementType); static TypeChecker<Queue<? extends T>> tQueue(TypeChecker<? extends T> elementChecker); static TypeChecker<Map<? extends K, ? extends V>> tMap(Class<? extends K> keyType, Class<? extends V> valueType); static TypeChecker<Map<? extends K, ? extends V>> tMap(Class<? extends K> keyType, TypeChecker<? extends V> valueChecker); static TypeChecker<Map<? extends K, ? extends V>> tMap(TypeChecker<? extends K> keyChecker, Class<? extends V> valueType); static TypeChecker<Map<? extends K, ? extends V>> tMap(TypeChecker<? extends K> keyChecker, TypeChecker<? extends V> valueChecker); T check(Object object); final T check(Object object, T defaultValue); final T checkTag(Tag<?> tag); final T checkTag(Tag<?> tag, T defaultValue);  }### Answer:
@Test public void testSuccess() throws Exception { List<Map<String, List<Integer>>> source = new ArrayList<>(); final HashMap<String, List<Integer>> map = new HashMap<>(); map.put("random key", Arrays.asList(1, 2, 3, 4)); source.add(map); List<? extends Map<? extends String, ? extends List<? extends Integer>>> checked = checker.check((Object) source); assertEquals(source, checked); }
@Test (expected = ClassCastException.class) public void testFailure1() throws Exception { List<String> source = new ArrayList<>(); source.add("Hi there, I break your program!"); checker.check((Object) source); }
@Test (expected = ClassCastException.class) public void testFailure2() throws Exception { List<Map<String, List<Object>>> source = new ArrayList<>(); final HashMap<String, List<Object>> map = new HashMap<>(); map.put("random key", Arrays.<Object>asList(1, 2, 3, "Hi there, I break your program!")); source.add(map); checker.check((Object) source); }
@Test (expected = ClassCastException.class) public void testFailure3() throws Exception { Set<Map<String, List<Integer>>> source = new HashSet<>(); checker.check((Object) source); }