### Question:
Crn { @Nullable public static Crn fromString(String input) { checkNotNull(input); Matcher matcher = CRN_PATTERN.matcher(input); if (!matcher.matches()) { return null; } String region = matcher.group(3); if (!Region.US_WEST_1.name.equals(region)) { throw new CrnParseException(String.format("%s is not a supported region", region)); } return new Crn.Builder() .setPartition(Partition.safeFromString(matcher.group(1))) .setService(Service.safeFromString(matcher.group(2))) .setAccountId(matcher.group(4)) .setResourceType(ResourceType.fromString(matcher.group(5))) .setResource(matcher.group(6)) .build(); } Crn(Partition partition,
            Service service,
            Region region,
            String accountId,
            ResourceType resourceType,
            String resource); Partition getPartition(); Service getService(); Region getRegion(); String getAccountId(); ResourceType getResourceType(); String getResource(); String getUserId(); @Override String toString(); @Nullable static Crn fromString(String input); static Crn safeFromString(String input); static boolean isCrn(@Nullable String input); @Override int hashCode(); @Override boolean equals(Object object); static Builder builder();  }### Answer:
@Test public void testFromString() { Crn crn = Crn.fromString(exampleCrn); assertEquals(Crn.Partition.CDP, crn.getPartition()); assertEquals(Crn.Service.IAM, crn.getService()); assertEquals(Crn.Region.US_WEST_1, crn.getRegion()); assertEquals("9d74eee4-1cad-45d7-b645-7ccf9edbb73d", crn.getAccountId()); assertEquals(Crn.ResourceType.USER, crn.getResourceType()); assertEquals("f3b8ed82-e712-4f89-bda7-be07183720d3", crn.getResource()); }
@Test public void testFromStringWithInvalidPattern() { assertNull(Crn.fromString(invalidCrnPattern)); }
@Test public void testInvalidCrnDueToPartition() { thrown.expect(CrnParseException.class); Crn.fromString(invalidCrnPartition); }
@Test public void testInvalidCrnDueToRegion() { thrown.expect(CrnParseException.class); Crn.fromString(invalidCrnRegion); }
@Test public void testInvalidCrnDueToService() { thrown.expect(CrnParseException.class); Crn.fromString(invalidCrnService); }
@Test public void testInvalidCrnDueToResourceType() { thrown.expect(CrnParseException.class); Crn.fromString(invalidCrnResourceType); }