Skip to content

Commit 4be5c2e

Browse files
author
gabrascher
committed
Test fails in Widows as the file separator "/" is different from "\"
File separator in windows is different from linux (the expected in the test); thus, the test *com.cloud.utils.SwiftUtilTest.testSplitSwiftPath()* will fail in windows. The problem is that the input of the test is *"container/object"* but the tested method uses the *File.separator* (that depends from the OS), in the windows the tested method (*com.cloud.utils.SwiftUtil.splitSwiftPath(String)*) looks for a "\" in windows systems, resulting in an empty string and consequently a failure in the test. Some solutions: - the simple way is to create a string `String input = "container" + File.separator + "object";`, thus independent of the OS, the test will succeed. - a tricky solution is to mock the final static variable *File.separator* and return "/". I picked the easy way.
1 parent 0dcaf19 commit 4be5c2e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

utils/src/test/java/com/cloud/utils/SwiftUtilTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
package com.cloud.utils;
2121

22+
2223
import org.junit.Test;
2324
import org.mockito.Mockito;
2425

26+
import java.io.File;
2527
import java.net.URL;
2628
import java.security.InvalidKeyException;
2729
import java.security.NoSuchAlgorithmException;
@@ -32,7 +34,6 @@
3234
import static org.junit.Assert.assertTrue;
3335
import static org.mockito.Mockito.when;
3436

35-
3637
public class SwiftUtilTest {
3738

3839
@Test
@@ -72,7 +73,7 @@ public void testGenerateTempUrl() {
7273

7374
@Test
7475
public void testSplitSwiftPath(){
75-
String input = "container/object";
76+
String input = "container" + File.separator + "object";
7677
String[] output = SwiftUtil.splitSwiftPath(input);
7778
String[] expected = {"container", "object"};
7879

0 commit comments

Comments
 (0)