13
13
*******************************************************************************/
14
14
package org .eclipse .core .tests .internal .builders ;
15
15
16
+ import static org .hamcrest .MatcherAssert .assertThat ;
17
+ import static org .hamcrest .Matchers .arrayContaining ;
18
+ import static org .hamcrest .Matchers .emptyArray ;
19
+
16
20
import org .eclipse .core .internal .events .BuildContext ;
17
21
import org .eclipse .core .internal .resources .BuildConfiguration ;
18
22
import org .eclipse .core .resources .IBuildConfiguration ;
@@ -91,8 +95,8 @@ private IBuildConfiguration changeActiveBuildConfig(IProject project) throws Cor
91
95
return config ;
92
96
}
93
97
}
94
- assertTrue ( false );
95
- return null ;
98
+ throw new IllegalStateException (
99
+ "No build config other than the active one could be found for project: " + project ) ;
96
100
}
97
101
98
102
/**
@@ -129,22 +133,22 @@ public void testBuildContext() {
129
133
IBuildContext context ;
130
134
131
135
context = new BuildContext (p0v0 , new IBuildConfiguration [] {p0v0 , p1v0 }, buildOrder );
132
- assertEquals ( "1.0" , new IBuildConfiguration [] {}, context .getAllReferencedBuildConfigs ());
133
- assertEquals ( "1.1" , new IBuildConfiguration [] { p0v1 , p1v0 }, context . getAllReferencingBuildConfigs ( ));
134
- assertEquals ( "1.2" , new IBuildConfiguration [] { p0v0 , p1v0 }, context . getRequestedConfigs ( ));
136
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray ());
137
+ assertThat ( context . getAllReferencingBuildConfigs (), arrayContaining ( p0v1 , p1v0 ));
138
+ assertThat ( context . getRequestedConfigs (), arrayContaining ( p0v0 , p1v0 ));
135
139
136
140
context = new BuildContext (p0v1 , buildOrder , buildOrder );
137
- assertEquals ( "2.0" , new IBuildConfiguration [] { p0v0 }, context .getAllReferencedBuildConfigs ());
138
- assertEquals ( "2.1" , new IBuildConfiguration [] { p1v0 }, context .getAllReferencingBuildConfigs ());
141
+ assertThat ( context .getAllReferencedBuildConfigs (), arrayContaining ( p0v0 ));
142
+ assertThat ( context .getAllReferencingBuildConfigs (), arrayContaining ( p1v0 ));
139
143
140
144
context = new BuildContext (p1v0 , buildOrder , buildOrder );
141
- assertEquals ( "3.0" , new IBuildConfiguration [] { p0v0 , p0v1 }, context . getAllReferencedBuildConfigs ( ));
142
- assertEquals ( "3.1" , new IBuildConfiguration [] {}, context .getAllReferencingBuildConfigs ());
145
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( p0v0 , p0v1 ));
146
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray ());
143
147
144
148
// And it works with no build context too
145
149
context = new BuildContext (p1v0 );
146
- assertEquals ( "4.0" , new IBuildConfiguration [] {}, context .getAllReferencedBuildConfigs ());
147
- assertEquals ( "4.1" , new IBuildConfiguration [] {}, context .getAllReferencingBuildConfigs ());
150
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray ());
151
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray ());
148
152
}
149
153
150
154
public void testSingleProjectBuild () throws CoreException {
@@ -153,20 +157,20 @@ public void testSingleProjectBuild() throws CoreException {
153
157
setupSimpleReferences ();
154
158
ContextBuilder .clearStats ();
155
159
project0 .build (IncrementalProjectBuilder .FULL_BUILD , getMonitor ());
156
- assertTrue ( "1.0" , ContextBuilder .checkValid () );
160
+ ContextBuilder .assertValid ( );
157
161
158
162
IBuildContext context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
159
- assertEquals ( "2.0" , 0 , context .getAllReferencedBuildConfigs (). length );
160
- assertEquals ( "2.1" , 0 , context .getAllReferencingBuildConfigs (). length );
163
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray () );
164
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray () );
161
165
162
166
// Change the active build configuration will cause the project to be rebuilt
163
167
ContextBuilder .clearStats ();
164
168
IBuildConfiguration newActive = changeActiveBuildConfig (project0 );
165
169
waitForBuild ();
166
- assertTrue ( "3.0" , ContextBuilder .checkValid () );
170
+ ContextBuilder .assertValid ( );
167
171
168
172
context = ContextBuilder .getContext (newActive );
169
- assertEquals ( "3.1" , 0 , context .getAllReferencedBuildConfigs (). length );
173
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray () );
170
174
}
171
175
172
176
/**
@@ -178,28 +182,30 @@ public void testWorkspaceBuildProject() throws CoreException {
178
182
179
183
// Build project and resolve references
180
184
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , true , getMonitor ());
181
- assertTrue ( "1.0" , ContextBuilder .checkValid () );
185
+ ContextBuilder .assertValid ( );
182
186
183
187
IBuildContext context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
184
- assertEquals ("2.0" , new IBuildConfiguration [] {project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()}, context .getAllReferencedBuildConfigs ());
185
- assertEquals ("2.1" , 0 , context .getAllReferencingBuildConfigs ().length );
188
+ assertThat (context .getAllReferencedBuildConfigs (),
189
+ arrayContaining (project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()));
190
+ assertThat (context .getAllReferencingBuildConfigs (), emptyArray ());
186
191
187
192
context = ContextBuilder .getBuilder (project1 .getActiveBuildConfig ()).contextForLastBuild ;
188
- assertEquals ( "3.0" , new IBuildConfiguration [] { project2 .getActiveBuildConfig ()}, context . getAllReferencedBuildConfigs ( ));
189
- assertEquals ( "3.1" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getAllReferencingBuildConfigs ( ));
193
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( project2 .getActiveBuildConfig ()));
194
+ assertThat ( context . getAllReferencingBuildConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
190
195
191
196
context = ContextBuilder .getBuilder (project2 .getActiveBuildConfig ()).contextForLastBuild ;
192
- assertEquals ("4.0" , 0 , context .getAllReferencedBuildConfigs ().length );
193
- assertEquals ("4.1" , new IBuildConfiguration [] {project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()}, context .getAllReferencingBuildConfigs ());
197
+ assertThat (context .getAllReferencedBuildConfigs (), emptyArray ());
198
+ assertThat (context .getAllReferencingBuildConfigs (),
199
+ arrayContaining (project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()));
194
200
195
201
// Build just project0
196
202
ContextBuilder .clearStats ();
197
203
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , false , getMonitor ());
198
- assertTrue ( "5.0" , ContextBuilder .checkValid () );
204
+ ContextBuilder .assertValid ( );
199
205
200
206
context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
201
- assertTrue ( "5.1" , context .getAllReferencedBuildConfigs (). length == 0 );
202
- assertTrue ( "5.2" , context .getAllReferencingBuildConfigs (). length == 0 );
207
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray () );
208
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray () );
203
209
}
204
210
205
211
/**
@@ -210,19 +216,21 @@ public void testWorkspaceBuildProjects() throws CoreException {
210
216
ContextBuilder .clearStats ();
211
217
// build project0 & project2 ; project1 will end up being built too.
212
218
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig (), project2 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , true , getMonitor ());
213
- assertTrue ( "1.0" , ContextBuilder .checkValid () );
219
+ ContextBuilder .assertValid ( );
214
220
215
221
IBuildContext context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
216
- assertEquals ("2.0" , new IBuildConfiguration [] {project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()}, context .getAllReferencedBuildConfigs ());
217
- assertEquals ("2.1" , 0 , context .getAllReferencingBuildConfigs ().length );
222
+ assertThat (context .getAllReferencedBuildConfigs (),
223
+ arrayContaining (project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()));
224
+ assertThat (context .getAllReferencingBuildConfigs (), emptyArray ());
218
225
219
226
context = ContextBuilder .getBuilder (project1 .getActiveBuildConfig ()).contextForLastBuild ;
220
- assertEquals ( "3.0" , new IBuildConfiguration [] { project2 .getActiveBuildConfig ()}, context . getAllReferencedBuildConfigs ( ));
221
- assertEquals ( "3.1" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getAllReferencingBuildConfigs ( ));
227
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( project2 .getActiveBuildConfig ()));
228
+ assertThat ( context . getAllReferencingBuildConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
222
229
223
230
context = ContextBuilder .getBuilder (project2 .getActiveBuildConfig ()).contextForLastBuild ;
224
- assertEquals ("4.0" , 0 , context .getAllReferencedBuildConfigs ().length );
225
- assertEquals ("4.1" , new IBuildConfiguration [] {project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()}, context .getAllReferencingBuildConfigs ());
231
+ assertThat (context .getAllReferencedBuildConfigs (), emptyArray ());
232
+ assertThat (context .getAllReferencingBuildConfigs (),
233
+ arrayContaining (project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()));
226
234
}
227
235
228
236
/**
@@ -235,19 +243,21 @@ public void testReferenceActiveVariant() throws CoreException {
235
243
236
244
ContextBuilder .clearStats ();
237
245
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , true , getMonitor ());
238
- assertTrue ( "1.0" , ContextBuilder .checkValid () );
246
+ ContextBuilder .assertValid ( );
239
247
240
248
IBuildContext context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
241
- assertEquals ("2.0" , new IBuildConfiguration [] {project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()}, context .getAllReferencedBuildConfigs ());
242
- assertEquals ("2.1" , 0 , context .getAllReferencingBuildConfigs ().length );
249
+ assertThat (context .getAllReferencedBuildConfigs (),
250
+ arrayContaining (project2 .getActiveBuildConfig (), project1 .getActiveBuildConfig ()));
251
+ assertThat (context .getAllReferencingBuildConfigs (), emptyArray ());
243
252
244
253
context = ContextBuilder .getBuilder (project1 .getActiveBuildConfig ()).contextForLastBuild ;
245
- assertEquals ( "3.0" , new IBuildConfiguration [] { project2 .getActiveBuildConfig ()}, context . getAllReferencedBuildConfigs ( ));
246
- assertEquals ( "3.1" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getAllReferencingBuildConfigs ( ));
254
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( project2 .getActiveBuildConfig ()));
255
+ assertThat ( context . getAllReferencingBuildConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
247
256
248
257
context = ContextBuilder .getBuilder (project2 .getActiveBuildConfig ()).contextForLastBuild ;
249
- assertEquals ("4.0" , 0 , context .getAllReferencedBuildConfigs ().length );
250
- assertEquals ("4.1" , new IBuildConfiguration [] {project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()}, context .getAllReferencingBuildConfigs ());
258
+ assertThat (context .getAllReferencedBuildConfigs (), emptyArray ());
259
+ assertThat (context .getAllReferencingBuildConfigs (),
260
+ arrayContaining (project1 .getActiveBuildConfig (), project0 .getActiveBuildConfig ()));
251
261
}
252
262
253
263
/**
@@ -262,27 +272,27 @@ public void testReferenceVariantTwice() throws CoreException {
262
272
263
273
ContextBuilder .clearStats ();
264
274
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , true , getMonitor ());
265
- assertTrue ( "1.0" , ContextBuilder .checkValid () );
275
+ ContextBuilder .assertValid ( );
266
276
267
277
IBuildContext context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
268
- assertEquals ( "2.0" , new IBuildConfiguration [] { project1 .getActiveBuildConfig ()}, context . getAllReferencedBuildConfigs ( ));
269
- assertEquals ( "2.1" , 0 , context .getAllReferencingBuildConfigs (). length );
270
- assertEquals ( "2.2" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getRequestedConfigs ( ));
278
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( project1 .getActiveBuildConfig ()));
279
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray () );
280
+ assertThat ( context . getRequestedConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
271
281
272
282
context = ContextBuilder .getBuilder (project1 .getActiveBuildConfig ()).contextForLastBuild ;
273
- assertEquals ( "3.0" , 0 , context .getAllReferencedBuildConfigs (). length );
274
- assertEquals ( "3.1" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getAllReferencingBuildConfigs ( ));
283
+ assertThat ( context .getAllReferencedBuildConfigs (), emptyArray () );
284
+ assertThat ( context . getAllReferencingBuildConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
275
285
276
286
// Change the active configuration of project1, and test that two configurations are built
277
287
ContextBuilder .clearStats ();
278
288
IBuildConfiguration project1PreviousActive = project1 .getActiveBuildConfig ();
279
289
IBuildConfiguration project1NewActive = changeActiveBuildConfig (project1 );
280
290
getWorkspace ().build (new IBuildConfiguration [] {project0 .getActiveBuildConfig ()}, IncrementalProjectBuilder .FULL_BUILD , true , getMonitor ());
281
- assertTrue ( "4.0" , ContextBuilder .checkValid () );
291
+ ContextBuilder .assertValid ( );
282
292
283
293
context = ContextBuilder .getContext (project0 .getActiveBuildConfig ());
284
- assertEquals ( "4.1" , new IBuildConfiguration [] { project1PreviousActive , project1NewActive }, context . getAllReferencedBuildConfigs ( ));
285
- assertEquals ( "4.2" , 0 , context .getAllReferencingBuildConfigs (). length );
286
- assertEquals ( "4.3" , new IBuildConfiguration [] { project0 .getActiveBuildConfig ()}, context . getRequestedConfigs ( ));
294
+ assertThat ( context . getAllReferencedBuildConfigs (), arrayContaining ( project1PreviousActive , project1NewActive ));
295
+ assertThat ( context .getAllReferencingBuildConfigs (), emptyArray () );
296
+ assertThat ( context . getRequestedConfigs (), arrayContaining ( project0 .getActiveBuildConfig ()));
287
297
}
288
298
}
0 commit comments