1
1
package org .jenkinsci .plugins .vsphere .tools ;
2
-
3
- import static org .junit .Assert .* ;
2
+ import static org . hamcrest . MatcherAssert . assertThat ;
3
+ import static org .junit .jupiter . api . Assertions . assertThrows ;
4
4
import static org .hamcrest .CoreMatchers .*;
5
5
import hudson .slaves .JNLPLauncher ;
6
6
import hudson .slaves .RetentionStrategy ;
13
13
import java .util .List ;
14
14
15
15
import org .jenkinsci .plugins .vSphereCloudSlaveTemplate ;
16
- import org .junit .Before ;
17
- import org .junit .Test ;
16
+ import org .junit .jupiter . api . BeforeEach ;
17
+ import org .junit .jupiter . api . Test ;
18
18
19
- public class CloudProvisioningAlgorithmTest {
19
+ class CloudProvisioningAlgorithmTest {
20
20
21
21
/** Used when faking up test data */
22
22
private int instanceNumber ;
23
23
24
- @ Before
25
- public void setup () {
24
+ @ BeforeEach
25
+ void setup () {
26
26
instanceNumber = 0 ;
27
27
}
28
28
29
29
@ Test
30
- public void findTemplateWithMostFreeCapacityGivenNoOptionsThenReturnsNull () {
30
+ void findTemplateWithMostFreeCapacityGivenNoOptionsThenReturnsNull () {
31
31
// Given
32
32
final List <CloudProvisioningRecord > emptyList = Collections .emptyList ();
33
33
@@ -39,7 +39,7 @@ public void findTemplateWithMostFreeCapacityGivenNoOptionsThenReturnsNull() {
39
39
}
40
40
41
41
@ Test
42
- public void findTemplateWithMostFreeCapacityGivenSomeActiveAndOneUnusedThenPrefersUnusedTemplate () {
42
+ void findTemplateWithMostFreeCapacityGivenSomeActiveAndOneUnusedThenPrefersUnusedTemplate () {
43
43
// Given
44
44
final CloudProvisioningRecord zeroOfTwo = createInstance (2 , 0 , 0 );
45
45
final CloudProvisioningRecord onePlannedOfTwo = createInstance (2 , 0 , 1 );
@@ -57,7 +57,7 @@ public void findTemplateWithMostFreeCapacityGivenSomeActiveAndOneUnusedThenPrefe
57
57
}
58
58
59
59
@ Test
60
- public void findTemplateWithMostFreeCapacityGivenEqualCapsThenDistributesTheLoadEvenly () {
60
+ void findTemplateWithMostFreeCapacityGivenEqualCapsThenDistributesTheLoadEvenly () {
61
61
// Given
62
62
final CloudProvisioningRecord a = createInstance (2 , 0 , 0 );
63
63
final CloudProvisioningRecord b = createInstance (2 , 0 , 0 );
@@ -69,7 +69,7 @@ public void findTemplateWithMostFreeCapacityGivenEqualCapsThenDistributesTheLoad
69
69
}
70
70
71
71
@ Test
72
- public void findTemplateWithMostFreeCapacityGivenEqualCapsButExistingUsageThenDistributesTheLoadEvenly () {
72
+ void findTemplateWithMostFreeCapacityGivenEqualCapsButExistingUsageThenDistributesTheLoadEvenly () {
73
73
// Given
74
74
final CloudProvisioningRecord a = createInstance (2 , 2 , 0 );
75
75
final CloudProvisioningRecord b = createInstance (2 , 1 , 0 );
@@ -81,7 +81,7 @@ public void findTemplateWithMostFreeCapacityGivenEqualCapsButExistingUsageThenDi
81
81
}
82
82
83
83
@ Test
84
- public void findTemplateWithMostFreeCapacityGivenNoCapsThenDistributesTheLoadEvenly () {
84
+ void findTemplateWithMostFreeCapacityGivenNoCapsThenDistributesTheLoadEvenly () {
85
85
// Given
86
86
final CloudProvisioningRecord a = createInstance (0 , 0 , 0 );
87
87
final CloudProvisioningRecord b = createInstance (0 , 0 , 0 );
@@ -93,12 +93,12 @@ public void findTemplateWithMostFreeCapacityGivenNoCapsThenDistributesTheLoadEve
93
93
}
94
94
95
95
@ Test
96
- public void findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly () {
96
+ void findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly () {
97
97
findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly (true );
98
98
}
99
99
100
100
@ Test
101
- public void findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly2 () {
101
+ void findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly2 () {
102
102
findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheLoadFairly (false );
103
103
}
104
104
@@ -114,12 +114,12 @@ private void findTemplateWithMostFreeCapacityGivenUnequalCapsThenDistributesTheL
114
114
}
115
115
116
116
@ Test
117
- public void findTemplateWithMostFreeCapacityGivenOneCappedAndOneUncappedThenDistributesTheLoadEvenlyUntilCapReached () {
117
+ void findTemplateWithMostFreeCapacityGivenOneCappedAndOneUncappedThenDistributesTheLoadEvenlyUntilCapReached () {
118
118
findTemplateWithMostFreeCapacityGivenDifferentCapnessThenDistributesTheLoadEvenlyUntilCapReached (true );
119
119
}
120
120
121
121
@ Test
122
- public void findTemplateWithMostFreeCapacityGivenOneUncappedAndOneCappedThenDistributesTheLoadEvenlyUntilCapReached () {
122
+ void findTemplateWithMostFreeCapacityGivenOneUncappedAndOneCappedThenDistributesTheLoadEvenlyUntilCapReached () {
123
123
findTemplateWithMostFreeCapacityGivenDifferentCapnessThenDistributesTheLoadEvenlyUntilCapReached (false );
124
124
}
125
125
@@ -150,22 +150,22 @@ private static void testScenario(List<CloudProvisioningRecord> records, CloudPro
150
150
}
151
151
152
152
@ Test
153
- public void toBigIntegerGivenTwoPow128MinusOneThenReturnsTwoPow128MinusOne () {
153
+ void toBigIntegerGivenTwoPow128MinusOneThenReturnsTwoPow128MinusOne () {
154
154
testToBigInteger (-1 , -1 , "340282366920938463463374607431768211455" );
155
155
}
156
156
157
157
@ Test
158
- public void toBigIntegerGivenTwoPow64PlusOneThenReturnsTwoPow64PlusOne () {
158
+ void toBigIntegerGivenTwoPow64PlusOneThenReturnsTwoPow64PlusOne () {
159
159
testToBigInteger (1 , 1 , "18446744073709551617" );
160
160
}
161
161
162
162
@ Test
163
- public void toBigIntegerGivenZeroThenReturnsZero () {
163
+ void toBigIntegerGivenZeroThenReturnsZero () {
164
164
testToBigInteger (0 , 0 , "0" );
165
165
}
166
166
167
167
@ Test
168
- public void toBigIntegerGivenPowersOfTwoThenReturnsPowersOfTwo () {
168
+ void toBigIntegerGivenPowersOfTwoThenReturnsPowersOfTwo () {
169
169
long lsb = 1 ;
170
170
long msb = 0 ;
171
171
BigInteger big = new BigInteger ("1" );
@@ -182,7 +182,7 @@ public void toBigIntegerGivenPowersOfTwoThenReturnsPowersOfTwo() {
182
182
}
183
183
}
184
184
185
- private void testToBigInteger (long msb , long lsb , String expected ) {
185
+ private static void testToBigInteger (long msb , long lsb , String expected ) {
186
186
// Given
187
187
final BigInteger expectedValue = new BigInteger (expected );
188
188
final byte [] expectedBytes = expectedValue .toByteArray ();
@@ -196,7 +196,7 @@ private void testToBigInteger(long msb, long lsb, String expected) {
196
196
}
197
197
198
198
@ Test
199
- public void findUnusedNameGivenZeroOfTwoExistsThenReturnsOneThenTwo () {
199
+ void findUnusedNameGivenZeroOfTwoExistsThenReturnsOneThenTwo () {
200
200
// Given
201
201
final CloudProvisioningRecord record = createInstance (2 , 0 , 0 );
202
202
final String prefix = record .getTemplate ().getCloneNamePrefix ();
@@ -215,7 +215,7 @@ public void findUnusedNameGivenZeroOfTwoExistsThenReturnsOneThenTwo() {
215
215
}
216
216
217
217
@ Test
218
- public void findUnusedNameGivenMiddleOfThreeStillExistsThenReturnsOneThenThree () {
218
+ void findUnusedNameGivenMiddleOfThreeStillExistsThenReturnsOneThenThree () {
219
219
// Given
220
220
final CloudProvisioningRecord record = createInstance (3 , 0 , 0 );
221
221
final String prefix = record .getTemplate ().getCloneNamePrefix ();
@@ -236,7 +236,7 @@ public void findUnusedNameGivenMiddleOfThreeStillExistsThenReturnsOneThenThree()
236
236
}
237
237
238
238
@ Test
239
- public void findUnusedNameGivenNoSpaceThenThrowsIllegalStateException () {
239
+ void findUnusedNameGivenNoSpaceThenThrowsIllegalStateException () {
240
240
// Given
241
241
final CloudProvisioningRecord record = createInstance (3 , 0 , 0 );
242
242
final String prefix = record .getTemplate ().getCloneNamePrefix ();
@@ -246,21 +246,16 @@ public void findUnusedNameGivenNoSpaceThenThrowsIllegalStateException() {
246
246
record .setCurrentlyUnwanted (unwanted , false );
247
247
record .addCurrentlyActive (active );
248
248
record .addCurrentlyPlanned (planned );
249
- final List <CloudProvisioningRecord > records = Arrays . asList (record );
249
+ final List <CloudProvisioningRecord > records = List . of (record );
250
250
final CloudProvisioningRecord shouldBeNull = CloudProvisioningAlgorithm .findTemplateWithMostFreeCapacity (records );
251
251
assertThat (shouldBeNull , nullValue ());
252
252
253
253
// When
254
- try {
255
- final String unexpected = CloudProvisioningAlgorithm .findUnusedName (record );
256
- fail ("Expected IllegalStateException, got '" + unexpected + "'." );
257
- } catch (IllegalStateException expected ) {
258
- // Then passed.
259
- }
254
+ assertThrows (IllegalStateException .class , () -> CloudProvisioningAlgorithm .findUnusedName (record ));
260
255
}
261
256
262
257
@ Test
263
- public void findUnusedNameGivenOneOfTwoHasEndedThenReturnsOne () {
258
+ void findUnusedNameGivenOneOfTwoHasEndedThenReturnsOne () {
264
259
// Given
265
260
final CloudProvisioningRecord record = createInstance (2 , 0 , 0 );
266
261
final String prefix = record .getTemplate ().getCloneNamePrefix ();
@@ -280,11 +275,11 @@ public void findUnusedNameGivenOneOfTwoHasEndedThenReturnsOne() {
280
275
}
281
276
282
277
@ Test
283
- public void findUnusedNameGivenUncappedInstancesThenReturnsUniqueNames () {
278
+ void findUnusedNameGivenUncappedInstancesThenReturnsUniqueNames () {
284
279
// Given
285
280
final CloudProvisioningRecord record = createInstance (0 , 5 , 6 );
286
281
final String prefix = record .getTemplate ().getCloneNamePrefix ();
287
- final List <String > actuals = new ArrayList <String >();
282
+ final List <String > actuals = new ArrayList <>();
288
283
289
284
// When
290
285
for (int i = 0 ; i < 100 ; i ++) {
@@ -294,7 +289,7 @@ public void findUnusedNameGivenUncappedInstancesThenReturnsUniqueNames() {
294
289
}
295
290
296
291
// Then
297
- final List <String > uniques = new ArrayList <String >(new LinkedHashSet <String >(actuals ));
292
+ final List <String > uniques = new ArrayList <>(new LinkedHashSet <>(actuals ));
298
293
assertThat (actuals , equalTo (uniques ));
299
294
assertThat (actuals , everyItem (startsWith (prefix )));
300
295
}
0 commit comments