package com.composum.sling.core.util;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;

import static org.hamcrest.Matchers.equalTo;

public class LinkUtilTest {

    @Rule
    public final ErrorCollector ec = new ErrorCollector();

    @Test
    public void codecTest() throws Exception {
        LinkCodec codec = new LinkCodec();
        String input, output;
        ec.checkThat(output = codec.encode(
                input = "/a/bb/ccc/d ef?äö=#+*:.;,_-$%&"),
                equalTo("/a/bb/ccc/d%20ef%3F%C3%A4%C3%B6%3D%23%2B*%3A.%3B%2C_-%24%25%26"));
        ec.checkThat(codec.decode(output), equalTo(input));
        ec.checkThat(output = codec.encodeUrl(
                input = "/a/bb/ccc/d ef?äö=#+*:.;,_-$%&"),
                equalTo("/a/bb/ccc/d%20ef?%C3%A4%C3%B6=#%2B*:.;%2C_-%24%25&"));
        ec.checkThat(codec.decode(output), equalTo(input));
    }
}

@@ -47,226 +47,1065 @@
 org.
-junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ErrorCollector;%0A%0Aimport static org.hamcrest.Matchers.equalTo;%0A%0Apublic class LinkUtilTest %7B%0A%0A    @Rule%0A    public final ErrorCollector ec = new ErrorCollector();
+apache.sling.api.SlingHttpServletRequest;%0Aimport org.apache.sling.api.resource.ResourceResolver;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ErrorCollector;%0Aimport org.mockito.Mock;%0Aimport org.mockito.Mockito;%0Aimport org.mockito.MockitoAnnotations;%0A%0Aimport static org.hamcrest.Matchers.equalTo;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.mockito.ArgumentMatchers.any;%0Aimport static org.mockito.ArgumentMatchers.anyString;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic class LinkUtilTest %7B%0A%0A    @Rule%0A    public final ErrorCollector ec = new ErrorCollector();%0A%0A    @Mock%0A    protected SlingHttpServletRequest request;%0A%0A    @Mock%0A    protected ResourceResolver resolver = Mockito.mock(ResourceResolver.class);%0A%0A    @Before%0A    public void setup() %7B%0A        MockitoAnnotations.initMocks(this);%0A        when(request.getResourceResolver()).thenReturn(resolver);%0A        when(resolver.map(any(), anyString())).thenAnswer(%0A                (invocation) -%3E invocation.getArgument(1)%0A        );%0A    %7D
 %0A%0A  
@@ -1738,11 +1738,204 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testPathMapping() %7B%0A        ec.checkThat(LinkUtil.getUrl(request, %22/content/charsettests/page with+spaces%22), is(%22/content/charsettests/page%2520with%252Bspaces%22));%0A    %7D
 %0A%7D%0A

extend LinkUtilTest