ConfigurationCommands implements Converter { static int compareConfigurations(Configuration a, Configuration b) { String factoryA = a.getFactoryPid(); String factoryB = b.getFactoryPid(); int result = 0; if (factoryA != null) { if (factoryB == null) result = -1; else result = factoryA.compareTo(factoryB); } else { if (factoryB == null) result = 0; else result = 1; } if (result == 0) result = a.getPid().compareTo(b.getPid()); return result; } ConfigurationCommands(ConfigurationAdmin configAdmin); @Descriptor("List configurations") Configuration[] list(); @Descriptor("List confgurations") Configuration[] list(@Descriptor("PID prefix") String prefix); Object info(String pid); @Override Object convert(Class<?> desiredType, Object in); @Override CharSequence format(Object target, int level, Converter escape);  }
@Test public void testCompareConfigs() { assertEquals(1, ConfigurationCommands.compareConfigurations(createMockConfig(null, ""), createMockConfig("", ""))); assertEquals(-1, ConfigurationCommands.compareConfigurations(createMockConfig("", ""), createMockConfig(null, ""))); assertEquals(0, ConfigurationCommands.compareConfigurations(createMockConfig(null, ""), createMockConfig(null, ""))); assertEquals(-1, ConfigurationCommands.compareConfigurations(createMockConfig("aaa", "yyy"), createMockConfig("bbb", "xxx"))); assertEquals(1, ConfigurationCommands.compareConfigurations(createMockConfig("bbb", "xxx"), createMockConfig("aaa", "yyy"))); assertEquals(-1, ConfigurationCommands.compareConfigurations(createMockConfig("aaa", "xxx"), createMockConfig("aaa", "yyy"))); assertEquals(1, ConfigurationCommands.compareConfigurations(createMockConfig("aaa", "yyy"), createMockConfig("aaa", "xxx"))); assertEquals(0, ConfigurationCommands.compareConfigurations(createMockConfig("aaa", "xxx"), createMockConfig("aaa", "xxx"))); }