Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
@Data
public class LockAndExecute<T> extends OpContext<T> {

private final List<Consumer<T>> operations = Lists.newArrayList();
private List<Consumer<T>> operations = Lists.newArrayList();
@NonNull
private final Mode mode;
private Mode mode;
private Supplier<T> getter;
private Function<T, T> saver;
private T entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand All @@ -24,9 +23,9 @@
@Builder
public class ReadOnlyForRelationalDao<T> extends OpContext<List<T>> {
@NonNull
private final Supplier<List<T>> getter;
private Supplier<List<T>> getter;
@Builder.Default
private final List<Consumer<List<T>>> operations = Lists.newArrayList();
private List<Consumer<List<T>>> operations = Lists.newArrayList();

@Override
public OpType getOpType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.appform.dropwizard.sharding.dao.operations;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Set;

public class OpContextTest {

/**
* Fields in the opcontext implementations should be mutable so that they are available for mutation by observers.
*/
@Test
void testFieldsAreMutable() {
Reflections reflections = new Reflections("io.appform.dropwizard.sharding.dao.operations");
Set<Class<? extends OpContext>> classes = reflections.getSubTypesOf(OpContext.class);
classes.stream().forEach(c -> {
if (Arrays.stream(c.getDeclaredFields()).anyMatch(field -> Modifier.isFinal(field.getModifiers()))) {
Assertions.fail("Immutable field in class " + c.getSimpleName());
}
});

}
}