ComposeStackUtil { public static Object findAncestorWithClass(Deque<Object> composeStack, Class<?> clazz) { for (Object obj : composeStack) { if (clazz.isAssignableFrom(obj.getClass())) { return obj; } } return null; } private  ComposeStackUtil(); static Object findAncestorWithClass(Deque<Object> composeStack, Class<?> clazz); @SuppressWarnings("unchecked") static Deque<Object> getComposeStack(Request request); static final String COMPOSE_STACK_ATTRIBUTE_NAME; }
@Test public void testFindAncestorWithClass() { Deque<Object> composeStack = new ArrayDeque<Object>(); Integer integerValue = new Integer(1); Long longValue = new Long(LONG_VALUE); String stringValue = "my value"; Integer integerValue2 = new Integer(INT_VALUE); composeStack.push(integerValue); composeStack.push(longValue); composeStack.push(stringValue); composeStack.push(integerValue2); assertEquals(integerValue2, ComposeStackUtil.findAncestorWithClass(composeStack, Integer.class)); assertEquals(longValue, ComposeStackUtil.findAncestorWithClass(composeStack, Long.class)); assertEquals(stringValue, ComposeStackUtil.findAncestorWithClass(composeStack, String.class)); assertEquals(integerValue2, ComposeStackUtil.findAncestorWithClass(composeStack, Object.class)); assertNull(ComposeStackUtil.findAncestorWithClass(composeStack, Date.class)); }