Skip to content

Commit

Permalink
Fix sonar issues (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrepa authored Jan 10, 2025
1 parent 4acb924 commit 0dff71a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -124,5 +126,18 @@ public String toString() {
return "%s<%s>".formatted(rawType.getTypeName(),
Stream.of(actualTypeArguments).map(Type::getTypeName).collect(Collectors.joining(", ")));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ParameterizedTypeImpl that = (ParameterizedTypeImpl) o;
return Objects.equals(rawType, that.rawType) && Objects.deepEquals(actualTypeArguments, that.actualTypeArguments);
}

@Override
public int hashCode() {
return Objects.hash(rawType, Arrays.hashCode(actualTypeArguments));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.CrudRepository;
Expand Down Expand Up @@ -48,8 +47,7 @@ public class SpringJPASteps {
public static boolean autoclean = true;
public static List<String> schemasToClean = List.of("public");

@Autowired(required = false)
private List<LocalContainerEntityManagerFactoryBean> entityManagerFactories;
private final List<LocalContainerEntityManagerFactoryBean> entityManagerFactories;
private Map<Type, CrudRepository<?, ?>> crudRepositoryByClass;
private Map<String, Type> entityClassByTableName;

Expand All @@ -61,9 +59,10 @@ public class SpringJPASteps {
JacksonMapper.with(objectMapper -> objectMapper.registerModule(PersistenceUtil.getMapperModule()));
}

public SpringJPASteps(ObjectSteps objects, SpringSteps spring) {
public SpringJPASteps(ObjectSteps objects, SpringSteps spring, @Nullable List<LocalContainerEntityManagerFactoryBean> entityManagerFactories) {
this.objects = objects;
this.spring = spring;
this.entityManagerFactories = entityManagerFactories;
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import jakarta.annotation.Nullable;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.avro.Schema;
Expand All @@ -24,11 +25,8 @@
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.header.Header;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
Expand Down Expand Up @@ -58,7 +56,6 @@
import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
@SuppressWarnings({"SpringJavaAutowiredMembersInspection", "unchecked"})
public class KafkaSteps {

public static final String RECORD = "(json messages?|" + VARIABLE_PATTERN + ")";
Expand Down Expand Up @@ -99,30 +96,26 @@ public static String bootstrapServers() {

private final ObjectSteps objects;

@Autowired(required = false)
private KafkaTemplate<GenericRecord, GenericRecord> avroKeyMessageKafkaTemplate;
private final KafkaTemplate<GenericRecord, GenericRecord> avroKeyMessageKafkaTemplate;

@Autowired(required = false)
private KafkaTemplate<String, GenericRecord> avroKafkaTemplate;
private final KafkaTemplate<String, GenericRecord> avroKafkaTemplate;

@Autowired(required = false)
private KafkaTemplate<String, String> jsonKafkaTemplate;
private final KafkaTemplate<String, String> jsonKafkaTemplate;

@Autowired(required = false)
List<ConsumerFactory<Object, Object>> avroJacksonConsumerFactories = new ArrayList<>();
List<ConsumerFactory<Object, Object>> avroJacksonConsumerFactories;

@Autowired(required = false)
List<ConsumerFactory<String, GenericRecord>> avroConsumerFactories = new ArrayList<>();
List<ConsumerFactory<String, GenericRecord>> avroConsumerFactories;

@Autowired(required = false)
List<ConsumerFactory<String, String>> jsonConsumerFactories = new ArrayList<>();
List<ConsumerFactory<String, String>> jsonConsumerFactories;

@Autowired(required = false)
private KafkaListenerEndpointRegistry registry;


public KafkaSteps(ObjectSteps objects) {
public KafkaSteps(ObjectSteps objects, @Nullable KafkaTemplate<GenericRecord, GenericRecord> avroKeyMessageKafkaTemplate, @Nullable KafkaTemplate<String, GenericRecord> avroKafkaTemplate, @Nullable KafkaTemplate<String, String> jsonKafkaTemplate, Optional<List<ConsumerFactory<Object, Object>>> avroJacksonConsumerFactories, Optional<List<ConsumerFactory<String, GenericRecord>>> avroConsumerFactories, Optional<List<ConsumerFactory<String, String>>> jsonConsumerFactories) {
this.objects = objects;
this.avroKeyMessageKafkaTemplate = avroKeyMessageKafkaTemplate;
this.avroKafkaTemplate = avroKafkaTemplate;
this.jsonKafkaTemplate = jsonKafkaTemplate;
this.avroJacksonConsumerFactories = avroJacksonConsumerFactories.orElse(new ArrayList<>());
this.avroConsumerFactories = avroConsumerFactories.orElse(new ArrayList<>());
this.jsonConsumerFactories = jsonConsumerFactories.orElse(new ArrayList<>());
}

public static String schemaRegistryUrl() {
Expand Down Expand Up @@ -548,9 +541,10 @@ public List<Map<?, Object>> asListOfRecordsWithHeaders(Object content) {

public Schema getSchema(String name) {
Object schema = objects.getOrSelf("_kafka.schemas." + name);
if (schema instanceof String && name.endsWith("s")) {
schema = objects.getOrSelf("_kafka.schemas." + name.substring(0, name.length() - 1));
if (schema instanceof Schema avroSchema) {
return avroSchema;
}
schema = objects.getOrSelf("_kafka.schemas." + name.substring(0, name.length() - 1));
assertThat(schema).isInstanceOf(Schema.class);
return (Schema) schema;
}
Expand Down

0 comments on commit 0dff71a

Please sign in to comment.