DescriptorUtils { public static ClassDescriptor findSumType(Collection<ClassDescriptor> classes) throws MetaDataException { return findCommonClasses(classes).get(0); } private  DescriptorUtils(); static ClassDescriptor findSumType(Collection<ClassDescriptor> classes); static ClassDescriptor findIntersectionType(Collection<ClassDescriptor> classes); static List<ClassDescriptor> findCommonClasses(Collection<ClassDescriptor> classes);  }
@Test public void testSingleMember() throws MetaDataException { withClass("Employee"); String common = DescriptorUtils.findSumType(classes).getUnqualifiedName(); assertEquals(common, "Employee"); }
@Test public void testNull() throws MetaDataException { classes = null; try { DescriptorUtils.findSumType(classes); fail("No exception thrown"); } catch (IllegalArgumentException e) { } }
@Test public void testEmptySet() { try { DescriptorUtils.findSumType(classes); fail("No exception thrown"); } catch (MetaDataException e) { } }
@Test public void testIncompatibleTypes() { withClasses("Employee", "SimpleObject"); try { String common = DescriptorUtils.findSumType(classes).getUnqualifiedName(); fail("No exception thrown: " + common); } catch (MetaDataException e) { } }
@Test public void testDirectSubclass() throws MetaDataException { withClasses("Employee", "Address"); String common = DescriptorUtils.findSumType(classes).getUnqualifiedName(); assertEquals(common, "Thing"); }
@Test public void testDistantSubclass() throws MetaDataException { withClasses("Employable", "Manager"); String common = DescriptorUtils.findSumType(classes).getUnqualifiedName(); assertEquals(common, "Employable"); }
@Test public void testCommonCousins() throws MetaDataException { withClasses("Employable", "Address"); String common = DescriptorUtils.findSumType(classes).getUnqualifiedName(); assertEquals(common, "Thing"); }