Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more Unit tests for the Utils class #655

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}