Skip to content

Commit 16f1934

Browse files
committed
sonar
1 parent ad68086 commit 16f1934

2 files changed

Lines changed: 38 additions & 28 deletions

File tree

core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/AffectedEntitiesUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private boolean updateShadowVariable(EntityVariablePair<Solution_> shadowVariabl
149149

150150
private void changeShadowVariableAndNotify(VariableUpdaterInfo<Solution_> shadowVariableReference, Object entity,
151151
Object newValue) {
152-
var variableDescriptor = (VariableDescriptor<Solution_>) shadowVariableReference.variableDescriptor();
152+
var variableDescriptor = shadowVariableReference.variableDescriptor();
153153
changeShadowVariableAndNotify(variableDescriptor, entity, newValue);
154154
}
155155

core/src/test/java/ai/timefold/solver/core/impl/util/ListBasedScalingOrderedSetTest.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class ListBasedScalingOrderedSetTest {
1515
void emptySetProperties() {
1616
var set = new ListBasedScalingOrderedSet<String>();
1717

18-
assertThat(set).isEmpty();
19-
assertThat(set).hasSize(0);
20-
assertThat(set).doesNotContain("test");
18+
assertThat(set)
19+
.doesNotContain("test")
20+
.isEmpty();
2121
}
2222

2323
@Test
@@ -27,8 +27,9 @@ void addSingleElement() {
2727
var changed = set.add("test");
2828

2929
assertThat(changed).isTrue();
30-
assertThat(set).hasSize(1);
31-
assertThat(set).contains("test");
30+
assertThat(set)
31+
.hasSize(1)
32+
.contains("test");
3233
}
3334

3435
@Test
@@ -39,8 +40,9 @@ void addDuplicateElement() {
3940
var changed = set.add("test");
4041

4142
assertThat(changed).isFalse();
42-
assertThat(set).hasSize(1);
43-
assertThat(set).containsExactly("test");
43+
assertThat(set)
44+
.hasSize(1)
45+
.containsExactly("test");
4446
}
4547

4648
@Test
@@ -50,8 +52,9 @@ void addAllWithNewElements() {
5052
var changed = set.addAll(Arrays.asList("a", "b", "c"));
5153

5254
assertThat(changed).isTrue();
53-
assertThat(set).hasSize(3);
54-
assertThat(set).containsExactly("a", "b", "c");
55+
assertThat(set)
56+
.hasSize(3)
57+
.containsExactly("a", "b", "c");
5558
}
5659

5760
@Test
@@ -63,8 +66,9 @@ void addAllWithDuplicateElements() {
6366
var changed = set.addAll(Arrays.asList("b", "c"));
6467

6568
assertThat(changed).isTrue();
66-
assertThat(set).hasSize(3);
67-
assertThat(set).containsExactly("a", "b", "c");
69+
assertThat(set)
70+
.hasSize(3)
71+
.containsExactly("a", "b", "c");
6872
}
6973

7074
@Test
@@ -76,8 +80,9 @@ void addAllWithAllDuplicateElements() {
7680
var changed = set.addAll(Arrays.asList("a", "b"));
7781

7882
assertThat(changed).isFalse();
79-
assertThat(set).hasSize(2);
80-
assertThat(set).containsExactly("a", "b");
83+
assertThat(set)
84+
.hasSize(2)
85+
.containsExactly("a", "b");
8186
}
8287

8388
@Test
@@ -99,8 +104,9 @@ void removeNonexistentElement() {
99104
var removed = set.remove("b");
100105

101106
assertThat(removed).isFalse();
102-
assertThat(set).hasSize(1);
103-
assertThat(set).contains("a");
107+
assertThat(set)
108+
.hasSize(1)
109+
.contains("a");
104110
}
105111

106112
@Test
@@ -144,9 +150,9 @@ void iteratorReturnsAllElements() {
144150

145151
var iterator = set.iterator();
146152

147-
assertThat(iterator.hasNext()).isTrue();
153+
assertThat(iterator).hasNext();
148154
assertThat(iterator.next()).isEqualTo("a");
149-
assertThat(iterator.hasNext()).isTrue();
155+
assertThat(iterator).hasNext();
150156
assertThat(iterator.next()).isEqualTo("b");
151157
assertThat(iterator.hasNext()).isFalse();
152158
}
@@ -168,8 +174,9 @@ void containsWorks() {
168174
var set = new ListBasedScalingOrderedSet<String>();
169175
set.add("a");
170176

171-
assertThat(set.contains("a")).isTrue();
172-
assertThat(set.contains("b")).isFalse();
177+
assertThat(set)
178+
.contains("a")
179+
.doesNotContain("b");
173180
}
174181

175182
@Test
@@ -178,15 +185,16 @@ void containsAllWorks() {
178185
set.add("a");
179186
set.add("b");
180187

181-
assertThat(set.containsAll(Arrays.asList("a", "b"))).isTrue();
188+
assertThat(set).containsAll(Arrays.asList("a", "b"));
182189
assertThat(set.containsAll(Arrays.asList("a", "c"))).isFalse();
183190
}
184191

185192
@Test
186193
void retainAllThrowsException() {
187194
var set = new ListBasedScalingOrderedSet<String>();
188195

189-
assertThatThrownBy(() -> set.retainAll(List.of("a")))
196+
var list = List.of("a");
197+
assertThatThrownBy(() -> set.retainAll(list))
190198
.isInstanceOf(UnsupportedOperationException.class)
191199
.hasMessageContaining("retainAll()");
192200
}
@@ -195,7 +203,8 @@ void retainAllThrowsException() {
195203
void removeAllThrowsException() {
196204
var set = new ListBasedScalingOrderedSet<String>();
197205

198-
assertThatThrownBy(() -> set.removeAll(List.of("a")))
206+
var list = List.of("a");
207+
assertThatThrownBy(() -> set.removeAll(list))
199208
.isInstanceOf(UnsupportedOperationException.class)
200209
.hasMessageContaining("removeAll()");
201210
}
@@ -227,7 +236,7 @@ void scalingFromListToSet() {
227236
// Verify it still works correctly
228237
assertThat(set).hasSize(ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD + 1);
229238
for (var i = 0; i <= ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD; i++) {
230-
assertThat(set.contains(i)).isTrue();
239+
assertThat(set).contains(i);
231240
}
232241
}
233242

@@ -252,10 +261,11 @@ void scalingFromSetToList() {
252261
set.remove(0);
253262

254263
// Verify it still works correctly
255-
assertThat(set).hasSize(ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD - 1);
256-
assertThat(set.contains(0)).isFalse();
264+
assertThat(set)
265+
.hasSize(ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD - 1)
266+
.doesNotContain(0);
257267
for (var i = 1; i < ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD; i++) {
258-
assertThat(set.contains(i)).isTrue();
268+
assertThat(set).contains(i);
259269
}
260270
}
261271

@@ -283,7 +293,7 @@ void addAllCausingScaling() {
283293
assertThat(changed).isTrue();
284294
assertThat(set).hasSize(ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD + 1);
285295
for (var i = 0; i <= ListBasedScalingOrderedSet.LIST_SIZE_THRESHOLD; i++) {
286-
assertThat(set.contains(i)).isTrue();
296+
assertThat(set).contains(i);
287297
}
288298
}
289299

0 commit comments

Comments
 (0)