Infrastructure extends Base implements Flavorful, Named { public void setName(String name) { this.name = name; }  String getName(); void setName(String name); String getFlavor(); void setFlavor(String flavor); List<QuotaLineItem> getCost(); void setCost(List<QuotaLineItem> cost); Set<String> getTags(); void setTags(Set<String> tags); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testLongName() throws Exception { String longName = new String(new char[64]).replace('\0', 'a'); InfrastructureExample infra = new InfrastructureExample(); infra.setName(longName); ImmutableList<String> violations = validator.validate(infra); assertThat(violations.size(), is(1)); assertThat(violations.get(0), containsString("name size must be between 1 and 63")); }
@Test public void testBadNames() throws Exception { List<String> badNames = ImmutableList.of("9to5", "^aaa", "test&me", "name with spaces", " no-trim "); for (String badName : badNames) { InfrastructureExample infra = new InfrastructureExample(); infra.setName(badName); ImmutableList<String> violations = validator.validate(infra); assertThat(violations.size(), is(1)); assertThat(violations.get(0), containsString("name must match \"^[a-zA-Z][a-zA-Z0-9-]*\"")); } }