Skip to content

Commit

Permalink
#652 Add more Unit tests for the Utils class (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Monoradioactivo authored Oct 10, 2023
1 parent dc27ef0 commit 0a56e8f
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/test/java/com/crowdin/cli/utils/UtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.crowdin.cli.utils;

import java.util.Optional;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand Down Expand Up @@ -32,4 +34,74 @@ public void testIsWindows() {
public void testBuildUserAgent() {
assertNotNull(Utils.buildUserAgent());
}

@Test
public void testUnixPath() {
assertEquals("/path/to/file", Utils.unixPath("\\path\\to\\file"));
}

@Test
public void testWindowsPath() {
assertEquals("\\path\\to\\file", Utils.windowsPath("/path/to/file"));
}

@Test
public void testNormalizePath() {
assertEquals(Utils.PATH_SEPARATOR + "path" + Utils.PATH_SEPARATOR + "to" + Utils.PATH_SEPARATOR + "file", Utils.normalizePath("/path/to/file"));
}

@Test
public void testNoSepAtStart() {
assertEquals("path/to/file", Utils.noSepAtStart("/path/to/file"));
}

@Test
public void testSepAtStart() {
assertEquals(Utils.PATH_SEPARATOR + "path/to/file", Utils.sepAtStart("path/to/file"));
}

@Test
public void testNoSepAtEnd() {
assertEquals("/path/to/file", Utils.noSepAtEnd("/path/to/file/"));
}

@Test
public void testSepAtEnd() {
assertEquals("/path/to/file" + Utils.PATH_SEPARATOR, Utils.sepAtEnd("/path/to/file"));
}

@Test
public void testRegexPath() {
assertEquals("\\\\path\\\\to\\\\file", Utils.regexPath("\\path\\to\\file"));
}

@Test
public void testJoinPaths() {
assertEquals("path" + Utils.PATH_SEPARATOR + "to" + Utils.PATH_SEPARATOR + "file", Utils.joinPaths("path", "to", "file"));
}

@Test
public void testSplitPath() {
assertArrayEquals(new String[]{"path", "to", "file"}, Utils.splitPath("path/to/file"));
}

@Test
public void testGetParentDirectory() {
assertEquals("path" + Utils.PATH_SEPARATOR + "to" + Utils.PATH_SEPARATOR, Utils.getParentDirectory("path" + Utils.PATH_SEPARATOR + "to" + Utils.PATH_SEPARATOR + "file"));
}

@Test
public void testProxyHost() {
assertEquals(Optional.empty(), Utils.proxyHost());
}

@Test
public void testProxyCredentials() {
assertEquals(Optional.empty(), Utils.proxyCredentials());
}

@Test
public void testEncodeURL() {
assertEquals("Hello+World", Utils.encodeURL("Hello World"));
}
}

0 comments on commit 0a56e8f

Please sign in to comment.