kazurayam / inspectus

The Inspectus library enables automated UI tests in Java/Groovy to perform "Visual Inspection" on top of the "materialstore"
Apache License 2.0
0 stars 0 forks source link

`sitemapLoader.resolveUrl("p1.html")` has a problem #63

Closed kazurayam closed 1 year ago

kazurayam commented 1 year ago

https://github.com/kazurayam/inspectus/blob/0.7.5/src/test/java/com/kazurayam/inspectus/materialize/discovery/SitemapLoaderTest.java has a problem.

Once it was as this, and failed.

    @Test
    public void test_resolveURl_withoutSlash() throws InspectusException {
        SitemapLoader sitemapLoader =
                new SitemapLoader(Target.builder("http://example.com/pages").build());
        URL url = sitemapLoader.resolveUrl("p1.html");
        assertEquals("http://example.com/pages/p1.html", url.toString());
    }

So I changed to

        assertEquals("http://example.com/p1.html", url.toString());

and this test now passes.

But, this behavior is not what I really want.

I want

        assertEquals("http://example.com/pages/p1.html", url.toString());

to pass.

kazurayam commented 1 year ago

I have found a fact.

See the following code.

    @Test
    public void test_URL_constructor_withoutSlash() throws MalformedURLException {
        URL baseURL1 = new URL("http://example.com/pages");
        URL derived1 = new URL(baseURL1, "p1.html");
        assertEquals("http://example.com/p1.html", derived1.toExternalForm());

        // the "/" character at the end of baseURL matters
        URL baseURL2 = new URL("http://example.com/pages/");
        URL derived2 = new URL(baseURL2, "p1.html");
        assertEquals("http://example.com/pages/p1.html", derived2.toExternalForm());
    }

The "/" character at the end of baseURL matters.