protected String buildQueryFilter(String streamId, String query) {
        checkArgument(streamId != null, "streamId parameter cannot be null");

        final String trimmedStreamId = streamId.trim();

        checkArgument(!trimmedStreamId.isEmpty(), "streamId parameter cannot be empty");

        final StringBuilder builder = new StringBuilder().append("streams:").append(trimmedStreamId);

        if (query != null) {
            final String trimmedQuery = query.trim();
            if (!trimmedQuery.isEmpty() && !"*".equals(trimmedQuery)) {
                builder.append(" AND (").append(trimmedQuery).append(")");
            }
        }

        return builder.toString();
    }
@Test
    public void testQueryFilterBuilder() {
        final AbstractAlertCondition condition = (AbstractAlertCondition) getDummyAlertCondition(ImmutableMap.of());

        assertThatThrownBy(() -> condition.buildQueryFilter(null, null))
                .hasMessageContaining("streamId")
                .hasMessageContaining("be null");
        assertThatThrownBy(() -> condition.buildQueryFilter("", null))
                .hasMessageContaining("streamId")
                .hasMessageContaining("be empty");

        assertThat(condition.buildQueryFilter("  abc123 ", null))
                .isEqualTo("streams:abc123");
        assertThat(condition.buildQueryFilter("abc123", ""))
                .isEqualTo("streams:abc123");
        assertThat(condition.buildQueryFilter("abc123", "*"))
                .isEqualTo("streams:abc123");
        assertThat(condition.buildQueryFilter("abc123", " *  "))
                .isEqualTo("streams:abc123");
        assertThat(condition.buildQueryFilter("abc123", " hello:world foo:\"bar baz\"   "))
                .isEqualTo("streams:abc123 AND (hello:world foo:\"bar baz\")");
        assertThat(condition.buildQueryFilter("abc123", "hello:world AND foo:\"bar baz\""))
                .isEqualTo("streams:abc123 AND (hello:world AND foo:\"bar baz\")");
        assertThat(condition.buildQueryFilter("abc123", "hello:world AND (foo:\"bar baz\" OR foo:yolo)"))
                .isEqualTo("streams:abc123 AND (hello:world AND (foo:\"bar baz\" OR foo:yolo))");
    }