### Question:
ServiceType implements Comparable<ServiceType> { public boolean matches(ServiceType serviceType) { if (serviceType == null) return false; if (equals(serviceType)) return true; if (isAbstractType()) { if (serviceType.isAbstractType()) { if (!getPrincipleTypeName().equals(serviceType.getPrincipleTypeName())) return false; return getConcreteTypeName().equals(serviceType.getConcreteTypeName()); } else { return false; } } else { if (serviceType.isAbstractType()) { return getPrincipleTypeName().equals(serviceType.getPrincipleTypeName()); } else { return getPrincipleTypeName().equals(serviceType.getPrincipleTypeName()); } } } ServiceType(String type); boolean isServiceURL(); boolean isAbstractType(); boolean isDefaultNamingAuthority(); String getConcreteTypeName(); String getPrincipleTypeName(); String getAbstractTypeName(); String getNamingAuthority(); boolean matches(ServiceType serviceType); int compareTo(ServiceType that); boolean equals(Object obj); int hashCode(); String asString(); @Override String toString(); static final String ANY_NAMING_AUTHORITY; static final String DEFAULT_NAMING_AUTHORITY; }### Answer:
@Test public void testMatch2() throws Exception { ServiceType st1 = new ServiceType("service:jmx:rmi"); ServiceType st2 = new ServiceType("service:jmx"); assert !st1.matches(st2); assert st2.matches(st1); st1 = new ServiceType("jmx:rmi"); st2 = new ServiceType("jmx"); assert !st1.matches(st2); assert st2.matches(st1); }
@Test public void testMatch3() throws Exception { ServiceType st1 = new ServiceType("service:jmx:http"); ServiceType st2 = new ServiceType("service:jmx:rmi"); assert !st1.matches(st2); assert !st2.matches(st1); st1 = new ServiceType("jmx:http"); st2 = new ServiceType("jmx:rmi"); assert !st1.matches(st2); assert !st2.matches(st1); st1 = new ServiceType("http"); st2 = new ServiceType("rmi"); assert !st1.matches(st2); assert !st2.matches(st1); }
@Test public void testMatch4() throws Exception { ServiceType st1 = new ServiceType("service:foo:rmi"); ServiceType st2 = new ServiceType("service:bar:rmi"); assert !st1.matches(st2); assert !st2.matches(st1); st1 = new ServiceType("foo:rmi"); st2 = new ServiceType("bar:rmi"); assert !st1.matches(st2); assert !st2.matches(st1); st1 = new ServiceType("foo:rmi"); st2 = new ServiceType("rmi"); assert !st1.matches(st2); assert !st2.matches(st1); }
@Test public void testMatch5() throws Exception { ServiceType st1 = new ServiceType("service:foo:rmi"); ServiceType st2 = new ServiceType("foo:rmi"); assert st1.matches(st2); assert st2.matches(st1); }
@Test public void testMatch1() throws Exception { ServiceType st1 = new ServiceType("service:jmx:rmi"); ServiceType st2 = new ServiceType("service:jmx:rmi"); assert st1.matches(st2); assert st2.matches(st1); st1 = new ServiceType("jmx:rmi"); st2 = new ServiceType("jmx:rmi"); assert st1.matches(st2); assert st2.matches(st1); st1 = new ServiceType("rmi"); st2 = new ServiceType("rmi"); assert st1.matches(st2); assert st2.matches(st1); }