### Question:
Utils { static <T> Predicate<Object> typed(Class<T> type, Predicate<? super T> condition) { requireNonNull(type); requireNonNull(condition); return x -> type.isInstance(x) && condition.test(type.cast(x)); }    }### Answer:
@Test public void testTyped_notOfType() { StringCondition condition = Mockito.mock(StringCondition.class); assertThat(Utils.typed(String.class, condition::test).test(1)).isFalse(); verify(condition, never()).test(any(String.class)); }
@Test public void testTyped_ofType_false() { StringCondition condition = Mockito.mock(StringCondition.class); when(condition.test("hi")).thenReturn(false); assertThat(Utils.typed(String.class, condition::test).test("hi")).isFalse(); verify(condition).test("hi"); }
@Test public void testTyped_ofType_true() { StringCondition condition = Mockito.mock(StringCondition.class); when(condition.test("hi")).thenReturn(true); assertThat(Utils.typed(String.class, condition::test).test("hi")).isTrue(); verify(condition).test("hi"); }
@Test public void testTyped_doesNotPassCondition() { assertThat(Utils.typed(String.class, x -> true).test(1)).isFalse(); }