@@ -3041,16 +3041,24 @@ public void testInspectVolume() throws Exception {
3041
3041
final Volume volume = sut .createVolume ();
3042
3042
3043
3043
assertEquals (volume , sut .inspectVolume (volume .name ()));
3044
+ sut .removeVolume (volume );
3044
3045
3045
3046
final String badVolumeName = "this-is-a-very-unlikely-volume-name" ;
3046
- try {
3047
- sut .inspectVolume (badVolumeName );
3048
- fail ("We should not have found a volume with name " + badVolumeName );
3049
- } catch (VolumeNotFoundException e ) {
3050
- assertEquals (badVolumeName , e .getVolumeName ());
3051
- }
3052
3047
3053
- sut .removeVolume (volume );
3048
+ exception .expect (VolumeNotFoundException .class );
3049
+ exception .expect (volumeNotFoundExceptionWithName (badVolumeName ));
3050
+ sut .inspectVolume (badVolumeName );
3051
+ }
3052
+
3053
+ private static Matcher <VolumeNotFoundException >
3054
+ volumeNotFoundExceptionWithName (final String volumeName ) {
3055
+ final String description = "for volume name " + volumeName ;
3056
+ return new CustomTypeSafeMatcher <VolumeNotFoundException >(description ) {
3057
+ @ Override
3058
+ protected boolean matchesSafely (final VolumeNotFoundException e ) {
3059
+ return e .getVolumeName ().equals (volumeName );
3060
+ }
3061
+ };
3054
3062
}
3055
3063
3056
3064
@ Test
@@ -3113,12 +3121,9 @@ public void testRemoveVolume() throws Exception {
3113
3121
sut .removeVolume (volume1 );
3114
3122
3115
3123
// Remove non-existent volume
3116
- try {
3117
- sut .removeVolume (volume1 );
3118
- fail ("Should not be able to remove a non-existent volume." );
3119
- } catch (VolumeNotFoundException e ) {
3120
- assertEquals (volume1 .name (), e .getVolumeName ());
3121
- }
3124
+ exception .expect (VolumeNotFoundException .class );
3125
+ exception .expect (volumeNotFoundExceptionWithName (volume1 .name ()));
3126
+ sut .removeVolume (volume1 );
3122
3127
3123
3128
// Create a volume, assign it to a container, and try to remove it.
3124
3129
// Should get a ConflictException.
@@ -3131,12 +3136,11 @@ public void testRemoveVolume() throws Exception {
3131
3136
.hostConfig (hostConfig )
3132
3137
.build ();
3133
3138
final ContainerCreation container = sut .createContainer (config );
3134
- try {
3135
- sut .removeVolume (volume2 );
3136
- fail ("Should not be able to remove a volume in use by a container." );
3137
- } catch (ConflictException ignored ) {
3138
- // pass
3139
- }
3139
+
3140
+ exception .expect (ConflictException .class );
3141
+ sut .removeVolume (volume2 );
3142
+
3143
+ // Clean up
3140
3144
sut .removeContainer (container .id ());
3141
3145
sut .removeVolume (volume2 );
3142
3146
}
0 commit comments