1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine.expression;
17
18 import java.math.BigInteger;
19
20 import org.junit.Test;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23
24
25
26
27
28
29
30 public class ComparisonOperatorTest {
31 @Test
32 public void testEquals() {
33 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.EQUALS.toString());
34 assertTrue(op.compare("StringOne", "StringOne"));
35 assertTrue(op.compare(123, "123"));
36 assertTrue(op.compare(BigInteger.TEN, "10"));
37
38
39
40
41
42 }
43
44 @Test
45 public void testNotEquals() {
46 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.NOT_EQUALS.toString());
47 assertTrue(op.compare("StringOne", "StringTwo"));
48 assertTrue(op.compare(122, "123"));
49 assertTrue(op.compare(BigInteger.TEN, "11"));
50 assertTrue(op.compare(null, "124"));
51 assertFalse(op.compare(null, null));
52 }
53
54 @Test
55 public void testLess() {
56 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.LESS_THAN.toString());
57 assertTrue(op.compare(123, "124"));
58 assertTrue(op.compare(new Double(123.2), "124"));
59 assertTrue(op.compare(null, "124"));
60 assertFalse(op.compare(124, null));
61 assertFalse(op.compare(null, null));
62 assertFalse(op.compare(123, "123"));
63 assertFalse(op.compare(new Integer(123), "122"));
64 assertFalse(op.compare(122.1, "122"));
65 }
66
67 @Test
68 public void testLessThanEqual() {
69 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.LESS_THAN_EQUAL.toString());
70 assertTrue(op.compare(123, "124"));
71 assertTrue(op.compare(123.1, "123.1"));
72 assertTrue(op.compare(null, null));
73 assertFalse(op.compare(new Double(123.1), "123.01"));
74 assertFalse(op.compare(123, "122"));
75 }
76
77 @Test
78 public void testGreaterThanEqual() {
79 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.GREATER_THAN_EQUAL.toString());
80 assertFalse(op.compare(123, "124"));
81 assertTrue(op.compare(123.1, "123.1"));
82 assertFalse(op.compare(null, "124"));
83 assertTrue(op.compare(124, null));
84 assertTrue(op.compare(null, null));
85 assertTrue(op.compare(new Double(123.1), "123.01"));
86 assertTrue(op.compare(123, "122"));
87 }
88 }