1717package com .google .gcloud .compute ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertFalse ;
2021import static org .junit .Assert .assertNull ;
2122import static org .junit .Assert .assertSame ;
23+ import static org .junit .Assert .assertTrue ;
2224
25+ import org .junit .Rule ;
2326import org .junit .Test ;
27+ import org .junit .rules .ExpectedException ;
2428
2529public class DiskTypeIdTest {
2630
@@ -30,6 +34,9 @@ public class DiskTypeIdTest {
3034 private static final String URL =
3135 "https://www.googleapis.com/compute/v1/projects/project/zones/zone/diskTypes/diskType" ;
3236
37+ @ Rule
38+ public ExpectedException thrown = ExpectedException .none ();
39+
3340 @ Test
3441 public void testOf () {
3542 DiskTypeId diskTypeId = DiskTypeId .of (PROJECT , ZONE , DISK_TYPE );
@@ -48,6 +55,9 @@ public void testToAndFromUrl() {
4855 DiskTypeId diskTypeId = DiskTypeId .of (PROJECT , ZONE , DISK_TYPE );
4956 assertSame (diskTypeId , diskTypeId .setProjectId (PROJECT ));
5057 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" );
5161 }
5262
5363 @ Test
@@ -57,6 +67,12 @@ public void testSetProjectId() {
5767 compareDiskTypeId (diskTypeId , DiskTypeId .of (ZONE , DISK_TYPE ).setProjectId (PROJECT ));
5868 }
5969
70+ @ Test
71+ public void testMatchesUrl () {
72+ assertTrue (DiskTypeId .matchesUrl (DiskTypeId .of (PROJECT , ZONE , DISK_TYPE ).toUrl ()));
73+ assertFalse (DiskTypeId .matchesUrl ("notMatchingUrl" ));
74+ }
75+
6076 private void compareDiskTypeId (DiskTypeId expected , DiskTypeId value ) {
6177 assertEquals (expected , value );
6278 assertEquals (expected .project (), expected .project ());
0 commit comments