geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject incubator-geode git commit: GEODE-785: Refactor repetitive comparison/loop code in CompiledIn.evaluate
Date Wed, 20 Jan 2016 18:08:16 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 731c668f4 -> 06a7dbd38


GEODE-785: Refactor repetitive comparison/loop code in CompiledIn.evaluate

Collapsed multiple primitive array loops into a single one
Added CompiledInJUnitTest


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/06a7dbd3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/06a7dbd3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/06a7dbd3

Branch: refs/heads/develop
Commit: 06a7dbd3888cfa706efbd5ce255c7b83d7720e57
Parents: 731c668
Author: Jason Huynh <huynhja@gmail.com>
Authored: Mon Jan 18 12:09:41 2016 -0800
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Wed Jan 20 10:14:35 2016 -0800

----------------------------------------------------------------------
 .../cache/query/internal/CompiledIn.java        | 106 +----
 .../query/internal/CompiledInJUnitTest.java     | 389 +++++++++++++++++++
 2 files changed, 399 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06a7dbd3/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledIn.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledIn.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledIn.java
index 75fb4b8..342aeea 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledIn.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledIn.java
@@ -17,6 +17,7 @@
 
 package com.gemstone.gemfire.cache.query.internal;
 
+import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -93,7 +94,7 @@ public class CompiledIn extends AbstractCompiledValue implements Indexable
{
   private Object evaluateColln(ExecutionContext context) 
       throws QueryInvocationTargetException, NameResolutionException, 
       TypeMismatchException, FunctionDomainException {
- Object evalColln = null;
+    Object evalColln = null;
     if (this.colln.isDependentOnCurrentScope(context)) {
       evalColln = this.colln.evaluate(context);
     }
@@ -143,107 +144,20 @@ public class CompiledIn extends AbstractCompiledValue implements Indexable
{
     if (!evalColln.getClass().isArray()) {
       throw new TypeMismatchException(LocalizedStrings.CompiledIn_OPERAND_OF_IN_CANNOT_BE_INTERPRETED_AS_A_COLLECTION_IS_INSTANCE_OF_0.toLocalizedString(evalColln.getClass().getName()));
     }
-    if (evalColln instanceof Object[]) {
-      Object[] a = (Object[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        if (TypeUtils.compare(evalElm, a[i], TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
+    if (evalColln.getClass().getComponentType().isPrimitive()) {
+      if (evalElm == null) {
+        throw new TypeMismatchException(LocalizedStrings.CompiledIn_IN_OPERATOR_CHECK_FOR_NULL_IN_PRIMITIVE_ARRAY.toLocalizedString());
       }
-      return Boolean.FALSE;
-    }
-
-    // at this point if evalElm is NULL, then it's a type mismatch
-    if (evalElm == null) {
-      throw new TypeMismatchException(LocalizedStrings.CompiledIn_IN_OPERATOR_CHECK_FOR_NULL_IN_PRIMITIVE_ARRAY.toLocalizedString());
-    }
-
-    // handle each type of primitive array
-    if (evalColln instanceof long[]) {
-      long[] a = (long[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = Long.valueOf(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
     }
     
-    if (evalColln instanceof double[]) {
-      double[] a = (double[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = Double.valueOf(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-    
-    if (evalColln instanceof float[]) {
-      float[] a = (float[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = new Float(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-    
-    if (evalColln instanceof int[]) {
-      int[] a = (int[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = Integer.valueOf(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-    
-    if (evalColln instanceof short[]) {
-      short[] a = (short[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = new Short(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-    
-    if (evalColln instanceof char[]) {
-      char[] a = (char[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = new Character(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-    
-    if (evalColln instanceof byte[]) {
-      byte[] a = (byte[])evalColln;
-      for (int i = 0; i < a.length; i++) {
-        Object e = Byte.valueOf(a[i]);
-        if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
-          return Boolean.TRUE;
-        }
-      }
-      return Boolean.FALSE;
-    }
-
-    // must be a boolean[]
-    boolean[] a = (boolean[]) evalColln;
-    for (int i = 0; i < a.length; i++) {
-      Object e = Boolean.valueOf(a[i]);
-      if (TypeUtils.compare(evalElm, e, TOK_EQ).equals(Boolean.TRUE)) {
+    int numElements = Array.getLength(evalColln);
+    for (int i = 0; i < numElements; i++) {
+      Object o = Array.get(evalColln, i);
+      if (TypeUtils.compare(evalElm, o, TOK_EQ).equals(Boolean.TRUE)) {
         return Boolean.TRUE;
       }
     }
+   
     return Boolean.FALSE;
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/06a7dbd3/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledInJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledInJUnitTest.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledInJUnitTest.java
new file mode 100644
index 0000000..3e573ef
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/CompiledInJUnitTest.java
@@ -0,0 +1,389 @@
+package com.gemstone.gemfire.cache.query.internal;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.query.TypeMismatchException;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class CompiledInJUnitTest {
+
+  ExecutionContext context;
+  CompiledValue elm;
+  CompiledValue colln;
+
+  @Before
+  public void setup() {
+    context = mock(ExecutionContext.class);
+    elm = mock(CompiledValue.class);
+    colln = mock(CompiledValue.class);
+  }
+
+  @Test
+  public void testShouldNotThrowTypeMismatchWithNullElementAndObjectArray() throws Exception
{
+    Object[] objectValues = new Object[] { true, true };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(null);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(objectValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+  }
+
+  @Test
+  public void testTypeMismatchWithNullElementAndPrimitiveArray() throws Exception {
+    boolean[] booleanValues = new boolean[] { true, true };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(null);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(booleanValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    try {
+      Object result = compiledIn.evaluate(context);
+      fail("TypeMismatchException should be thrown");
+    } catch (TypeMismatchException e) {
+
+    }
+  }
+
+  @Test
+  public void testEvaluatesFalseForStringAgainstShortArray() throws Exception {
+    short[] shortValues = new short[] { 1, 1 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("1");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(shortValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueForFloatAgainstShortArray() throws Exception {
+    short[] shortValues = new short[] { 1, 1 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(new Float(1.0));
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(shortValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueForShortAgainstShortArray() throws Exception {
+    short[] shortValues = new short[] { 1, 2 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(shortValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueForIntegerAgainstShortArray() throws Exception {
+    short[] shortValues = new short[] { 1, 2 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(new Integer(1));
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(shortValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesFalseForStringAgainstBooleanArray() throws Exception {
+    boolean[] booleanValues = new boolean[] { true, true };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("true");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(booleanValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesFalseWithBooleanArrayNotMatchingBooleanElement() throws Exception
{
+    boolean[] booleanValues = new boolean[] { true, true };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(false);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(booleanValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithBooleanArrayMatchingBooleanElement() throws Exception
{
+    boolean[] booleanValues = new boolean[] { true, true };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(true);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(booleanValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithBooleanArrayMatchingBooleanFalseElement() throws Exception
{
+    boolean[] booleanValues = new boolean[] { false, false };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(false);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(booleanValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithCharArrayMatchingCharElement() throws Exception {
+    char[] charValues = new char[] { 'a', 'b', '1' };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn('a');
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(charValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWitCharArrayNotMatchingCharElement() throws Exception {
+    char[] charValues = new char[] { 'a', 'b', '1' };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn('c');
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(charValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testStringDoesNotMatchCharElements() throws Exception {
+    char[] charValues = new char[] { 'a', 'b', '1' };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("a");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(charValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testIntegerDoesNotMatchCharElements() throws Exception {
+    char[] charValues = new char[] { 'a', 'b', '1' };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(97);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(charValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesFalseWithByteArrayNotMatchingIntegerElement() throws Exception
{
+    byte[] byteValues = new byte[] { 127, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(127);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(byteValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesFalseWithByteArrayNotMatchingLargerIntegerElement() throws Exception
{
+    byte[] byteValues = new byte[] { 127, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(128);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(byteValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithByteArrayMatchingByteElement() throws Exception {
+    byte[] byteValues = new byte[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn((Byte.valueOf("1")));
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(byteValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluateNotMatchingLongElement() throws Exception {
+    long[] longValues = new long[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(4L);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(longValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithLongArrayMatchingLongElement() throws Exception {
+    long[] longValues = new long[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1L);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(longValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithSecondElementOfLongArrayMatchingLongElement() throws Exception
{
+    long[] longValues = new long[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(2L);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(longValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithLongArrayMatchingAndDoubleElement() throws Exception {
+    long[] longValues = new long[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1D);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(longValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWithLongArrayMatchingAndIntegerElement() throws Exception
{
+    long[] longValues = new long[] { 1, 2, 3 };
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(new Integer(1));
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(longValues);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testExceptionThrownWhenEvaluateAgainstANonCollection() throws Exception {
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn("NotACollection");
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    try {
+      Object result = compiledIn.evaluate(context);
+      fail("should throw a TypeMismatchException");
+    } catch (TypeMismatchException e) {
+      // expected
+    }
+  }
+
+  @Test
+  public void testEvaluatesFalseWhenIntegerNotInCollection() throws Exception {
+    Collection collection = new ArrayList();
+    collection.add(1);
+    collection.add(2);
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(3);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWhenIntegerInIntegerCollection() throws Exception {
+    Collection collection = new ArrayList();
+    collection.add(1);
+    collection.add(2);
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWhenIntegerInSingleElementIntegerCollection() throws Exception
{
+    Collection collection = new ArrayList();
+    collection.add(1);
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  // String form
+  @Test
+  public void testEvaluatesFalseWhenIntegerNotInStringCollection() throws Exception {
+    Collection collection = new ArrayList();
+    collection.add("1");
+    collection.add("2");
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn(1);
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesFalseWhenStringNotInStringCollection() throws Exception {
+    Collection collection = new ArrayList();
+    collection.add("1");
+    collection.add("2");
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("3");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertFalse((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWhenStringInStringCollection() throws Exception {
+    Collection collection = new ArrayList();
+    collection.add("1");
+    collection.add("2");
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("1");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testEvaluatesTrueWhenStringInSingleElementStringCollection() throws Exception
{
+    Collection collection = new ArrayList();
+    collection.add("1");
+    when(elm.evaluate(isA(ExecutionContext.class))).thenReturn("1");
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(collection);
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertTrue((Boolean) result);
+  }
+
+  @Test
+  public void testCompiledInCanEvaluate() throws Exception {
+    when(colln.evaluate(isA(ExecutionContext.class))).thenReturn(new ArrayList());
+
+    CompiledIn compiledIn = new CompiledIn(elm, colln);
+    Object result = compiledIn.evaluate(context);
+    Assert.assertNotNull(result);
+  }
+}


Mime
View raw message