From 1063b25ff5defe946c9caff42733a82f9de2cf15 Mon Sep 17 00:00:00 2001 From: Eka Winata Date: Mon, 16 Sep 2024 15:41:40 +0700 Subject: [PATCH] Assert exception message. Add fail mechanism in case of not throwing any exception --- ...fkaConsumerAdditionalConfigurationsAdaptorTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dagger-core/src/test/java/com/gotocompany/dagger/core/source/config/adapter/DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest.java b/dagger-core/src/test/java/com/gotocompany/dagger/core/source/config/adapter/DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest.java index 9b507e1e8..43fca4921 100644 --- a/dagger-core/src/test/java/com/gotocompany/dagger/core/source/config/adapter/DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest.java +++ b/dagger-core/src/test/java/com/gotocompany/dagger/core/source/config/adapter/DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest.java @@ -9,6 +9,7 @@ import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest { @@ -27,13 +28,18 @@ public void shouldMapJsonStringToMap() throws IOException { assertEquals(expectedResult, result); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldThrowExceptionForInvalidProperties() throws IOException { String input = "{\"SOURCE_KAFKA_CONSUMER_CONFIG_KEY_1\":\"value1\",\"SOURCE_KAFKA_CONSUMER_CONFIG_KEY_2\":\"value2\",\"INVALID_KEY\":\"value3\"}"; JsonReader jsonReader = new JsonReader(new StringReader(input)); DaggerKafkaConsumerAdditionalConfigurationsAdaptor daggerKafkaConsumerAdditionalConfigurationsAdaptor = new DaggerKafkaConsumerAdditionalConfigurationsAdaptor(); - daggerKafkaConsumerAdditionalConfigurationsAdaptor.read(jsonReader); + try { + daggerKafkaConsumerAdditionalConfigurationsAdaptor.read(jsonReader); + fail("Should have thrown an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + assertEquals("Invalid additional kafka consumer configuration properties found: [INVALID_KEY]", e.getMessage()); + } } }