KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > util > junkscore > ComposedJunkScoreTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20
21
22 package org.apache.james.util.junkscore;
23
24 import junit.framework.TestCase;
25
26 public class ComposedJunkScoreTest extends TestCase {
27
28     private final static String JavaDoc KEY1 = "KEY1";
29     private final static double SCORE1 = 20.0;
30     private final static String JavaDoc KEY2 = "KEY2";
31     private final static double SCORE2 = 2.0;
32     
33     private JunkScore getJunkScore(String JavaDoc key, double score) {
34         JunkScore junk = new JunkScoreImpl();
35         if (key != null) {
36             junk.setStoredScore(key, score);
37         }
38         return junk;
39     }
40     
41     public void testIllegalArguments() {
42         boolean exception1 = false;
43         boolean exception2 = false;
44         boolean exception3 = false;
45     
46         try {
47             JunkScore junk = new ComposedJunkScore(null,null);
48         } catch (IllegalArgumentException JavaDoc e) {
49             exception1 = true;
50         }
51         assertTrue("Exception thrown", exception1);
52     
53         try {
54             JunkScore junk = new ComposedJunkScore(null,getJunkScore(null,0));
55         } catch (IllegalArgumentException JavaDoc e) {
56             exception2 = true;
57         }
58         assertTrue("Exception thrown", exception2);
59     
60         try {
61             JunkScore junk = new ComposedJunkScore(getJunkScore(null,0),null);
62         } catch (IllegalArgumentException JavaDoc e) {
63             exception3 = true;
64         }
65         assertTrue("Exception thrown", exception3);
66     
67     }
68     
69     public void testComposedJunkScore() {
70         JunkScore junk = new ComposedJunkScore(getJunkScore(KEY1, SCORE1), getJunkScore(KEY2, SCORE2));
71     
72         assertEquals("Summarize score", junk.getCompleteStoredScores(),SCORE1 + SCORE2, 0d);
73
74         assertEquals("Get stored score", junk.getStoredScore(KEY1), SCORE1, 0d);
75         assertEquals("Get stored score", junk.getStoredScore(KEY2), SCORE2, 0d);
76     
77         assertEquals("Get Map", junk.getStoredScores().size(), 2);
78     
79         assertEquals("Reset Score", junk.resetStoredScores(), SCORE1 + SCORE2, 0d);
80     
81         assertEquals("No Score", junk.getCompleteStoredScores(), 0.0, 0d);
82         assertEquals("Empty Map", junk.getStoredScores().size(), 0);
83     
84     }
85     
86     public void testUnsuportedOperation() {
87         boolean exception1 = false;
88     
89         JunkScore junk = new ComposedJunkScore(getJunkScore(KEY1, SCORE1), getJunkScore(KEY2, SCORE2));
90         try {
91             junk.setStoredScore(KEY1, SCORE1);
92         } catch (UnsupportedOperationException JavaDoc e) {
93             exception1 = true;
94         }
95         
96         assertTrue("Unsupported operation", exception1);
97     
98     }
99 }
100
Popular Tags