1 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 KEY1 = "KEY1"; 29 private final static double SCORE1 = 20.0; 30 private final static String KEY2 = "KEY2"; 31 private final static double SCORE2 = 2.0; 32 33 private JunkScore getJunkScore(String 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 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 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 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 e) { 93 exception1 = true; 94 } 95 96 assertTrue("Unsupported operation", exception1); 97 98 } 99 } 100 | Popular Tags |