### Eclipse Workspace Patch 1.0
#P lucene_trunk
Index: src/java/org/apache/lucene/search/Query.java
===================================================================
--- src/java/org/apache/lucene/search/Query.java	(revision 785160)
+++ src/java/org/apache/lucene/search/Query.java	(working copy)
@@ -169,17 +169,17 @@
    *
    *<p>A utility for use by {@link #combine(Query[])} implementations.
    */
-  public static Query mergeBooleanQueries(Query[] queries) {
+  public static Query mergeBooleanQueries(BooleanQuery[] queries) {
     HashSet allClauses = new HashSet();
     for (int i = 0; i < queries.length; i++) {
-      BooleanClause[] clauses = ((BooleanQuery)queries[i]).getClauses();
+      BooleanClause[] clauses = queries[i].getClauses();
       for (int j = 0; j < clauses.length; j++) {
         allClauses.add(clauses[j]);
       }
     }
 
     boolean coordDisabled =
-      queries.length==0? false : ((BooleanQuery)queries[0]).isCoordDisabled();
+      queries.length==0? false : queries[0].isCoordDisabled();
     BooleanQuery result = new BooleanQuery(coordDisabled);
     Iterator i = allClauses.iterator();
     while (i.hasNext()) {
Index: src/java/org/apache/lucene/search/BooleanClause.java
===================================================================
--- src/java/org/apache/lucene/search/BooleanClause.java	(revision 785160)
+++ src/java/org/apache/lucene/search/BooleanClause.java	(working copy)
@@ -94,9 +94,9 @@
 
 
 
-  /** Returns true iff <code>o</code> is equal to this. */
+  /** Returns true if <code>o</code> is equal to this. */
   public boolean equals(Object o) {
-    if (!(o instanceof BooleanClause))
+    if (o == null || !(o instanceof BooleanClause))
       return false;
     BooleanClause other = (BooleanClause)o;
     return this.query.equals(other.query)
Index: src/test/org/apache/lucene/search/TestQuery.java
===================================================================
--- src/test/org/apache/lucene/search/TestQuery.java	(revision 0)
+++ src/test/org/apache/lucene/search/TestQuery.java	(revision 0)
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.search;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * Tests static methods of {@link Query}
+ */
+public class TestQuery extends LuceneTestCase {
+
+  /*
+   * Tests #MergeBooleanQueries()
+   */
+  public void testMergeBooleanQueries(){
+    TermQuery termQuery = new TermQuery(new Term("field", "term"));
+    BooleanQuery query = new BooleanQuery();
+    query.add(new BooleanClause(termQuery, Occur.SHOULD));
+    query.add(new BooleanClause(termQuery, Occur.SHOULD)); 
+    query.add(new BooleanClause(termQuery, Occur.MUST));
+    
+    TermQuery termQuery1 = new TermQuery(new Term("field1", "term1"));
+    BooleanQuery query1 = new BooleanQuery();
+    query1.add(new BooleanClause(termQuery, Occur.MUST_NOT));
+    query1.add(new BooleanClause(termQuery, Occur.SHOULD));
+    query1.add(new BooleanClause(termQuery1, Occur.SHOULD));
+    
+    TermQuery termQuery2 = new TermQuery(new Term("field2", "term2"));
+    BooleanQuery query2 = new BooleanQuery();
+    query2.add(new BooleanClause(termQuery, Occur.MUST_NOT));
+    query2.add(new BooleanClause(termQuery1, Occur.SHOULD));
+    query2.add(new BooleanClause(termQuery2, Occur.SHOULD));
+    BooleanQuery mergeBooleanQueries = (BooleanQuery) Query.mergeBooleanQueries(new BooleanQuery[]{ query, query1, query2 });
+    
+    // expected set
+    BooleanClause[] clauses = mergeBooleanQueries.getClauses();
+    Set clauseSet = new HashSet();
+    clauseSet.add(new BooleanClause(termQuery, Occur.SHOULD));
+    clauseSet.add(new BooleanClause(termQuery, Occur.MUST));
+    clauseSet.add(new BooleanClause(termQuery, Occur.MUST_NOT));
+    clauseSet.add(new BooleanClause(termQuery1, Occur.SHOULD));
+    clauseSet.add(new BooleanClause(termQuery2, Occur.SHOULD));
+    
+    assertEquals("Expected number of clauses does not match", clauseSet.size(), clauses.length);
+    for (Iterator iterator = clauseSet.iterator(); iterator.hasNext();) {
+      BooleanClause clause = (BooleanClause) iterator.next();
+      assertTrue("missing boolean clause", isIn(clauses, clause));
+    }
+    
+    
+  }
+  
+  static boolean isIn(BooleanClause[] clauses, BooleanClause clause){
+    for (int i = 0; i < clauses.length; i++) {
+      if(clauses[i].equals(clause))
+        return true;
+    }
+    return false;
+  }
+}
+
+
