From ae1ffb7eab6f8437cbb6e223e416c67f218d136f Mon Sep 17 00:00:00 2001 From: Gloria Ciavarrini Date: Fri, 14 Apr 2023 11:34:41 +0200 Subject: [PATCH] Fix: make getHash test programmatic Signed-off-by: Gloria Ciavarrini --- .../WorkFlowVersionServiceImplTest.java | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/version/WorkFlowVersionServiceImplTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/version/WorkFlowVersionServiceImplTest.java index 23ec102a7..ff1b0bcdb 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/version/WorkFlowVersionServiceImplTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/version/WorkFlowVersionServiceImplTest.java @@ -3,8 +3,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertThrows; class WorkFlowVersionServiceImplTest { @@ -17,14 +21,49 @@ public void setUp() { } @Test - public void testGetHash() { + public void testGetHashSameValue() { // given - Object object = new Object(); + String foo1 = new String("foo"); + String foo2 = new String("foo"); + + assertNotSame(foo1, foo2); + + // when + assertDoesNotThrow(() -> { + String hashFoo1 = this.workFlowVersionService.getHash(foo1); + assertNotNull(hashFoo1); + assertFalse(hashFoo1.isEmpty()); + assertFalse(hashFoo1.isBlank()); + + String hashFoo2 = this.workFlowVersionService.getHash(foo2); + assertNotNull(hashFoo2); + assertFalse(hashFoo2.isEmpty()); + assertFalse(hashFoo2.isBlank()); + + assertEquals(hashFoo1, hashFoo2); + + }); + } + + @Test + public void testGetHashDifferentValue() { + // given + String foo = new String("foo"); + String bar = new String("bar"); // when assertDoesNotThrow(() -> { - String hash = this.workFlowVersionService.getHash(object); - assertEquals(hash, "b0c8ed039dc102c0bab6a5e979931a0b"); + String hashFoo1 = this.workFlowVersionService.getHash(foo); + assertNotNull(foo); + assertFalse(foo.isEmpty()); + assertFalse(foo.isBlank()); + + String hashFoo2 = this.workFlowVersionService.getHash(bar); + assertNotNull(bar); + assertFalse(bar.isEmpty()); + assertFalse(bar.isBlank()); + + assertNotEquals(foo, bar); }); }