### Question:
ResourceUtils { public static List<GParameter> accumulateUriParameters(GResource resource) { Set<String> seenHere = extractSeen(new HashSet<String>(), resource); List<GParameter> parameters = new ArrayList<>(); parameters.addAll(Lists.reverse(FluentIterable.from(resource.uriParameters()).toList())); while (resource.parentResource() != null) { resource = resource.parentResource(); Set<String> seenInParent = extractSeen(seenHere, resource); final Set<String> finalSeenHere = seenHere; parameters.addAll(Lists.reverse(FluentIterable.from(resource.uriParameters()).filter(new Predicate<GParameter>() { @Override public boolean apply(@Nullable GParameter gParameter) { return !finalSeenHere.contains(gParameter.name()); } }).toList())); seenHere = seenInParent; } Collections.reverse(parameters); return parameters; }  static void fillInBodiesAndResponses(GResource resource,
                                              Multimap<GMethod, GRequest> incomingBodies, Multimap<GMethod, GResponse> responses); static List<GParameter> accumulateUriParameters(GResource resource);  }### Answer:
@Test public void accumulateUriParameters() throws Exception { when(resource.relativePath()).thenReturn("/fun"); when(one.name()).thenReturn("one"); when(two.name()).thenReturn("two"); when(resource.uriParameters()).thenReturn(Arrays.asList(one, two)); List<GParameter> parameters = ResourceUtils.accumulateUriParameters(resource); assertEquals(2, parameters.size()); assertEquals(one, parameters.get(0)); assertEquals(two, parameters.get(1)); }
@Test public void accumulateUriParametersFromParent() throws Exception { when(one.name()).thenReturn("one"); when(two.name()).thenReturn("two"); when(three.name()).thenReturn("three"); when(topResource.relativePath()).thenReturn("/fun/"); when(resource.relativePath()).thenReturn("/allo"); when(resource.parentResource()).thenReturn(topResource); when(topResource.uriParameters()).thenReturn(Arrays.asList(one, two)); when(resource.uriParameters()).thenReturn(Collections.singletonList(three)); List<GParameter> parameters = ResourceUtils.accumulateUriParameters(resource); assertEquals(3, parameters.size()); assertEquals(one, parameters.get(0)); assertEquals(two, parameters.get(1)); assertEquals(three, parameters.get(2)); }
@Test public void accumulateImplicitParameter() throws Exception { when(one.name()).thenReturn("one"); when(resource.relativePath()).thenReturn("/fun/{id}"); when(resource.uriParameters()).thenReturn(Collections.singletonList(one)); List<GParameter> parameters = ResourceUtils.accumulateUriParameters(resource); assertEquals(1, parameters.size()); assertEquals("one", parameters.get(0).name()); }
@Test public void accumulateImplicitUriParametersFromParent() throws Exception { when(one.name()).thenReturn("id"); when(two.name()).thenReturn("color"); when(three.name()).thenReturn("goo"); when(topResource.relativePath()).thenReturn("/fun/{id}/{color}"); when(topResource.uriParameters()).thenReturn(Arrays.asList(one, two)); when(resource.parentResource()).thenReturn(topResource); when(resource.relativePath()).thenReturn("/{goo}"); when(resource.uriParameters()).thenReturn(Collections.singletonList(three)); List<GParameter> parameters = ResourceUtils.accumulateUriParameters(resource); assertEquals(3, parameters.size()); assertEquals("id", parameters.get(0).name()); assertEquals("color", parameters.get(1).name()); assertEquals("goo", parameters.get(2).name()); }
@Test public void accumulateDeclaredLater() throws Exception { when(topResource.relativePath()).thenReturn("/fun/{id}"); when(resource.parentResource()).thenReturn(topResource); when(resource.relativePath()).thenReturn("/fun"); when(one.name()).thenReturn("id"); when(resource.uriParameters()).thenReturn(Collections.singletonList(one)); List<GParameter> parameters = ResourceUtils.accumulateUriParameters(resource); assertEquals(1, parameters.size()); assertEquals("id", parameters.get(0).name()); }