Treat null and empty string as different values when doing transforms
This commit is contained in:
parent
8dec08aad3
commit
d2687cc58a
@ -125,11 +125,9 @@ public class ExpressionUtils {
|
||||
|
||||
static public boolean sameValue(Object v1, Object v2) {
|
||||
if (v1 == null) {
|
||||
return (v2 == null)
|
||||
|| (v2 instanceof String && ((String) v2).length() == 0);
|
||||
return (v2 == null) ;
|
||||
} else if (v2 == null) {
|
||||
return (v1 == null)
|
||||
|| (v1 instanceof String && ((String) v1).length() == 0);
|
||||
return (v1 == null);
|
||||
} else {
|
||||
return v1.equals(v2);
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
|
||||
Copyright 2017, Owen Stephens
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
package com.google.refine.tests.expr.functions;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.expr.ExpressionUtils;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
|
||||
|
||||
public class ExpressionUtilsTests extends RefineTest {
|
||||
|
||||
Project project;
|
||||
Properties bindings;
|
||||
|
||||
@Override
|
||||
@BeforeTest
|
||||
public void init() {
|
||||
logger = LoggerFactory.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
|
||||
@BeforeMethod
|
||||
public void SetUp() {
|
||||
project = new Project();
|
||||
bindings = ExpressionUtils.createBindings(project);
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void TearDown() {
|
||||
project = null;
|
||||
bindings = null;
|
||||
}
|
||||
|
||||
// -----------------tests------------
|
||||
|
||||
@Test
|
||||
public void testSameValueTrue() {
|
||||
Assert.assertTrue(ExpressionUtils.sameValue(null,null));
|
||||
Assert.assertTrue(ExpressionUtils.sameValue("",""));
|
||||
Assert.assertTrue(ExpressionUtils.sameValue("one","one"));
|
||||
Assert.assertTrue(ExpressionUtils.sameValue(1,1));
|
||||
Assert.assertTrue(ExpressionUtils.sameValue(1.0,1.00));
|
||||
Assert.assertTrue(ExpressionUtils.sameValue(true,true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameValueFalse() {
|
||||
Assert.assertFalse(ExpressionUtils.sameValue("",null));
|
||||
Assert.assertFalse(ExpressionUtils.sameValue(null,""));
|
||||
Assert.assertFalse(ExpressionUtils.sameValue("one","two"));
|
||||
Assert.assertFalse(ExpressionUtils.sameValue(1,2));
|
||||
Assert.assertFalse(ExpressionUtils.sameValue(1,1.0));
|
||||
Assert.assertFalse(ExpressionUtils.sameValue(true,false));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user