Skip to content

Instantly share code, notes, and snippets.

View mchmielarz's full-sized avatar
🏠
Working from home

Michał Chmielarz mchmielarz

🏠
Working from home
View GitHub Profile
@Component
public class KafkaListenerConsumer {
@KafkaListener(
concurrency = "2",
topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group-id}")
public void processMessage(List<Message<String>> content) {
// processing logic comes here
}
}
@Component
public class KafkaListenerConsumer {
@KafkaListener(topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group-id}")
public void processMessage(List<Message<String>> content) {
// processing logic comes here
}
}
@mchmielarz
mchmielarz / Assumptions_v0.2.0.java
Created December 14, 2019 07:29
Assumptions examples from assertj-vavr v0.2.0
// given
Option<String> empty = Option.none();
// this one fails
assumeThat(empty).isDefined();
// so the assertion won't be checked and test is ignored
assertThat(empty).contains("yay!);
// given
Either<String, Integer> value = Either.right(42);
// this oone passes
@mchmielarz
mchmielarz / EitherAssert_v0.2.0.java
Created December 14, 2019 07:27
Assertions added to EitherAssert in assertj-vavr v0.2.0
Either<Integer, String> actualLeft = Either.left(42);
assertThat(actualLeft).hasLeftValueSatisfying(it -> Assertions.assertThat(it).isEqualTo(42));
Either<Integer, String> actualRight = Either.right("42");
assertThat(actualRight).hasRightValueSatisfying(it -> Assertions.assertThat(it).isEqualTo("42"));
@mchmielarz
mchmielarz / MultimapAssert_v0.2.0.java
Last active December 14, 2019 20:51
MultimapAssert in assertj-vavr v0.2.0
// given
private static final Tuple2<String, String> FRODO = Tuple.of("hobbit", "frodo");
private static final Tuple2<String, String> SAM = Tuple.of("hobbit", "sam");
private static final Tuple2<String, String> GIMLI = Tuple.of("dwarf", "gimli");
private static final Tuple2<String, String> LEGOLAS = Tuple.of("elf", "legolas");
private static final Multimap<String, String> RACES =
HashMultimap.withSeq().ofEntries(FRODO, SAM, GIMLI);
private static final BiConsumer<String, String> OK_CONSUMER = (key, value) -> Assertions.assertThat(key).isLowerCase();
@mchmielarz
mchmielarz / entry_MapAssert_v0.2.0.java
Created December 14, 2019 07:24
Assertion checking for an entry satisfying condition added to MapAssert in assertj-vavr v0.2.0
assertThat(PERSONS).hasEntrySatisfying("frodo", new Condition<String>() {
@Override
public boolean matches(String value) {
return value.equals("hobbit");
}
});
@mchmielarz
mchmielarz / ordered_MapAssert_v0.2.0.java
Created December 14, 2019 07:21
Assertions for ordered maps added to MapAssert in assertj-vavr v0.2.0
// given
private static final Map<String, String> PERSONS_ORDERED = TreeMap.ofEntries(GIMLI, FRODO);
// in test
assertThat(PERSONS_ORDERED).containsExactly(FRODO, GIMLI);
@mchmielarz
mchmielarz / MapAssert_v0.2.0.java
Created December 14, 2019 07:18
New assertions added to MapAssert in assertj-vavr v0.2.0
// given
private static final Tuple2<String, String> FRODO = Tuple.of("frodo", "hobbit");
private static final Tuple2<String, String> GIMLI = Tuple.of("gimli", "dwarf");
private static final Tuple2<String, String> LEGOLAS = Tuple.of("legolas", "elf");
private static final Map<String, String> PERSONS = List.of(FRODO, GIMLI, LEGOLAS).toMap(tup -> tup);
// somewhere in tests
assertThat(PERSONS)
.containsOnly(List.of(FRODO, GIMLI, LEGOLAS))
public Option<TokenTTL> fetchRemainingTTL(AppId appId, UserId userId) {
ResultSet resultSet = cassandraOperations
.getCqlOperations()
.queryForResultSet("SELECT TTL(remote_ip) AS token_ttl from tokens WHERE app_id = ? AND user_id = ?", appId, userId);
return Option.of(resultSet.one()).map(row -> row.get("token_ttl", TokenTTL.class));
}
class MyConfig extends AbstractCassandraConfiguration {
@Override
protected ClusterBuilderConfigurer getClusterBuilderConfigurer() {
return clusterBuilder -> {
clusterBuilder.getConfiguration()
.getCodecRegistry()
.register(ApplicationIdCodec.instance)
.register(UserIdCodec.instance);
return clusterBuilder;