### Question:
RestHelper { public static final List<Param> computeRequestTemplateParams(final Resource resource, final Stack<Resource> ancestors) { final List<Param> params = new LinkedList<Param>(); final List<Resource> rightToLeftResources = new LinkedList<Resource>(); rightToLeftResources.addAll(reverse(ancestors)); rightToLeftResources.add(resource); for (final Resource rightToLeftResource : rightToLeftResources) { for (final Param param : rightToLeftResource.getParams()) { if (param.getStyle() == ParamStyle.TEMPLATE) { params.add(param); } } } return Collections.unmodifiableList(params); }  static final List<Param> computeRequestTemplateParams(final Resource resource,
            final Stack<Resource> ancestors); static final List<T> reverse(final List<T> strings);  }### Answer:
@Test public void testComputeRequestTemplateParamsEmptyAncestors() { Stack<Resource> resources = new Stack<Resource>(); Param r1p1 = mock(Param.class); when(r1p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r1p1.getId()).thenReturn(R1P1_ID); List<Param> r1Params = new ArrayList<Param>(1); r1Params.add(r1p1); Resource r1 = mock(Resource.class); when(r1.getParams()).thenReturn(r1Params); List<Param> templateParams = RestHelper.computeRequestTemplateParams(r1, resources); assertEquals(1, templateParams.size()); assertEquals(R1P1_ID, templateParams.get(0).getId()); }
@Test public void testComputeRequestTemplateParams() { Stack<Resource> resources = new Stack<Resource>(); Param r1p1 = mock(Param.class); when(r1p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r1p1.getId()).thenReturn(R1P1_ID); List<Param> r1Params = new ArrayList<Param>(1); r1Params.add(r1p1); Resource r1 = mock(Resource.class); when(r1.getParams()).thenReturn(r1Params); Param r2p1 = mock(Param.class); when(r2p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r2p1.getId()).thenReturn(R2P1_ID); Param r2p2 = mock(Param.class); when(r2p2.getStyle()).thenReturn(ParamStyle.QUERY); when(r2p2.getId()).thenReturn(R2P2_ID); List<Param> r2Params = new ArrayList<Param>(2); r2Params.add(r2p1); r2Params.add(r2p2); Resource r2 = mock(Resource.class); when(r2.getParams()).thenReturn(r2Params); Param r3p1 = mock(Param.class); when(r3p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r3p1.getId()).thenReturn(R3P1_ID); Param r3p2 = mock(Param.class); when(r3p2.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r3p2.getId()).thenReturn(R3P2_ID); List<Param> r3Params = new ArrayList<Param>(2); r3Params.add(r3p1); r3Params.add(r3p2); Resource r3 = mock(Resource.class); when(r3.getParams()).thenReturn(r3Params); resources.push(r2); resources.push(r3); List<Param> templateParams = RestHelper.computeRequestTemplateParams(r1, resources); assertEquals(4, templateParams.size()); assertEquals(R3P1_ID, templateParams.get(0).getId()); assertEquals(R3P2_ID, templateParams.get(1).getId()); assertEquals(R2P1_ID, templateParams.get(2).getId()); assertEquals(R1P1_ID, templateParams.get(3).getId()); }