@Before
  public void setup() {
    Mockito.when(
            androidPushMock.acceptPushNotficationForType(
                Mockito.argThat(
                    new BaseMatcher<Device>() {
                      @Override
                      public boolean matches(Object item) {
                        Device dev = (Device) item;
                        return dev.getKindOfDevice() == Device.KindOfDeviceEnum.ANDROID;
                      }

                      @Override
                      public void describeTo(Description description) {}
                    })))
        .thenReturn(Boolean.TRUE);
    List<Push2Mobile> pushers = Lists.newArrayList(androidPushMock);
    Mockito.when(inst.iterator()).thenReturn(pushers.iterator());
  }
  private Pair<WebsocketHandlers, Method> getMethod(JsonObject request) {
    String action = request.getAsJsonPrimitive("action").getAsString();

    Pair<WebsocketHandlers, Method> methodPair = methodsCache.get(action);
    if (methodPair != null) {
      return methodPair;
    }

    for (Iterator<WebsocketHandlers> iter = handlers.iterator(); iter.hasNext(); ) {
      WebsocketHandlers current = iter.next();
      Class<? extends WebsocketHandlers> currentClass = current.getClass();
      boolean found = false;
      for (final Method method : currentClass.getMethods()) {
        if (method.isAnnotationPresent(Action.class)) {
          if (method.getAnnotation(Action.class).value().equals(action)) {
            Preconditions.checkState(
                method.getReturnType().equals(WebSocketResponse.class),
                "Method should have %s return type",
                WebSocketResponse.class);
            methodPair = ImmutablePair.of(current, method);
            found = true;
            break;
          }
        }
      }
      if (found) {
        break;
      }
    }
    if (methodPair == null) {
      throw new HiveException(
          String.format(Messages.UNKNOWN_ACTION_REQUESTED_WS, action),
          HttpServletResponse.SC_BAD_REQUEST);
    }
    methodsCache.put(action, methodPair);
    return methodPair;
  }
  @Test
  public void testQueryInvalidIndexTerms() throws IOException, InterruptedException {
    final Instance<NamedQuery> namedQueriesProducer = mock(Instance.class);
    when(namedQueriesProducer.iterator()).thenReturn(queries.iterator());

    final RefactoringQueryServiceImpl service =
        new RefactoringQueryServiceImpl(getConfig(), namedQueriesProducer);
    service.init();

    // Add test files
    final Path path1 = basePath.resolve("drl1.drl");
    final String drl1 = loadText("drl1.drl");
    ioService().write(path1, drl1);

    Thread.sleep(
        5000); // wait for events to be consumed from jgit -> (notify changes -> watcher -> index)
               // -> lucene index

    {
      final RefactoringPageRequest request =
          new RefactoringPageRequest(
              "FindRulesByProjectQuery", new HashSet<ValueIndexTerm>(), 0, -1);

      try {
        final PageResponse<RefactoringPageRow> response = service.query(request);
        fail();
      } catch (IllegalArgumentException e) {
        // Swallow. Expected
      }
    }

    {
      final RefactoringPageRequest request =
          new RefactoringPageRequest(
              "FindRulesByProjectQuery",
              new HashSet<ValueIndexTerm>() {
                {
                  add(
                      new ValueTypeIndexTerm(
                          "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant"));
                }
              },
              0,
              -1);

      try {
        final PageResponse<RefactoringPageRow> response = service.query(request);
        fail();
      } catch (IllegalArgumentException e) {
        // Swallow. Expected
      }
    }

    {
      final RefactoringPageRequest request =
          new RefactoringPageRequest(
              "FindRulesByProjectQuery",
              new HashSet<ValueIndexTerm>() {
                {
                  add(new ValueRuleIndexTerm("myRule"));
                  add(
                      new ValueTypeIndexTerm(
                          "org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant"));
                }
              },
              0,
              -1);

      try {
        final PageResponse<RefactoringPageRow> response = service.query(request);
        fail();
      } catch (IllegalArgumentException e) {
        // Swallow. Expected
      }
    }
  }