Plugin { public PluginDiff compare(Plugin pluginB) { final PluginDiff result = new PluginDiff(); if (pluginB == null) { return result.mismatch("second plugin is null"); } if (!this.getDocumentType().equals(pluginB.getDocumentType())) { return result.mismatch("types differ"); } if (!this.getDocumentName().equals(pluginB.getDocumentName())) { return result.mismatch("names differ"); } final LoopDescriptor[] loopsOfB = pluginB.loops; if (loops == null) { if (loopsOfB != null) { return result.mismatch("second plugin has non-null loops while this plugin does not"); } } else { if (loopsOfB == null) { return result.mismatch("second plugin has null loops while this plugin does not"); } if (loops.length != loopsOfB.length) { return result.mismatch("second plugin has a different number of loops than this plugin"); } } result.setMatch(true); return result; } Plugin(String documentType, String documentName); protected  Plugin(String documentType, String documentName, boolean validating); void init(); String getDocumentType(); String getDocumentName(); LoopDescriptor[] getLoopDescriptors(); LoopDescriptor query(String segment, String currentLoopStack, int currentLevel, Set<String> resultFlags); static int getCount(); @Override String toString(); void prepare(); boolean isValidating(); PluginControllerImpl createController(String standard, Tokenizer tokenizer); String getDocumentVersion(); PluginDiff compare(Plugin pluginB); static final String ANY_CONTEXT; static final String INITIAL_CONTEXT; static final String CURRENT; }
@Test public void comparePluginToItself() { final CompositeAwarePlugin pluginA = new CompositeAwarePlugin("210", "Motor Carrier Freight Details and Invoice") { }; diff = pluginA.compare(pluginA); assertTrue(diff.isMatch()); assertEquals("matches", diff.getReason()); }
@Test public void comparePluginToNull() { final CompositeAwarePlugin pluginA = new CompositeAwarePlugin("210", "Motor Carrier Freight Details and Invoice") { }; diff = pluginA.compare(null); assertFalse(diff.isMatch()); assertEquals("second plugin is null", diff.getReason()); }
@Test public void comparedTypesMustMatch() { final CompositeAwarePlugin pluginA = new CompositeAwarePlugin("210", "Motor Carrier Freight Details and Invoice") { }; final CompositeAwarePlugin pluginB = new CompositeAwarePlugin("211", "Motor Carrier Freight Details and Invoice") { }; diff = pluginA.compare(pluginB); assertFalse(diff.isMatch()); assertEquals("types differ", diff.getReason()); }
@Test public void comparedNamesMustMatch() { final CompositeAwarePlugin pluginA = new CompositeAwarePlugin("210", "Motor Carrier Freight Details and Invoice") { }; final CompositeAwarePlugin pluginB = new CompositeAwarePlugin("210", "Motor Carrier Freight Details & Invoice") { }; diff = pluginA.compare(pluginB); assertFalse(diff.isMatch()); assertEquals("names differ", diff.getReason()); }
@Test public void comparedDescriptorCountMustMatch() { diff = new PluginA1().compare(new PluginA2()); assertFalse(diff.isMatch()); assertEquals("second plugin has a different number of loops than this plugin", diff.getReason()); }