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 op.setComparisonOperatorService(ComparisonOperatorServiceImpl.getInstance());
35 assertTrue(op.compare("StringOne", "StringOne"));
36 assertTrue(op.compare(123, "123"));
37 assertTrue(op.compare(BigInteger.TEN, "10"));
38
39
40
41
42
43 }
44
45 @Test
46 public void testNotEquals() {
47 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.NOT_EQUALS.toString());
48 op.setComparisonOperatorService(ComparisonOperatorServiceImpl.getInstance());
49 assertTrue(op.compare("StringOne", "StringTwo"));
50 assertTrue(op.compare(122, "123"));
51 assertTrue(op.compare(BigInteger.TEN, "11"));
52 assertTrue(op.compare(null, "124"));
53 assertFalse(op.compare(null, null));
54 }
55
56 @Test
57 public void testLess() {
58 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.LESS_THAN.toString());
59 op.setComparisonOperatorService(ComparisonOperatorServiceImpl.getInstance());
60 assertTrue(op.compare(123, "124"));
61 assertTrue(op.compare(new Double(123.2), "124"));
62 assertTrue(op.compare(null, "124"));
63 assertFalse(op.compare(124, null));
64 assertFalse(op.compare(null, null));
65 assertFalse(op.compare(123, "123"));
66 assertFalse(op.compare(new Integer(123), "122"));
67 assertFalse(op.compare(122.1, "122"));
68 }
69
70 @Test
71 public void testLessThanEqual() {
72 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.LESS_THAN_EQUAL.toString());
73 op.setComparisonOperatorService(ComparisonOperatorServiceImpl.getInstance());
74 assertTrue(op.compare(123, "124"));
75 assertTrue(op.compare(123.1, "123.1"));
76 assertTrue(op.compare(null, null));
77 assertFalse(op.compare(new Double(123.1), "123.01"));
78 assertFalse(op.compare(123, "122"));
79 }
80
81 @Test
82 public void testGreaterThanEqual() {
83 ComparisonOperator op = ComparisonOperator.fromCode(ComparisonOperator.GREATER_THAN_EQUAL.toString());
84 op.setComparisonOperatorService(ComparisonOperatorServiceImpl.getInstance());
85 assertFalse(op.compare(123, "124"));
86 assertTrue(op.compare(123.1, "123.1"));
87 assertFalse(op.compare(null, "124"));
88 assertTrue(op.compare(124, null));
89 assertTrue(op.compare(null, null));
90 assertTrue(op.compare(new Double(123.1), "123.01"));
91 assertTrue(op.compare(123, "122"));
92 }
93 }