Skip to content

Commit

Permalink
Refactor unit tests to try and fix SonarQube
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Jul 21, 2023
1 parent 1b75dae commit 9eb8fb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void close() {
* @param kafkaStreams The kafka streams to configure.
* @return An optional exception handler if {@code uncaught-exception-handler} was configured.
*/
private static Optional<StreamsUncaughtExceptionHandler> setUncaughtExceptionHandler(Properties properties, KafkaStreams kafkaStreams) {
Optional<StreamsUncaughtExceptionHandler> setUncaughtExceptionHandler(Properties properties, KafkaStreams kafkaStreams) {
final Optional<StreamsUncaughtExceptionHandler> uncaughtExceptionHandler = Optional
.ofNullable(properties.getProperty(UNCAUGHT_EXCEPTION_HANDLER_PROPERTY))
.filter(not(String::isBlank))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package io.micronaut.configuration.kafka.streams

import org.apache.kafka.streams.KafkaStreams
import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler
import spock.lang.Specification
import spock.lang.Unroll

import static org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler.StreamThreadExceptionResponse.*

class KafkaStreamsFactorySpec extends Specification {
class KafkaStreamsFactorySpec extends AbstractTestContainersSpec {

void "set exception handler when no config is given"() {
given:
KafkaStreamsFactory kafkaStreamsFactory = context.getBean(KafkaStreamsFactory)
KafkaStreams kafkaStreams = Mock()
Properties props = new Properties()

when:
def handler = KafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)
def handler = kafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)

then:
handler.empty
Expand All @@ -24,11 +24,12 @@ class KafkaStreamsFactorySpec extends Specification {

void "set exception handler when no valid config is given"() {
given:
KafkaStreamsFactory kafkaStreamsFactory = context.getBean(KafkaStreamsFactory)
KafkaStreams kafkaStreams = Mock()
Properties props = ['uncaught-exception-handler': config]

when:
def handler = KafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)
def handler = kafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)

then:
handler.empty
Expand All @@ -41,16 +42,18 @@ class KafkaStreamsFactorySpec extends Specification {
@Unroll
void "set exception handler when given config is #config"(String config) {
given:
KafkaStreamsFactory kafkaStreamsFactory = context.getBean(KafkaStreamsFactory)
KafkaStreams kafkaStreams = Mock()
Properties props = ['uncaught-exception-handler': config]

when:
def handler = KafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)
def handler = kafkaStreamsFactory.setUncaughtExceptionHandler(props, kafkaStreams)

then:
handler.present
handler.get().handle(null) == expected
1 * kafkaStreams.setUncaughtExceptionHandler(_ as StreamsUncaughtExceptionHandler)
0 * _

where:
config | expected
Expand Down

0 comments on commit 9eb8fb3

Please sign in to comment.