class 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;
	}

}

class ConfigurationCommandsTest {

	@Test
	public void testCompareConfigs() {

		// factory before non-factory
		assertEquals(1, ConfigurationCommands.compareConfigurations(createMockConfig(null, ""), createMockConfig("", ""))); 
		assertEquals(-1, ConfigurationCommands.compareConfigurations(createMockConfig("", ""), createMockConfig(null, ""))); 
		assertEquals(0, ConfigurationCommands.compareConfigurations(createMockConfig(null, ""), createMockConfig(null, "")));
		
		// compare factory first
		assertEquals(-1, ConfigurationCommands.compareConfigurations(createMockConfig("aaa", "yyy"), createMockConfig("bbb", "xxx"))); 
		assertEquals(1, ConfigurationCommands.compareConfigurations(createMockConfig("bbb", "xxx"), createMockConfig("aaa", "yyy")));
		
		// compare pid second
		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")));
	}

}