@Test public void testTerminalClauseTwoSearchHandlersDifferent() throws Exception { final TerminalClause input1 = new TerminalClauseImpl("field", Operator.EQUALS, "Value1"); final TerminalClause input2 = new TerminalClauseImpl("field", Operator.EQUALS, "Value2"); final SearchHandlerManager manager = mockController.getMock(SearchHandlerManager.class); final ClausePermissionHandler permissionHandler = mockController.getMock(ClausePermissionHandler.class); EasyMock.expect(permissionHandler.sanitise(null, input1)).andReturn(input1); EasyMock.expect(permissionHandler.sanitise(null, input1)).andReturn(input2); final ClauseHandler handler1 = new MockClauseHandler(null, null, permissionHandler, null); final ClauseHandler handler2 = new MockClauseHandler(null, null, permissionHandler, null); EasyMock.expect(manager.getClauseHandler((User) null, "field")) .andReturn(CollectionBuilder.newBuilder(handler1, handler2).asList()); final JqlOperandResolver jqlOperandResolver = mockController.getMock(JqlOperandResolver.class); mockController.replay(); ClauseSanitisingVisitor visitor = new ClauseSanitisingVisitor(manager, jqlOperandResolver, null) { @Override TerminalClause sanitiseOperands(final TerminalClause clause) { return clause; } }; final Clause expected = new OrClause(input1, input2); final Clause clause = input1.accept(visitor); assertEquals(expected, clause); mockController.verify(); }
@Test public void testTerminalClauseOneSearchHandler() throws Exception { final TerminalClause input = new TerminalClauseImpl("field", Operator.EQUALS, "Value"); final SearchHandlerManager manager = mockController.getMock(SearchHandlerManager.class); final ClausePermissionHandler permissionHandler = mockController.getMock(ClausePermissionHandler.class); EasyMock.expect(permissionHandler.sanitise(null, input)).andReturn(input); final ClauseHandler handler = new MockClauseHandler(null, null, permissionHandler, null); EasyMock.expect(manager.getClauseHandler((User) null, "field")) .andReturn(Collections.singletonList(handler)); final JqlOperandResolver jqlOperandResolver = mockController.getMock(JqlOperandResolver.class); mockController.replay(); ClauseSanitisingVisitor visitor = new ClauseSanitisingVisitor(manager, jqlOperandResolver, null) { @Override TerminalClause sanitiseOperands(final TerminalClause clause) { return clause; } }; final Clause clause = input.accept(visitor); assertSame(clause, input); mockController.verify(); }