FloatMapper extends SingleColumnMapper.SingleFieldMapper<Float> { @JsonCreator public FloatMapper(String field, String column, Boolean validated, Float boost) { super(field, column, true, validated, null, Float.class, NUMERIC_TYPES); this.boost = boost == null ? DEFAULT_BOOST : boost; } @JsonCreator  FloatMapper(String field, String column, Boolean validated, Float boost); @Override Optional<Field> indexedField(String name, Float value); @Override Optional<Field> sortedField(String name, Float value); @Override SortField sortField(String name, boolean reverse); @Override String toString(); static final Float DEFAULT_BOOST; final Float boost; }
@Test public void testConstructorWithoutArgs() { FloatMapper mapper = floatMapper().build("field"); assertEquals("Field is not properly set", "field", mapper.field); assertEquals("Column is not set to default value", "field", mapper.column); assertEquals("Mapped columns are not properly set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("field")); assertEquals("Boost is not set to default value", DoubleMapper.DEFAULT_BOOST, mapper.boost, 1); }
@Test public void testConstructorWithAllArgs() { FloatMapper mapper = floatMapper().column("column").boost(0.3f).build("field"); assertEquals("Field is not properly set", "field", mapper.field); assertEquals("Column is not properly set", "column", mapper.column); assertEquals("Mapped columns are not properly set", 1, mapper.mappedColumns.size()); assertTrue("Mapped columns are not properly set", mapper.mappedColumns.contains("column")); assertEquals("Boost is not properly set", 0.3f, mapper.boost, 1); }
@Test public void testJsonSerialization() { FloatMapperBuilder builder = floatMapper().column("column").boost(0.3f); testJson(builder, "{type:\"float\",column:\"column\",boost:0.3}"); }
@Test public void testJsonSerializationDefaults() { FloatMapperBuilder builder = floatMapper(); testJson(builder, "{type:\"float\"}"); }
@Test public void testValueNull() { FloatMapper mapper = floatMapper().boost(1f).build("field"); assertNull("Base for nulls is wrong", mapper.base("test", null)); }
@Test public void testValueString() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", "3.4"); assertEquals("Base for strings is wrong", Float.valueOf(3.4f), parsed); }
@Test(expected = IndexException.class) public void testValueStringInvalid() { FloatMapper mapper = floatMapper().boost(1f).build("field"); mapper.base("test", "error"); }
@Test public void testValueInteger() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3); assertEquals("Base for integers is wrong", Float.valueOf(3), parsed); }
@Test public void testValueLong() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3l); assertEquals("Base for longs is wrong", Float.valueOf(3), parsed); }
@Test public void testValueByte() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Byte bite = new Byte("3"); Float parsed = mapper.base("test", bite); assertEquals("Base for longs is wrong", Float.valueOf(3), parsed); }
@Test public void testValueShort() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Short shorty = new Short("3"); Float parsed = mapper.base("test", shorty); assertEquals("Base for longs is wrong", Float.valueOf(3), parsed); }
@Test public void testValueFloatWithoutDecimal() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3f); assertEquals("Base for floats is wrong", Float.valueOf(3), parsed); }
@Test public void testValueFloatWithDecimalFloor() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3.5f); assertEquals("Base for floats is wrong", Float.valueOf(3.5f), parsed); }
@Test public void testValueFloatWithDecimalCeil() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3.6f); assertEquals("Base for floats is wrong", Float.valueOf(3.6f), parsed); }
@Test public void testValueDoubleWithoutDecimal() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3d); assertEquals("Base for doubles is wrong", Float.valueOf(3), parsed); }
@Test public void testValueDoubleWithDecimalFloor() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3.5d); assertEquals("Base for doubles is wrong", Float.valueOf(3.5f), parsed); }
@Test public void testValueDoubleWithDecimalCeil() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", 3.6d); assertEquals("Base for doubles is wrong", Float.valueOf(3.6f), parsed); }
@Test public void testValueStringWithoutDecimal() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", "3"); assertEquals("Base for strings is wrong", Float.valueOf(3), parsed); }
@Test public void testValueStringWithDecimalFloor() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", "3.2"); assertEquals("Base for strings is wrong", Float.valueOf(3.2f), parsed); }
@Test public void testValueStringWithDecimalCeil() { FloatMapper mapper = floatMapper().boost(1f).build("field"); Float parsed = mapper.base("test", "3.6"); assertEquals("Base for strings is wrong", Float.valueOf(3.6f), parsed); }
@Test public void testExtractAnalyzers() { FloatMapper mapper = floatMapper().boost(1f).build("field"); assertNull("Analyzer must be null", mapper.analyzer); }