### Question:
ColumnControlRewriteRule implements StructureRewriteRule { @Override public boolean matches(Node root) throws RepositoryException { if (!root.hasProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) { return false; } javax.jcr.Property prop = root.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY); if (!StringUtils.equals(resourceType, prop.getString())) { return false; } if (!root.hasProperty(PROP_LAYOUT)) { return false; } prop = root.getProperty(PROP_LAYOUT); if (!StringUtils.equals(layout, prop.getString())) { return false; } Node parent = root.getParent(); NodeIterator siblings = parent.getNodes(); while (siblings.hasNext()) { Node sibling = siblings.nextNode(); if (sibling.getName().equals(root.getName())) { break; } } int count = widths.length; while (siblings.hasNext()) { Node sibling = siblings.nextNode(); if (sibling.hasProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) && StringUtils.equals( sibling.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY).getString(), resourceType)) { if (sibling.hasProperty(PROP_LAYOUT) && count != 0) { return false; } else if (sibling.hasProperty(PROP_CONTROL_TYPE) && (StringUtils.equals(sibling.getProperty(PROP_CONTROL_TYPE).getString(), CONTROL_TYPE_BREAK) || StringUtils.equals(sibling.getProperty(PROP_CONTROL_TYPE).getString(), CONTROL_TYPE_END))) { count--; if (StringUtils.equals(sibling.getProperty(PROP_CONTROL_TYPE).getString(), CONTROL_TYPE_END)) { break; } } } } return count == 0; }  @Override boolean matches(Node root); @Override Node applyTo(Node root, Set<Node> finalNodes); @Override int getRanking();  }### Answer:
@Test public void testMatches() throws Exception { Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/matches/jcr:content/par/colctrl").adaptTo(Node.class); ServiceReference ref = bundleContext.getServiceReference(StructureRewriteRule.class.getName()); StructureRewriteRule rule = bundleContext.<StructureRewriteRule>getService(ref); assertTrue(rule.matches(rootNode)); }
@Test public void testNoMatchResourceType() throws Exception { Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/matches/jcr:content").adaptTo(Node.class); ServiceReference ref = bundleContext.getServiceReference(StructureRewriteRule.class.getName()); StructureRewriteRule rule = bundleContext.<StructureRewriteRule>getService(ref); assertFalse(rule.matches(rootNode)); }
@Test public void testNoMatchLayout() throws Exception { Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/matches/jcr:content/par/col_break").adaptTo(Node.class); ServiceReference ref = bundleContext.getServiceReference(StructureRewriteRule.class.getName()); StructureRewriteRule rule = bundleContext.<StructureRewriteRule>getService(ref); assertFalse(rule.matches(rootNode)); }
@Test public void testNoMatchWrongColumnCount() throws Exception { Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/doesNotMatch/jcr:content/par/colctrl").adaptTo(Node.class); ServiceReference ref = bundleContext.getServiceReference(StructureRewriteRule.class.getName()); StructureRewriteRule rule = bundleContext.<StructureRewriteRule>getService(ref); assertFalse(rule.matches(rootNode)); }