16
16
17
17
package com .google .common .graph ;
18
18
19
+ import static com .google .common .graph .GraphConstants .ENDPOINTS_MISMATCH ;
19
20
import static com .google .common .truth .Truth .assertThat ;
20
- import static com .google .common .truth .Truth8 .assertThat ;
21
21
import static com .google .common .truth .TruthJUnit .assume ;
22
22
import static org .junit .Assert .assertTrue ;
23
23
import static org .junit .Assert .fail ;
24
24
25
25
import com .google .common .collect .ImmutableSet ;
26
26
import com .google .common .testing .EqualsTester ;
27
+ import java .util .Optional ;
27
28
import java .util .Set ;
28
29
import org .junit .After ;
29
30
import org .junit .Test ;
@@ -196,29 +197,41 @@ public void successors_checkReturnedSetMutability() {
196
197
@ Test
197
198
public void edges_containsOrderMismatch () {
198
199
addEdge (N1 , N2 , E12 );
199
- assertThat (network .asGraph ().edges ()).contains (ENDPOINTS_N2N1 );
200
- assertThat (network .asGraph ().edges ()).contains (ENDPOINTS_N1N2 );
200
+ assertThat (network .asGraph ().edges ()).doesNotContain (ENDPOINTS_N2N1 );
201
+ assertThat (network .asGraph ().edges ()).doesNotContain (ENDPOINTS_N1N2 );
201
202
}
202
203
203
204
@ Test
204
205
public void edgesConnecting_orderMismatch () {
205
206
addEdge (N1 , N2 , E12 );
206
- assertThat (network .edgesConnecting (ENDPOINTS_N2N1 )).containsExactly (E12 );
207
- assertThat (network .edgesConnecting (ENDPOINTS_N1N2 )).containsExactly (E12 );
207
+ try {
208
+ Set <String > unused = network .edgesConnecting (ENDPOINTS_N1N2 );
209
+ fail ("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH );
210
+ } catch (IllegalArgumentException e ) {
211
+ assertThat (e ).hasMessageThat ().contains (ENDPOINTS_MISMATCH );
212
+ }
208
213
}
209
214
210
215
@ Test
211
216
public void edgeConnecting_orderMismatch () {
212
217
addEdge (N1 , N2 , E12 );
213
- assertThat (network .edgeConnecting (ENDPOINTS_N2N1 )).hasValue (E12 );
214
- assertThat (network .edgeConnecting (ENDPOINTS_N1N2 )).hasValue (E12 );
218
+ try {
219
+ Optional <String > unused = network .edgeConnecting (ENDPOINTS_N1N2 );
220
+ fail ("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH );
221
+ } catch (IllegalArgumentException e ) {
222
+ assertThat (e ).hasMessageThat ().contains (ENDPOINTS_MISMATCH );
223
+ }
215
224
}
216
225
217
226
@ Test
218
227
public void edgeConnectingOrNull_orderMismatch () {
219
228
addEdge (N1 , N2 , E12 );
220
- assertThat (network .edgeConnectingOrNull (ENDPOINTS_N2N1 )).isEqualTo (E12 );
221
- assertThat (network .edgeConnectingOrNull (ENDPOINTS_N1N2 )).isEqualTo (E12 );
229
+ try {
230
+ String unused = network .edgeConnectingOrNull (ENDPOINTS_N1N2 );
231
+ fail ("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH );
232
+ } catch (IllegalArgumentException e ) {
233
+ assertThat (e ).hasMessageThat ().contains (ENDPOINTS_MISMATCH );
234
+ }
222
235
}
223
236
224
237
@ Test
@@ -433,7 +446,7 @@ public void addEdge_existingEdgeBetweenDifferentNodes() {
433
446
networkAsMutableNetwork .addEdge (N4 , N5 , E12 );
434
447
fail (ERROR_ADDED_EXISTING_EDGE );
435
448
} catch (IllegalArgumentException e ) {
436
- assertThat (e . getMessage () ).contains (ERROR_REUSE_EDGE );
449
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_REUSE_EDGE );
437
450
}
438
451
}
439
452
@@ -447,13 +460,13 @@ public void addEdge_parallelEdge_notAllowed() {
447
460
networkAsMutableNetwork .addEdge (N1 , N2 , EDGE_NOT_IN_GRAPH );
448
461
fail (ERROR_ADDED_PARALLEL_EDGE );
449
462
} catch (IllegalArgumentException e ) {
450
- assertThat (e . getMessage () ).contains (ERROR_PARALLEL_EDGE );
463
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_PARALLEL_EDGE );
451
464
}
452
465
try {
453
466
networkAsMutableNetwork .addEdge (N2 , N1 , EDGE_NOT_IN_GRAPH );
454
467
fail (ERROR_ADDED_PARALLEL_EDGE );
455
468
} catch (IllegalArgumentException e ) {
456
- assertThat (e . getMessage () ).contains (ERROR_PARALLEL_EDGE );
469
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_PARALLEL_EDGE );
457
470
}
458
471
}
459
472
@@ -473,7 +486,12 @@ public void addEdge_orderMismatch() {
473
486
assume ().that (graphIsMutable ()).isTrue ();
474
487
475
488
EndpointPair <Integer > endpoints = EndpointPair .ordered (N1 , N2 );
476
- assertThat (networkAsMutableNetwork .addEdge (endpoints , E12 )).isTrue ();
489
+ try {
490
+ networkAsMutableNetwork .addEdge (endpoints , E12 );
491
+ fail ("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH );
492
+ } catch (IllegalArgumentException e ) {
493
+ assertThat (e ).hasMessageThat ().contains (ENDPOINTS_MISMATCH );
494
+ }
477
495
}
478
496
479
497
@ Test
@@ -542,20 +560,20 @@ public void addEdge_existingEdgeBetweenDifferentNodes_selfLoops() {
542
560
networkAsMutableNetwork .addEdge (N1 , N2 , E11 );
543
561
fail ("Reusing an existing self-loop edge to connect different nodes succeeded" );
544
562
} catch (IllegalArgumentException e ) {
545
- assertThat (e . getMessage () ).contains (ERROR_REUSE_EDGE );
563
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_REUSE_EDGE );
546
564
}
547
565
try {
548
566
networkAsMutableNetwork .addEdge (N2 , N2 , E11 );
549
567
fail ("Reusing an existing self-loop edge to make a different self-loop edge succeeded" );
550
568
} catch (IllegalArgumentException e ) {
551
- assertThat (e . getMessage () ).contains (ERROR_REUSE_EDGE );
569
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_REUSE_EDGE );
552
570
}
553
571
addEdge (N1 , N2 , E12 );
554
572
try {
555
573
networkAsMutableNetwork .addEdge (N1 , N1 , E12 );
556
574
fail ("Reusing an existing edge to add a self-loop edge between different nodes succeeded" );
557
575
} catch (IllegalArgumentException e ) {
558
- assertThat (e . getMessage () ).contains (ERROR_REUSE_EDGE );
576
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_REUSE_EDGE );
559
577
}
560
578
}
561
579
@@ -570,7 +588,7 @@ public void addEdge_parallelSelfLoopEdge_notAllowed() {
570
588
networkAsMutableNetwork .addEdge (N1 , N1 , EDGE_NOT_IN_GRAPH );
571
589
fail ("Adding a parallel self-loop edge succeeded" );
572
590
} catch (IllegalArgumentException e ) {
573
- assertThat (e . getMessage () ).contains (ERROR_PARALLEL_EDGE );
591
+ assertThat (e ). hasMessageThat ( ).contains (ERROR_PARALLEL_EDGE );
574
592
}
575
593
}
576
594
0 commit comments