-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UT for ConfigUtils.toMap and handled more edge cases
- Loading branch information
voonhou.su
committed
Jul 4, 2022
1 parent
e095404
commit 396022e
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestConfigUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.apache.hudi.sync.common.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestConfigUtils { | ||
|
||
@Test | ||
public void testToMapSucceeds() { | ||
Map<String, String> expectedMap = new HashMap<>(); | ||
expectedMap.put("k.1.1.2", "v1"); | ||
expectedMap.put("k.2.1.2", "v2"); | ||
expectedMap.put("k.3.1.2", "v3"); | ||
|
||
// Test base case | ||
String srcKv = "k.1.1.2=v1\nk.2.1.2=v2\nk.3.1.2=v3"; | ||
Map<String, String> outMap = ConfigUtils.toMap(srcKv); | ||
assertEquals(expectedMap, outMap); | ||
|
||
// Test ends with new line | ||
srcKv = "k.1.1.2=v1\nk.2.1.2=v2\nk.3.1.2=v3\n"; | ||
outMap = ConfigUtils.toMap(srcKv); | ||
assertEquals(expectedMap, outMap); | ||
|
||
// Test delimited by multiple new lines | ||
srcKv = "k.1.1.2=v1\nk.2.1.2=v2\n\nk.3.1.2=v3"; | ||
outMap = ConfigUtils.toMap(srcKv); | ||
assertEquals(expectedMap, outMap); | ||
|
||
// Test delimited by multiple new lines with spaces in between | ||
srcKv = "k.1.1.2=v1\n \nk.2.1.2=v2\n\nk.3.1.2=v3"; | ||
outMap = ConfigUtils.toMap(srcKv); | ||
assertEquals(expectedMap, outMap); | ||
|
||
// Test with random spaces if trim works properly | ||
srcKv = " k.1.1.2 = v1\n k.2.1.2 = v2 \nk.3.1.2 = v3"; | ||
outMap = ConfigUtils.toMap(srcKv); | ||
assertEquals(expectedMap, outMap); | ||
} | ||
|
||
@Test | ||
public void testToMapThrowError() { | ||
String srcKv = "k.1.1.2=v1=v1.1\nk.2.1.2=v2\nk.3.1.2=v3"; | ||
assertThrows(IllegalArgumentException.class, () -> ConfigUtils.toMap(srcKv)); | ||
} | ||
} |