Buggy code:
public class MongoFilterSerializerTest { MongoFilterSerializer ser ; @ Before public void setup ( ) { } @ Test public void shouldTestMongoSimpleFilterSerialization ( ) throws Exception { } @ Test public void shouldTestMongoOrFilterSerialization ( ) throws Exception { } @ Test public void shouldTestMongoAndOrFilterSerialization ( ) throws Exception { Filter f = Mockito . mock ( Filter . class ) ; FilterCondition fc1 = Mockito . mock ( FilterCondition . class ) ; FilterCondition fc2 = Mockito . mock ( FilterCondition . class ) ; FilterCondition fc3 = Mockito . mock ( FilterCondition . class ) ; FilterCondition fc4 = Mockito . mock ( FilterCondition . class ) ; String property1 = "mimetype" ; String property2 = "puid" ; String value1 = "applciation//pdf" ; String value2 = "text//html" ; String value3 = "text//xml" ; String value4 = "fmt//42" ; Mockito . when ( fc1 . getField ( ) ) . thenReturn ( property1 ) ; Mockito . when ( fc1 . getValue ( ) ) . thenReturn ( value1 ) ; Mockito . when ( fc2 . getField ( ) ) . thenReturn ( property1 ) ; Mockito . when ( fc2 . getValue ( ) ) . thenReturn ( value2 ) ; Mockito . when ( fc3 . getField ( ) ) . thenReturn ( property1 ) ; Mockito . when ( fc3 . getValue ( ) ) . thenReturn ( value3 ) ; Mockito . when ( fc4 . getField ( ) ) . thenReturn ( property2 ) ; Mockito . when ( fc4 . getValue ( ) ) . thenReturn ( value4 ) ; Mockito . when ( f . getConditions ( ) ) . thenReturn ( Arrays . asList ( fc1 , fc2 , fc3 , fc4 ) ) ; DBObject filter = ser . serialize ( f ) ; String val = filter . toString ( ) ; <START_BUG> String expr = "{<seq2seq4repair_space>\"$and\"<seq2seq4repair_space>:<seq2seq4repair_space>[<seq2seq4repair_space>{<seq2seq4repair_space>\"$or\"<seq2seq4repair_space>:<seq2seq4repair_space>[<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"applciation//pdf\"}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"text//html\"}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"text//xml\"}]}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.puid.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"fmt//42\"}]}" ; <END_BUG> Assert . assertEquals ( expr , val ) ; } }

Fix:
String expr = "{<seq2seq4repair_space>\"$and\"<seq2seq4repair_space>:<seq2seq4repair_space>[<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.puid.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"fmt//42\"}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"$or\"<seq2seq4repair_space>:<seq2seq4repair_space>[<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"applciation//pdf\"}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"text//html\"}<seq2seq4repair_space>,<seq2seq4repair_space>{<seq2seq4repair_space>\"metadata.mimetype.value\"<seq2seq4repair_space>:<seq2seq4repair_space>\"text//xml\"}]}]}" ;