View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.errorprone;
6   
7   import java.io.File;
8   import java.net.URI;
9   import org.hamcrest.MatcherAssert;
10  import org.hamcrest.Matchers;
11  import org.junit.jupiter.api.Test;
12  import org.junit.jupiter.api.io.TempDir;
13  
14  /**
15   * Test case for {@link Unencoded}.
16   *
17   * @since 1.0
18   */
19  final class UnencodedTest {
20  
21      @Test
22      void decodesSpaceInDirectoryName(@TempDir final File dir) throws Exception {
23          final File jar = new File(new File(dir, "My Project"), "foo.jar");
24          MatcherAssert.assertThat(
25              "space in a directory name cannot survive as an escape",
26              new Unencoded(jar.toURI().toURL()).path().orElse(""),
27              Matchers.equalTo(jar.getAbsolutePath())
28          );
29      }
30  
31      @Test
32      void dontResolveRemoteUrls() throws Exception {
33          MatcherAssert.assertThat(
34              "remote URL cannot resolve to a local path",
35              new Unencoded(
36                  URI.create("http://example.com/foo.jar").toURL()
37              ).path().isPresent(),
38              Matchers.is(false)
39          );
40      }
41  }