VIVO-873 Improve unit tests of DocumentModifier classes

Add copy constructors, equals(), and hashCode() to BaseSearchInputDocument and BaseSearchInputField
This commit is contained in:
Jim Blake 2014-10-17 10:52:11 -04:00
parent 3ccb10dc83
commit 7a12354430
5 changed files with 170 additions and 11 deletions

View file

@ -0,0 +1,56 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.searchengine.base;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.Map;
import org.junit.Test;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputField;
/**
* TODO
*/
public class BaseSearchInputDocumentTest {
/**
* The copy constructor should make a deep copy, down to (but not including)
* the field values. The component parts should be equal, but not the same.
*/
@Test
public void copyConstructor() {
BaseSearchInputDocument doc = new BaseSearchInputDocument();
doc.setDocumentBoost(42.6F);
SearchInputField field1 = new BaseSearchInputField("testField");
field1.addValues("value1", "value2");
field1.setBoost(1.1F);
doc.addField(field1);
SearchInputField field2 = new BaseSearchInputField("anotherField");
field2.setBoost(-16F);
doc.addField(field2);
BaseSearchInputDocument other = new BaseSearchInputDocument(doc);
assertEquals(doc, other);
assertEquals(doc.getDocumentBoost(), other.getDocumentBoost(), 0.01F);
Map<String, SearchInputField> docMap = doc.getFieldMap();
Map<String, SearchInputField> otherMap = other.getFieldMap();
assertEquals(docMap, otherMap);
assertNotSame(docMap, otherMap);
for (String fieldName : docMap.keySet()) {
SearchInputField docField = doc.getField(fieldName);
SearchInputField otherField = other.getField(fieldName);
assertEquals(docField, otherField);
assertNotSame(docField, otherField);
Collection<Object> docFieldValues = docField.getValues();
Collection<Object> otherFieldValues = otherField.getValues();
assertEquals(docFieldValues, otherFieldValues);
}
}
}