### Question:
StyleAdjacencyVisitor implements Visitor { public VisitStatus visit(Gadget gadget, Node node) throws RewritingException { if (node.getNodeType() == Node.ELEMENT_NODE && ("style".equalsIgnoreCase(node.getNodeName()) || ("link".equalsIgnoreCase(node.getNodeName()) && ("stylesheet".equalsIgnoreCase(getAttrib(node, "rel")) || ("text/css".equalsIgnoreCase(getAttrib(node, "type"))))))) { return VisitStatus.RESERVE_TREE; } return VisitStatus.BYPASS; }  VisitStatus visit(Gadget gadget, Node node); boolean revisit(Gadget gadget, List<Node> nodes);  }### Answer:
@Test public void visitStyle() throws Exception { Node node = elem("style"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void visitLinkWithRel() throws Exception { Node node = elem("link", "rel", "stylesheet"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void visitLinkWithType() throws Exception { Node node = elem("link", "type", "text/css"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void visitStyleCaseInsensitive() throws Exception { Node node = elem("sTYlE"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void visitLinkCaseInsensitive() throws Exception { Node node = elem("lINK", "REL", "stYlEsheet"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); node = elem("LINk", "tyPe", "text/csS"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void visitStyleWithAttribs() throws Exception { Node node = elem("style", "foo", "bar"); assertEquals(VisitStatus.RESERVE_TREE, visit(node)); }
@Test public void bypassUnknownElement() throws Exception { Node node = elem("div"); assertEquals(VisitStatus.BYPASS, visit(node)); }
@Test public void bypassLinkWithoutAttribs() throws Exception { Node node = elem("link"); assertEquals(VisitStatus.BYPASS, visit(node)); }
@Test public void bypassLinkWithWrongAttribs() throws Exception { Node node = elem("link", "type", "somecss"); assertEquals(VisitStatus.BYPASS, visit(node)); }
@Test public void bypassText() throws Exception { Node node = doc.createTextNode("text"); assertEquals(VisitStatus.BYPASS, visit(node)); }
@Test public void bypassComment() throws Exception { Node node = doc.createComment("comment"); assertEquals(VisitStatus.BYPASS, visit(node)); }