Skip to content

Commit 1b313af

Browse files
committed
chore: minor adjustments
1 parent 1d28450 commit 1b313af

File tree

8 files changed

+111
-140
lines changed

8 files changed

+111
-140
lines changed

core/src/test/java/ai/timefold/solver/core/impl/domain/lookup/LookUpManagerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ void lookUpNull() {
2424

2525
@Test
2626
void resetWorkingObjects() {
27-
TestdataObjectIntegerId o = new TestdataObjectIntegerId(0);
28-
TestdataObjectIntegerId p = new TestdataObjectIntegerId(1);
27+
var o = new TestdataObjectIntegerId(0);
28+
var p = new TestdataObjectIntegerId(1);
2929
// The objects should be added during the reset
3030
lookUpManager.reset();
3131
for (Object fact : Arrays.asList(o, p)) {

core/src/test/java/ai/timefold/solver/core/impl/domain/variable/custom/CustomVariableListenerTest.java

+32-42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ai.timefold.solver.core.impl.domain.variable.custom;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatCode;
45
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
56
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
67
import static org.mockito.Mockito.verify;
@@ -9,10 +10,6 @@
910
import java.util.Arrays;
1011
import java.util.List;
1112

12-
import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore;
13-
import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor;
14-
import ai.timefold.solver.core.impl.domain.variable.descriptor.GenuineVariableDescriptor;
15-
import ai.timefold.solver.core.impl.score.director.InnerScoreDirector;
1613
import ai.timefold.solver.core.impl.testdata.domain.TestdataValue;
1714
import ai.timefold.solver.core.impl.testdata.domain.shadow.cyclic.TestdataSevenNonCyclicShadowedSolution;
1815
import ai.timefold.solver.core.impl.testdata.domain.shadow.cyclic.invalid.TestdataCyclicReferencedShadowedSolution;
@@ -43,7 +40,8 @@ void cyclicReferenced() {
4340

4441
@Test
4542
void nonCyclicWithSevenDisorderedShadows() {
46-
TestdataSevenNonCyclicShadowedSolution.buildSolutionDescriptor();
43+
assertThatCode(TestdataSevenNonCyclicShadowedSolution::buildSolutionDescriptor)
44+
.doesNotThrowAnyException();
4745
}
4846

4947
@Test
@@ -60,19 +58,18 @@ void basicVariableListenerWithListSourceVariable() {
6058

6159
@Test
6260
void extendedZigZag() {
63-
GenuineVariableDescriptor<TestdataExtendedShadowedSolution> variableDescriptor =
64-
TestdataExtendedShadowedParentEntity.buildVariableDescriptorForValue();
65-
InnerScoreDirector<TestdataExtendedShadowedSolution, SimpleScore> scoreDirector =
61+
var variableDescriptor = TestdataExtendedShadowedParentEntity.buildVariableDescriptorForValue();
62+
var scoreDirector =
6663
PlannerTestUtils.mockScoreDirector(variableDescriptor.getEntityDescriptor().getSolutionDescriptor());
6764

68-
TestdataValue val1 = new TestdataValue("1");
69-
TestdataValue val2 = new TestdataValue("2");
70-
TestdataValue val3 = new TestdataValue("3");
71-
TestdataExtendedShadowedParentEntity a = new TestdataExtendedShadowedParentEntity("a", null);
72-
TestdataExtendedShadowedParentEntity b = new TestdataExtendedShadowedParentEntity("b", null);
73-
TestdataExtendedShadowedChildEntity c = new TestdataExtendedShadowedChildEntity("c", null);
65+
var val1 = new TestdataValue("1");
66+
var val2 = new TestdataValue("2");
67+
var val3 = new TestdataValue("3");
68+
var a = new TestdataExtendedShadowedParentEntity("a", null);
69+
var b = new TestdataExtendedShadowedParentEntity("b", null);
70+
var c = new TestdataExtendedShadowedChildEntity("c", null);
7471

75-
TestdataExtendedShadowedSolution solution = new TestdataExtendedShadowedSolution("solution");
72+
var solution = new TestdataExtendedShadowedSolution("solution");
7673
solution.setEntityList(Arrays.asList(a, b, c));
7774
solution.setValueList(Arrays.asList(val1, val2, val3));
7875
scoreDirector.setWorkingSolution(solution);
@@ -110,24 +107,21 @@ void extendedZigZag() {
110107

111108
@Test
112109
void manyToMany() {
113-
EntityDescriptor<TestdataManyToManyShadowedSolution> entityDescriptor =
114-
TestdataManyToManyShadowedEntity.buildEntityDescriptor();
115-
GenuineVariableDescriptor<TestdataManyToManyShadowedSolution> primaryVariableDescriptor =
116-
entityDescriptor.getGenuineVariableDescriptor("primaryValue");
117-
GenuineVariableDescriptor<TestdataManyToManyShadowedSolution> secondaryVariableDescriptor =
118-
entityDescriptor.getGenuineVariableDescriptor("secondaryValue");
119-
InnerScoreDirector<TestdataManyToManyShadowedSolution, SimpleScore> scoreDirector =
110+
var entityDescriptor = TestdataManyToManyShadowedEntity.buildEntityDescriptor();
111+
var primaryVariableDescriptor = entityDescriptor.getGenuineVariableDescriptor("primaryValue");
112+
var secondaryVariableDescriptor = entityDescriptor.getGenuineVariableDescriptor("secondaryValue");
113+
var scoreDirector =
120114
PlannerTestUtils.mockScoreDirector(primaryVariableDescriptor.getEntityDescriptor().getSolutionDescriptor());
121115

122-
TestdataValue val1 = new TestdataValue("1");
123-
TestdataValue val2 = new TestdataValue("2");
124-
TestdataValue val3 = new TestdataValue("3");
125-
TestdataValue val4 = new TestdataValue("4");
126-
TestdataManyToManyShadowedEntity a = new TestdataManyToManyShadowedEntity("a", null, null);
127-
TestdataManyToManyShadowedEntity b = new TestdataManyToManyShadowedEntity("b", null, null);
128-
TestdataManyToManyShadowedEntity c = new TestdataManyToManyShadowedEntity("c", null, null);
116+
var val1 = new TestdataValue("1");
117+
var val2 = new TestdataValue("2");
118+
var val3 = new TestdataValue("3");
119+
var val4 = new TestdataValue("4");
120+
var a = new TestdataManyToManyShadowedEntity("a", null, null);
121+
var b = new TestdataManyToManyShadowedEntity("b", null, null);
122+
var c = new TestdataManyToManyShadowedEntity("c", null, null);
129123

130-
TestdataManyToManyShadowedSolution solution = new TestdataManyToManyShadowedSolution("solution");
124+
var solution = new TestdataManyToManyShadowedSolution("solution");
131125
solution.setEntityList(Arrays.asList(a, b, c));
132126
solution.setValueList(Arrays.asList(val1, val2, val3, val4));
133127
scoreDirector.setWorkingSolution(solution);
@@ -180,18 +174,14 @@ void manyToMany() {
180174

181175
@Test
182176
void manyToManyRequiresUniqueEntityEvents() {
183-
EntityDescriptor<TestdataManyToManyShadowedSolution> entityDescriptor =
184-
TestdataManyToManyShadowedEntityUniqueEvents.buildEntityDescriptor();
185-
GenuineVariableDescriptor<TestdataManyToManyShadowedSolution> primaryVariableDescriptor =
186-
entityDescriptor.getGenuineVariableDescriptor("primaryValue");
187-
GenuineVariableDescriptor<TestdataManyToManyShadowedSolution> secondaryVariableDescriptor =
188-
entityDescriptor.getGenuineVariableDescriptor("secondaryValue");
189-
InnerScoreDirector<TestdataManyToManyShadowedSolution, SimpleScore> scoreDirector =
190-
PlannerTestUtils.mockScoreDirector(entityDescriptor.getSolutionDescriptor());
191-
192-
TestdataValue val1 = new TestdataValue("1");
193-
TestdataManyToManyShadowedEntityUniqueEvents b = new TestdataManyToManyShadowedEntityUniqueEvents("b", null, null);
194-
TestdataManyToManyShadowedSolution solution = new TestdataManyToManyShadowedSolution("solution");
177+
var entityDescriptor = TestdataManyToManyShadowedEntityUniqueEvents.buildEntityDescriptor();
178+
var primaryVariableDescriptor = entityDescriptor.getGenuineVariableDescriptor("primaryValue");
179+
var secondaryVariableDescriptor = entityDescriptor.getGenuineVariableDescriptor("secondaryValue");
180+
var scoreDirector = PlannerTestUtils.mockScoreDirector(entityDescriptor.getSolutionDescriptor());
181+
182+
var val1 = new TestdataValue("1");
183+
var b = new TestdataManyToManyShadowedEntityUniqueEvents("b", null, null);
184+
var solution = new TestdataManyToManyShadowedSolution("solution");
195185
solution.setEntityList(new ArrayList<>());
196186
solution.setValueList(List.of(val1));
197187
scoreDirector.setWorkingSolution(solution);

core/src/test/java/ai/timefold/solver/core/impl/domain/variable/descriptor/GenuineVariableDescriptorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ class GenuineVariableDescriptorTest {
1616

1717
@Test
1818
void isReinitializable() {
19-
GenuineVariableDescriptor<?> variableDescriptor = TestdataEntity.buildVariableDescriptorForValue();
19+
var variableDescriptor = TestdataEntity.buildVariableDescriptorForValue();
2020
assertThat(variableDescriptor.isReinitializable(new TestdataEntity("a", new TestdataValue()))).isFalse();
2121
assertThat(variableDescriptor.isReinitializable(new TestdataEntity("b", null))).isTrue();
2222
}
2323

2424
@Test
2525
void isReinitializable_allowsUnassigned() {
26-
GenuineVariableDescriptor<?> variableDescriptor = TestdataAllowsUnassignedEntity.buildVariableDescriptorForValue();
26+
var variableDescriptor = TestdataAllowsUnassignedEntity.buildVariableDescriptorForValue();
2727
assertThat(variableDescriptor.isReinitializable(new TestdataAllowsUnassignedEntity("a", new TestdataValue())))
2828
.isFalse();
2929
assertThat(variableDescriptor.isReinitializable(new TestdataAllowsUnassignedEntity("b", null))).isTrue();
3030
}
3131

3232
@Test
3333
void isReinitializable_list() {
34-
GenuineVariableDescriptor<?> variableDescriptor = TestdataListEntity.buildVariableDescriptorForValueList();
34+
var variableDescriptor = TestdataListEntity.buildVariableDescriptorForValueList();
3535
assertThat(variableDescriptor.isReinitializable(new TestdataListEntity("a", new TestdataListValue()))).isFalse();
3636
assertThat(variableDescriptor.isReinitializable(new TestdataListEntity("b", new ArrayList<>()))).isFalse();
3737
}

core/src/test/java/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupportTest.java

+24-37
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717

1818
import ai.timefold.solver.core.api.function.QuadConsumer;
1919
import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore;
20-
import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore;
21-
import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor;
22-
import ai.timefold.solver.core.impl.domain.solution.descriptor.SolutionDescriptor;
2320
import ai.timefold.solver.core.impl.domain.variable.declarative.DefaultTopologicalOrderGraph;
2421
import ai.timefold.solver.core.impl.domain.variable.declarative.EntityVariablePair;
2522
import ai.timefold.solver.core.impl.domain.variable.declarative.TopologicalOrderGraph;
2623
import ai.timefold.solver.core.impl.domain.variable.descriptor.VariableDescriptor;
2724
import ai.timefold.solver.core.impl.domain.variable.inverserelation.ExternalizedSingletonInverseVariableSupply;
2825
import ai.timefold.solver.core.impl.domain.variable.inverserelation.SingletonInverseVariableDemand;
2926
import ai.timefold.solver.core.impl.domain.variable.inverserelation.SingletonInverseVariableListener;
30-
import ai.timefold.solver.core.impl.domain.variable.inverserelation.SingletonInverseVariableSupply;
3127
import ai.timefold.solver.core.impl.domain.variable.supply.SupplyManager;
3228
import ai.timefold.solver.core.impl.score.director.InnerScoreDirector;
3329
import ai.timefold.solver.core.impl.testdata.domain.TestdataEntity;
@@ -40,7 +36,6 @@
4036
import ai.timefold.solver.core.impl.testdata.domain.declarative.concurrent.TestdataConcurrentSolution;
4137
import ai.timefold.solver.core.impl.testdata.domain.declarative.concurrent.TestdataConcurrentValue;
4238
import ai.timefold.solver.core.impl.testdata.domain.shadow.order.TestdataShadowVariableOrderEntity;
43-
import ai.timefold.solver.core.impl.testdata.domain.shadow.order.TestdataShadowVariableOrderSolution;
4439
import ai.timefold.solver.core.preview.api.domain.metamodel.VariableMetaModel;
4540

4641
import org.junit.jupiter.api.Test;
@@ -49,33 +44,32 @@ class VariableListenerSupportTest {
4944

5045
@Test
5146
void demandBasic() {
52-
SolutionDescriptor<TestdataSolution> solutionDescriptor = TestdataSolution.buildSolutionDescriptor();
53-
InnerScoreDirector<TestdataSolution, SimpleScore> scoreDirector = mock(InnerScoreDirector.class);
47+
var solutionDescriptor = TestdataSolution.buildSolutionDescriptor();
48+
var scoreDirector = mock(InnerScoreDirector.class);
5449
when(scoreDirector.getSolutionDescriptor()).thenReturn(solutionDescriptor);
55-
TestdataSolution solution = new TestdataSolution();
50+
var solution = new TestdataSolution();
5651
solution.setEntityList(Collections.emptyList());
5752
when(scoreDirector.getWorkingSolution()).thenReturn(solution);
5853
when(scoreDirector.getSupplyManager()).thenReturn(mock(SupplyManager.class));
5954
VariableListenerSupport<TestdataSolution> variableListenerSupport = VariableListenerSupport.create(scoreDirector);
6055
variableListenerSupport.linkVariableListeners();
6156

62-
VariableDescriptor<TestdataSolution> variableDescriptor =
63-
solutionDescriptor.getEntityDescriptorStrict(TestdataEntity.class)
64-
.getVariableDescriptor("value");
57+
var variableDescriptor = solutionDescriptor.getEntityDescriptorStrict(TestdataEntity.class)
58+
.getVariableDescriptor("value");
6559

66-
SingletonInverseVariableSupply supply1 = variableListenerSupport
60+
var supply1 = variableListenerSupport
6761
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
68-
SingletonInverseVariableSupply supply2 = variableListenerSupport
62+
var supply2 = variableListenerSupport
6963
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
7064
assertThat(supply2).isSameAs(supply1);
7165
}
7266

7367
@Test
7468
void demandChained() {
75-
SolutionDescriptor<TestdataChainedSolution> solutionDescriptor = TestdataChainedSolution.buildSolutionDescriptor();
76-
InnerScoreDirector<TestdataChainedSolution, SimpleScore> scoreDirector = mock(InnerScoreDirector.class);
69+
var solutionDescriptor = TestdataChainedSolution.buildSolutionDescriptor();
70+
var scoreDirector = mock(InnerScoreDirector.class);
7771
when(scoreDirector.getSolutionDescriptor()).thenReturn(solutionDescriptor);
78-
TestdataChainedSolution solution = new TestdataChainedSolution();
72+
var solution = new TestdataChainedSolution();
7973
solution.setChainedEntityList(Collections.emptyList());
8074
when(scoreDirector.getWorkingSolution()).thenReturn(solution);
8175
when(scoreDirector.getSupplyManager()).thenReturn(mock(SupplyManager.class));
@@ -87,55 +81,48 @@ void demandChained() {
8781
solutionDescriptor.getEntityDescriptorStrict(TestdataChainedEntity.class)
8882
.getVariableDescriptor("chainedObject");
8983

90-
SingletonInverseVariableSupply supply1 = variableListenerSupport
84+
var supply1 = variableListenerSupport
9185
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
9286
assertThat(supply1)
9387
.isInstanceOf(ExternalizedSingletonInverseVariableSupply.class);
94-
SingletonInverseVariableSupply supply2 = variableListenerSupport
88+
var supply2 = variableListenerSupport
9589
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
9690
assertThat(supply2).isSameAs(supply1);
9791
}
9892

9993
@Test
10094
void demandRichChained() {
101-
SolutionDescriptor<TestdataShadowingChainedSolution> solutionDescriptor =
102-
TestdataShadowingChainedSolution.buildSolutionDescriptor();
103-
InnerScoreDirector<TestdataShadowingChainedSolution, SimpleScore> scoreDirector =
104-
mock(InnerScoreDirector.class);
95+
var solutionDescriptor = TestdataShadowingChainedSolution.buildSolutionDescriptor();
96+
var scoreDirector = mock(InnerScoreDirector.class);
10597
when(scoreDirector.getSolutionDescriptor()).thenReturn(solutionDescriptor);
106-
TestdataShadowingChainedSolution solution = new TestdataShadowingChainedSolution();
98+
var solution = new TestdataShadowingChainedSolution();
10799
solution.setChainedEntityList(Collections.emptyList());
108100
when(scoreDirector.getWorkingSolution()).thenReturn(solution);
109101
when(scoreDirector.getSupplyManager()).thenReturn(mock(SupplyManager.class));
110-
VariableListenerSupport<TestdataShadowingChainedSolution> variableListenerSupport =
111-
VariableListenerSupport.create(scoreDirector);
102+
var variableListenerSupport = VariableListenerSupport.create(scoreDirector);
112103
variableListenerSupport.linkVariableListeners();
113104

114-
VariableDescriptor<TestdataShadowingChainedSolution> variableDescriptor = solutionDescriptor
105+
var variableDescriptor = solutionDescriptor
115106
.getEntityDescriptorStrict(TestdataShadowingChainedEntity.class)
116107
.getVariableDescriptor("chainedObject");
117108

118-
SingletonInverseVariableSupply supply1 = variableListenerSupport
119-
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
109+
var supply1 = variableListenerSupport.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
120110
assertThat(supply1)
121111
.isInstanceOf(SingletonInverseVariableListener.class);
122-
SingletonInverseVariableSupply supply2 = variableListenerSupport
123-
.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
112+
var supply2 = variableListenerSupport.demand(new SingletonInverseVariableDemand<>(variableDescriptor));
124113
assertThat(supply2).isSameAs(supply1);
125114
}
126115

127116
@Test
128117
void shadowVariableListenerOrder() {
129-
EntityDescriptor<TestdataShadowVariableOrderSolution> entityDescriptor =
130-
TestdataShadowVariableOrderEntity.buildEntityDescriptor();
131-
SolutionDescriptor<TestdataShadowVariableOrderSolution> solutionDescriptor = entityDescriptor.getSolutionDescriptor();
132-
InnerScoreDirector<TestdataShadowVariableOrderSolution, SimpleScore> scoreDirector = mock(InnerScoreDirector.class);
118+
var entityDescriptor = TestdataShadowVariableOrderEntity.buildEntityDescriptor();
119+
var solutionDescriptor = entityDescriptor.getSolutionDescriptor();
120+
var scoreDirector = mock(InnerScoreDirector.class);
133121
when(scoreDirector.getSolutionDescriptor()).thenReturn(solutionDescriptor);
134122
when(scoreDirector.getSolutionDescriptor()).thenReturn(solutionDescriptor);
135123

136-
NotifiableRegistry<TestdataShadowVariableOrderSolution> registry = new NotifiableRegistry<>(solutionDescriptor);
137-
VariableListenerSupport<TestdataShadowVariableOrderSolution> variableListenerSupport =
138-
new VariableListenerSupport<>(scoreDirector, registry, DefaultTopologicalOrderGraph::new);
124+
var registry = new NotifiableRegistry<>(solutionDescriptor);
125+
var variableListenerSupport = new VariableListenerSupport<>(scoreDirector, registry, DefaultTopologicalOrderGraph::new);
139126

140127
variableListenerSupport.linkVariableListeners();
141128

0 commit comments

Comments
 (0)