KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javax > management > BinaryOpValueExpTest


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package test.javax.management;
10
11 import javax.management.Query JavaDoc;
12 import javax.management.QueryExp JavaDoc;
13 import javax.management.ValueExp JavaDoc;
14
15 import junit.framework.TestCase;
16
17 /**
18  * @version $Revision: 1.4 $
19  */

20 public class BinaryOpValueExpTest extends TestCase
21 {
22    /**
23     * Constructor requested by the JUnit framework
24     */

25    public BinaryOpValueExpTest(String JavaDoc name)
26    {
27       super(name);
28    }
29
30    public void testLongOperations() throws Exception JavaDoc
31    {
32       ValueExp JavaDoc value1 = Query.value(new Integer JavaDoc(3));
33       ValueExp JavaDoc value2 = Query.value(new Integer JavaDoc(4));
34       ValueExp JavaDoc op = Query.plus(value1, value2);
35       QueryExp JavaDoc result = Query.eq(Query.value(7L), op);
36       assertTrue(result.apply(null));
37
38       op = Query.minus(value1, value2);
39       result = Query.eq(Query.value(-1L), op);
40       assertTrue(result.apply(null));
41
42       op = Query.times(value1, value2);
43       result = Query.eq(Query.value(12L), op);
44       assertTrue(result.apply(null));
45
46       op = Query.div(value1, value2);
47       result = Query.eq(Query.value(0L), op);
48       assertTrue(result.apply(null));
49    }
50
51    public void testDoubleOperations() throws Exception JavaDoc
52    {
53       ValueExp JavaDoc value1 = Query.value(new Double JavaDoc(3.0D));
54       ValueExp JavaDoc value2 = Query.value(new Double JavaDoc(4.0D));
55       ValueExp JavaDoc op = Query.plus(value1, value2);
56       QueryExp JavaDoc result = Query.eq(Query.value(7.0D), op);
57       assertTrue(result.apply(null));
58
59       op = Query.minus(value1, value2);
60       result = Query.eq(Query.value(-1.0D), op);
61       assertTrue(result.apply(null));
62
63       op = Query.times(value1, value2);
64       result = Query.eq(Query.value(12.0D), op);
65       assertTrue(result.apply(null));
66
67       op = Query.div(value1, value2);
68       result = Query.eq(Query.value(3.0D / 4.0D), op);
69       assertTrue(result.apply(null));
70    }
71 }
72
73
Popular Tags