@Test(expected = IllegalArgumentException.class) public void forbidDuplicatedType() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("TRK").build()) .build(); }
@Test(expected = IllegalArgumentException.class) public void forbidNullRelation() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addRelations("DIR" /* missing child */) .build(); }
public class ResourceTypeTreeTest { private final ResourceTypeTree tree = ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addType(ResourceType.builder("FIL").build()) .addType(ResourceType.builder("UTS").build()) .addRelations("TRK", "DIR") .addRelations("DIR", "FIL") .addRelations("DIR", "UTS") .build(); @Test public void getTypes() { assertThat(tree.getTypes().size(), is(4)); assertThat(qualifiers(tree.getTypes()), hasItems("TRK", "DIR", "FIL", "UTS")); } @Test public void getChildren() { assertThat(tree.getChildren("TRK").size(), is(1)); assertThat(tree.getChildren("TRK"), hasItems("DIR")); assertThat(tree.getChildren("DIR").size(), is(2)); assertThat(tree.getChildren("DIR"), hasItems("FIL", "UTS")); assertThat(tree.getChildren("FIL").size(), is(0)); } @Test public void getRoot() { assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build())); } @Test public void getLeaves() { assertThat(tree.getLeaves().size(), is(2)); assertThat(tree.getLeaves(), hasItems("FIL", "UTS")); } @Test(expected = IllegalArgumentException.class) public void forbidNullRelation() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addRelations("DIR" /* missing child */) .build(); } @Test(expected = IllegalArgumentException.class) public void forbidDuplicatedType() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("TRK").build()) .build(); } }
public ResourceType get(String qualifier) { ResourceType type = typeByQualifier.get(qualifier); return type != null ? type : ResourceType.builder(qualifier).build(); }
@Test public void getRoot() { assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build())); }