@Test
public void toUrlShouldTransformGivenRequestToUrl() throws Exception {

    Request request = mock(Request.class);
    MethodConfig methodConfig = mock(MethodConfig.class);
    PathTemplate pathTemplate = mock(PathTemplate.class);
    PathBuilder pathBuilder = mock(PathBuilder.class);
    Iterator<EncodedPair> pathPairs = asList(
            Pairs.toPreEncodedPair("p1","v1"),
            Pairs.toPreEncodedPair("p2","v2")
    ).iterator();
    Iterator<EncodedPair> queryPairs = mock(Iterator.class);
    Iterator<EncodedPair> matrixPairs = mock(Iterator.class);
    when(request.getEncodedParamsIterator(PATH)).thenReturn(pathPairs);
    when(request.getEncodedParamsIterator(QUERY)).thenReturn(queryPairs);
    when(request.getEncodedParamsIterator(MATRIX)).thenReturn(matrixPairs);
    when(pathTemplate.getBuilder(UTF8)).thenReturn(pathBuilder);
    when(methodConfig.getCharset()).thenReturn(UTF8);
    when(methodConfig.getPathTemplate()).thenReturn(pathTemplate);
    when(request.getMethodConfig()).thenReturn(methodConfig);
    when(pathBuilder.build()).thenReturn("path");
    mockStatic(Pairs.class);
    when(Pairs.join(queryPairs, '&')).thenReturn("query");
    when(Pairs.join(matrixPairs, ';')).thenReturn("matrix");
    assertEquals("path;matrix?query", HttpRequests.toUrl(request));
    verify(pathBuilder).merge("p1", "v1", true);
    verify(pathBuilder).merge("p2", "v2", true);
}