git clone of logicmail with some fixes/features added
at master 167 lines 6.2 kB view raw
1/*- 2 * Copyright (c) 2009, Derek Konigsberg 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of the project nor the names of its 15 * contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31package org.logicprobe.LogicMail.model; 32 33import java.util.Vector; 34 35import net.rim.device.api.util.SimpleSortingVector; 36import j2meunit.framework.Test; 37import j2meunit.framework.TestCase; 38import j2meunit.framework.TestMethod; 39import j2meunit.framework.TestSuite; 40 41public class MailFileComparatorTest extends TestCase { 42 public MailFileComparatorTest() { 43 } 44 45 public MailFileComparatorTest(String testName, TestMethod testMethod) { 46 super(testName, testMethod); 47 } 48 49 public void setUp() { 50 } 51 52 public void tearDown() { 53 } 54 55 public void testSortImapFiles() { 56 String[] input = { 57 "74.msg", 58 "23.msg", 59 "a0.msg", 60 "ba.msg", 61 "104.msg", 62 "c.msg" 63 }; 64 65 String[] expected = { 66 "c.msg", 67 "23.msg", 68 "74.msg", 69 "a0.msg", 70 "ba.msg", 71 "104.msg" 72 }; 73 74 SimpleSortingVector vector = new SimpleSortingVector(); 75 vector.setSortComparator(new MailFileComparator()); 76 vector.setSort(true); 77 addAll(vector, input); 78 79 int size = vector.size(); 80 for(int i=0; i<size; i++) { 81 assertEquals("Item " + i, expected[i], vector.elementAt(i)); 82 } 83 } 84 85 public void testSortPopFiles() { 86 String[] input = { 87 "1255368645.133.msg", 88 "1255368645.134.msg", 89 "1255368645.135.msg", 90 "1255368645.88.msg", 91 "1255368645.89.msg", 92 "1255368645.90.msg" 93 }; 94 95 String[] expected = { 96 "1255368645.88.msg", 97 "1255368645.89.msg", 98 "1255368645.90.msg", 99 "1255368645.133.msg", 100 "1255368645.134.msg", 101 "1255368645.135.msg" 102 }; 103 104 SimpleSortingVector vector = new SimpleSortingVector(); 105 vector.setSortComparator(new MailFileComparator()); 106 vector.setSort(true); 107 addAll(vector, input); 108 109 int size = vector.size(); 110 for(int i=0; i<size; i++) { 111 assertEquals("Item " + i, expected[i], vector.elementAt(i)); 112 } 113 } 114 115// Cannot test this case until we try to pick hex numbers out of non-numeric 116// strings. Since every mail server may use a different format for these, 117// it almost might make sense to just to research and implement several 118// different special cases. 119// public void testSortOtherFiles() { 120// String[] input = { 121// "AmailId1238a4df5d3901c1", 122// "AmailId12282f454e1f7cde", 123// "AmailId1235dcec9a38af53", 124// "AmailId1236766c21a73c07", 125// "AmailId123a65a0783f0692", 126// "AmailId122a05f95ad37fb9" 127// }; 128// 129// String[] expected = { 130// "AmailId12282f454e1f7cde", 131// "AmailId122a05f95ad37fb9", 132// "AmailId1235dcec9a38af53", 133// "AmailId1236766c21a73c07", 134// "AmailId1238a4df5d3901c1", 135// "AmailId123a65a0783f0692" 136// }; 137// 138// SimpleSortingVector vector = new SimpleSortingVector(); 139// vector.setSortComparator(new MailFileComparator()); 140// vector.setSort(true); 141// addAll(vector, input); 142// 143// int size = vector.size(); 144// for(int i=0; i<size; i++) { 145// assertEquals("Item " + i, expected[i], vector.elementAt(i)); 146// } 147// } 148 149 private static void addAll(Vector vector, Object[] source) { 150 for(int i=0; i<source.length; i++) { 151 vector.addElement(source[i]); 152 } 153 } 154 155 public Test suite() { 156 TestSuite suite = new TestSuite("MailFileComparator"); 157 158 suite.addTest(new MailFileComparatorTest("sortImapFiles", new TestMethod() 159 { public void run(TestCase tc) {((MailFileComparatorTest)tc).testSortImapFiles(); } })); 160 suite.addTest(new MailFileComparatorTest("sortPopFiles", new TestMethod() 161 { public void run(TestCase tc) {((MailFileComparatorTest)tc).testSortPopFiles(); } })); 162// suite.addTest(new MailFileComparatorTest("sortOtherFiles", new TestMethod() 163// { public void run(TestCase tc) {((MailFileComparatorTest)tc).testSortOtherFiles(); } })); 164 165 return suite; 166 } 167}