Skip to content

Commit

Permalink
Stop using lombok val.
Browse files Browse the repository at this point in the history
We require at least Java 17 now, which has var.
  • Loading branch information
prdoyle committed Aug 18, 2024
1 parent 0deeb61 commit 4b2586d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 45 deletions.
9 changes: 4 additions & 5 deletions bosk-core/src/test/java/works/bosk/BoskConstructorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import works.bosk.Bosk.DefaultRootFunction;
Expand Down Expand Up @@ -50,7 +49,7 @@ void basicProperties_correctValues() {

assertSame(driver.get(), bosk.getDriver(ForwardingDriver.class));

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(root, bosk.rootReference().value());
}
}
Expand Down Expand Up @@ -106,7 +105,7 @@ void driverInitialRoot_matches() {
SimpleTypes.class,
_ -> {throw new AssertionError("Shouldn't be called");},
initialRootDriver(()->root));
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(root, bosk.rootReference().value());
}
}
Expand All @@ -116,14 +115,14 @@ void defaultRoot_matches() {
SimpleTypes root = newEntity();
{
Bosk<StateTreeNode> valueBosk = new Bosk<>(boskName(), SimpleTypes.class, root, Bosk::simpleDriver);
try (val _ = valueBosk.readContext()) {
try (var _ = valueBosk.readContext()) {
assertSame(root, valueBosk.rootReference().value());
}
}

{
Bosk<StateTreeNode> functionBosk = new Bosk<StateTreeNode>(boskName(), SimpleTypes.class, _ -> root, Bosk::simpleDriver);
try (val _ = functionBosk.readContext()) {
try (var _ = functionBosk.readContext()) {
assertSame(root, functionBosk.rootReference().value());
}
}
Expand Down
31 changes: 15 additions & 16 deletions bosk-core/src/test/java/works/bosk/BoskLocalReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import lombok.experimental.Delegate;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import works.bosk.annotations.ReferencePath;
Expand Down Expand Up @@ -163,7 +162,7 @@ void testListingReference() throws Exception {
// Check references to the Listing contents
Listing<TestEntity> listing;
Map<Identifier, TestEntity> entries;
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
listing = listingRef.value();
entries = listing.valueMap();
}
Expand Down Expand Up @@ -206,7 +205,7 @@ void testSideTableReference() throws InvalidTypeException {
} catch (AssertionError e) {
throw new AssertionError("Failed checkRefence on id " + id + ", sideTableRef " + sideTableRef);
}
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
for (Entry<Identifier, String> entry: sideTable.idEntrySet()) {
Identifier key = entry.getKey();
Reference<String> entryRef = sideTableRef.then(key);
Expand Down Expand Up @@ -290,7 +289,7 @@ private <T> void checkReferenceProperties(Reference<T> ref, Path expectedPath, T
assertEquals(expectedPath.urlEncoded(), ref.pathString());

assertThrows(IllegalStateException.class, ref::value, "Can't read before ReadContext");
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
T actualValue = ref.valueIfExists();
assertSame(expectedValue, actualValue);

Expand Down Expand Up @@ -322,7 +321,7 @@ private void checkEntityReference(Reference<TestEntity> ref, Path expectedPath,
assertEquals(expectedPath.then(TestEntity.Fields.listing), ref.then(Listing.class, TestEntity.Fields.listing).path());
assertEquals(expectedPath.then(TestEntity.Fields.sideTable), ref.then(SideTable.class, TestEntity.Fields.sideTable).path());

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
if (expectedValue == null) {
assertNull(ref.then(Catalog.class, TestEntity.Fields.catalog).valueIfExists());
assertNull(ref.then(Listing.class, TestEntity.Fields.listing).valueIfExists());
Expand All @@ -339,33 +338,33 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws
Root originalRoot;
T firstValue;
assertThrows(IllegalStateException.class, ref::value, "Can't read from Bosk before ReadContext");
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
firstValue = ref.value();
}
assertThrows(IllegalStateException.class, ref::value, "Can't read from Bosk between ReadContexts");

T secondValue = updater.apply(firstValue);
T thirdValue = updater.apply(secondValue);
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(firstValue, ref.value(), "New ReadContext sees same value as before");
bosk.driver().submitReplacement(ref, secondValue);
assertSame(firstValue, ref.value(), "Bosk updates not visible during the same ReadContext");

try (val _ = bosk.supersedingReadContext()) {
try (var _ = bosk.supersedingReadContext()) {
assertSame(secondValue, ref.value(), "Superseding context sees the latest state");
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(secondValue, ref.value(), "Nested context matches outer context");
}
}

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(firstValue, ref.value(), "Nested context matches original outer context");
}
}

try (
val context = bosk.readContext();
var context = bosk.readContext();
) {
assertSame(secondValue, ref.value(), "New value is visible in next ReadContext");
bosk.driver().submitReplacement(ref, thirdValue);
Expand All @@ -382,13 +381,13 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws
fail("Unexpected exception: ", e);
}
assertNotNull(caught, "New thread should not have any scope by default, so an exception should be thrown");
try (val unrelatedContext = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertSame(thirdValue, ref.value(), "Separate thread should see the latest state");
}
try (val inheritedContext = context.adopt()) {
try (var inheritedContext = context.adopt()) {
assertSame(secondValue, ref.value(), "Inherited scope should see the same state");

try (val reinheritedContext = inheritedContext.adopt()) {
try (var _ = inheritedContext.adopt()) {
// Harmless to re-assert a scope you're already in
assertSame(secondValue, ref.value(), "Inner scope should see the same state");
}
Expand All @@ -408,13 +407,13 @@ private <T> void checkUpdates(Reference<T> ref, UnaryOperator<T> updater) throws

private <T> void checkDeletion(Reference<T> ref, T expectedValue) {
Root originalRoot;
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
assertSame(expectedValue, ref.valueIfExists(), "Value is present before deletion");
bosk.driver().submitDeletion(ref);
assertSame(expectedValue, ref.valueIfExists(), "Bosk deletions not visible during the same ReadContext");
}
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertThrows(NonexistentReferenceException.class, ref::value);
if (expectedValue != null) {
bosk.driver().submitReplacement(ref, expectedValue);
Expand Down
5 changes: 2 additions & 3 deletions bosk-core/src/test/java/works/bosk/BoskUpdateTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package works.bosk;

import java.io.IOException;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import works.bosk.annotations.ReferencePath;
Expand Down Expand Up @@ -47,7 +46,7 @@ void createBosk() throws InvalidTypeException {
Bosk::simpleDriver
);
refs = bosk.buildReferences(Refs.class);
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
originalParent = refs.entity(PARENT_ID).value();
originalChild1 = refs.child(PARENT_ID, CHILD_1_ID).value();
Expand Down Expand Up @@ -153,7 +152,7 @@ void conditionalReplaceIDMismatchesNonNull_nothingChanged() throws IOException,

<T> void assertValueEquals(T expected, Reference<T> ref) throws IOException, InterruptedException {
bosk.driver().flush();
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expected, ref.valueIfExists());
}
}
Expand Down
9 changes: 4 additions & 5 deletions bosk-core/src/test/java/works/bosk/HooksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -49,7 +48,7 @@ public interface Refs {
void setupBosk() throws InvalidTypeException {
bosk = setUpBosk(Bosk::simpleDriver);
refs = bosk.rootReference().buildReferences(Refs.class);
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
originalParent = refs.parent().value();
originalChild1 = refs.child(child1).value();
Expand Down Expand Up @@ -449,7 +448,7 @@ void nestedMultipleUpdates_breadthFirst() {
recorder.events(),
"All hooks for an update should be called before any hooks for subsequent updates");

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expectedParent, refs.parent().value());
}
}
Expand All @@ -461,7 +460,7 @@ void nested_correctReadContext() {
recorder.restart();
String expectedString = "expected string";

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
bosk.driver().submitReplacement(refs.childString(child2), expectedString);
// If the hook were to run accidentally in this ReadContext, it would
// see originalChild2.string() instead of expectedString.
Expand All @@ -473,7 +472,7 @@ void nested_correctReadContext() {
"Hooks run in the right ReadContext regardless of active read scope at submission or execution time");


try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(expectedString, refs.childString(child2).value(), "Correct value got copied");
}
}
Expand Down
13 changes: 6 additions & 7 deletions bosk-core/src/test/java/works/bosk/ListingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants;
import lombok.val;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -107,7 +106,7 @@ public static class TestEntity implements Entity {
@ParameterizedTest
@ArgumentsSource(ListingArgumentProvider.class)
void testGet(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) throws InvalidTypeException {
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
for (TestEntity child: children) {
TestEntity actual = listing.getValue(child.id());
assertSame(child, actual, "All expected entities should be present in the Listing");
Expand All @@ -129,7 +128,7 @@ void testGet(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEn
void testValueIterator(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Iterator<TestEntity> expected = children.iterator();
Iterator<TestEntity> actual;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the iterator
actual = listing.valueIterator();
}
Expand Down Expand Up @@ -169,7 +168,7 @@ void testIdStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<T
void testStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Iterator<TestEntity> expected = children.iterator();
Stream<TestEntity> stream;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the stream
stream = listing.valueStream();
}
Expand All @@ -180,7 +179,7 @@ void testStream(Listing<TestEntity> listing, List<TestEntity> children, Bosk<Tes
@ArgumentsSource(ListingArgumentProvider.class)
void testAsCollection(Listing<TestEntity> listing, List<TestEntity> children, Bosk<TestEntity> bosk) {
Collection<TestEntity> actual;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// ReadContext is needed only when creating the collection
actual = listing.valueList();
}
Expand Down Expand Up @@ -208,7 +207,7 @@ void testSpliterator(Listing<TestEntity> listing, List<TestEntity> children, Bos
}

Spliterator<TestEntity> newSplit;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
newSplit = listing.values().spliterator();
}

Expand Down Expand Up @@ -257,7 +256,7 @@ void testEmpty() throws InvalidTypeException {
assertEquals(0, actual.size());

Iterator<TestEntity> iterator;
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// iterator() needs a ReadContext at creation time
iterator = actual.valueIterator();
}
Expand Down
7 changes: 3 additions & 4 deletions bosk-core/src/test/java/works/bosk/OptionalRefsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -122,15 +121,15 @@ private <E extends Entity, V> void doTest(E initialRoot, ValueFactory<E, V> valu
V value = valueFactory.createFrom(bosk);
@SuppressWarnings("unchecked")
Reference<V> optionalRef = bosk.rootReference().then((Class<V>)value.getClass(), "field");
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertNull(optionalRef.valueIfExists());
}
bosk.driver().submitReplacement(optionalRef, value);
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertEquals(value, optionalRef.valueIfExists());
}
bosk.driver().submitDeletion(optionalRef);
try (val context = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertNull(optionalRef.valueIfExists());
}

Expand Down
3 changes: 1 addition & 2 deletions bosk-core/src/test/java/works/bosk/ReferenceErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.experimental.FieldNameConstants;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import works.bosk.exceptions.InvalidTypeException;
Expand All @@ -27,7 +26,7 @@ void setupBosk() {
@Test
void referenceGet_brokenGetter_propagatesException() throws InvalidTypeException {
Reference<Identifier> idRef = bosk.rootReference().then(Identifier.class, Path.just("id"));
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
assertThrows(UnsupportedOperationException.class, idRef::value,
"Reference.value() should propagate the exception as-is");
}
Expand Down
5 changes: 2 additions & 3 deletions lib-testing/src/main/java/works/bosk/PluginRoundTripTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package works.bosk;

import lombok.val;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import works.bosk.exceptions.InvalidTypeException;
Expand All @@ -13,12 +12,12 @@ public class PluginRoundTripTest extends AbstractRoundTripTest {
void testRoundTrip(DriverFactory<TestRoot> driverFactory) throws InvalidTypeException {
Bosk<TestRoot> bosk = setUpBosk(driverFactory);
TestRoot originalRoot;
try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
originalRoot = bosk.rootReference().value();
}
bosk.driver().submitReplacement(bosk.rootReference(), originalRoot);

try (val _ = bosk.readContext()) {
try (var _ = bosk.readContext()) {
// Use our entity's equals() to check that all is well
//
assertEquals(originalRoot, bosk.rootReference().value());
Expand Down
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ lombok.accessors.fluent=true
lombok.anyConstructor.addConstructorProperties=true
lombok.addLombokGeneratedAnnotation=true
lombok.sneakyThrows.flagUsage=error
lombok.val.flagUsage=error

0 comments on commit 4b2586d

Please sign in to comment.