From 365e9ac75be4d24faa31cf56c33f3cf658fc3cc7 Mon Sep 17 00:00:00 2001 From: DohaRamadan <77820526+DohaRamadan@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:20:29 +0200 Subject: [PATCH] added unit test cases --- .../zerocode/core/utils/TokenUtilsTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/core/src/test/java/org/jsmart/zerocode/core/utils/TokenUtilsTest.java b/core/src/test/java/org/jsmart/zerocode/core/utils/TokenUtilsTest.java index 9566c4dc9..6c01ac6c8 100644 --- a/core/src/test/java/org/jsmart/zerocode/core/utils/TokenUtilsTest.java +++ b/core/src/test/java/org/jsmart/zerocode/core/utils/TokenUtilsTest.java @@ -10,6 +10,8 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.jsmart.zerocode.core.utils.TokenUtils.absolutePathOf; +import static org.jsmart.zerocode.core.utils.TokenUtils.getMaskedTokensReplaced; +import static org.jsmart.zerocode.core.utils.TokenUtils.getMasksRemoved; import static org.jsmart.zerocode.core.utils.TokenUtils.resolveKnownTokens; import static org.junit.Assert.*; @@ -169,4 +171,48 @@ public void testAbsolutePathOf() { assertThat(absolutePathOf("unit_test_files/jks_files/dummy_key_store.jks"), containsString("zerocode/core/target/test-classes/unit_test_files/jks_files/dummy_key_store.jks")); } + + + @Test + public void testGetMaskedTokensReplaced_multipleOccurrences(){ + assertEquals("This is a ***masked*** message with ***masked*** tokens.", getMaskedTokensReplaced("This is a ${MASKED:secret} message with ${MASKED:masked} tokens.")); + } + + @Test + public void testGetMaskedTokensReplaced_noOccurrences(){ + assertEquals("This string has no masked tokens.", getMaskedTokensReplaced("This string has no masked tokens.")); + } + + @Test + public void testGetMaskedTokensReplaced_emptyString(){ + assertEquals("", getMaskedTokensReplaced("")); + } + + @Test + public void testGetMaskedTokensReplaced_specialCharacters(){ + assertEquals("***masked*** and ***masked***", getMaskedTokensReplaced("${MASKED:abc@123} and ${MASKED:!@#$%^}")); + } + + @Test + public void testGetMaskedTokensRemoved_multipleOccurrences(){ + assertEquals("This is a secret message with masked tokens.", getMasksRemoved("This is a ${MASKED:secret} message with ${MASKED:masked} tokens.")); + } + + @Test + public void testGetMaskedTokensRemoved_noOccurrences(){ + assertEquals("This string has no masked tokens.", getMasksRemoved("This string has no masked tokens.")); + } + + @Test + public void testGetMaskedTokensRemoved_emptyString(){ + assertEquals("", getMasksRemoved("")); + } + + @Test + public void testGetMaskedTokensRemoved_specialCharacters(){ + assertEquals("abc@123 and !@#$%^", getMasksRemoved("${MASKED:abc@123} and ${MASKED:!@#$%^}")); + } + + + } \ No newline at end of file