17
17
package com .google .gcloud .compute ;
18
18
19
19
import static org .junit .Assert .assertEquals ;
20
+ import static org .junit .Assert .assertFalse ;
20
21
import static org .junit .Assert .assertNull ;
21
22
import static org .junit .Assert .assertSame ;
23
+ import static org .junit .Assert .assertTrue ;
22
24
25
+ import org .junit .Rule ;
23
26
import org .junit .Test ;
27
+ import org .junit .rules .ExpectedException ;
24
28
25
29
public class DiskTypeIdTest {
26
30
@@ -30,6 +34,9 @@ public class DiskTypeIdTest {
30
34
private static final String URL =
31
35
"https://www.googleapis.com/compute/v1/projects/project/zones/zone/diskTypes/diskType" ;
32
36
37
+ @ Rule
38
+ public ExpectedException thrown = ExpectedException .none ();
39
+
33
40
@ Test
34
41
public void testOf () {
35
42
DiskTypeId diskTypeId = DiskTypeId .of (PROJECT , ZONE , DISK_TYPE );
@@ -48,6 +55,9 @@ public void testToAndFromUrl() {
48
55
DiskTypeId diskTypeId = DiskTypeId .of (PROJECT , ZONE , DISK_TYPE );
49
56
assertSame (diskTypeId , diskTypeId .setProjectId (PROJECT ));
50
57
compareDiskTypeId (diskTypeId , DiskTypeId .fromUrl (diskTypeId .toUrl ()));
58
+ thrown .expect (IllegalArgumentException .class );
59
+ thrown .expectMessage ("notMatchingUrl is not a valid disk type URL" );
60
+ diskTypeId = DiskTypeId .fromUrl ("notMatchingUrl" );
51
61
}
52
62
53
63
@ Test
@@ -57,6 +67,12 @@ public void testSetProjectId() {
57
67
compareDiskTypeId (diskTypeId , DiskTypeId .of (ZONE , DISK_TYPE ).setProjectId (PROJECT ));
58
68
}
59
69
70
+ @ Test
71
+ public void testMatchesUrl () {
72
+ assertTrue (DiskTypeId .matchesUrl (DiskTypeId .of (PROJECT , ZONE , DISK_TYPE ).toUrl ()));
73
+ assertFalse (DiskTypeId .matchesUrl ("notMatchingUrl" ));
74
+ }
75
+
60
76
private void compareDiskTypeId (DiskTypeId expected , DiskTypeId value ) {
61
77
assertEquals (expected , value );
62
78
assertEquals (expected .project (), expected .project ());
0 commit comments