Skip to content

Commit

Permalink
Assert exception message. Add fail mechanism in case of not throwing …
Browse files Browse the repository at this point in the history
…any exception
  • Loading branch information
ekawinataa committed Sep 16, 2024
1 parent 6c4e8ae commit 1063b25
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


public class DaggerKafkaConsumerAdditionalConfigurationsAdaptorTest {
Expand All @@ -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());
}
}

}

0 comments on commit 1063b25

Please sign in to comment.