📄 sorttest.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.mailclient.cm.rms;
import com.funambol.mailclient.cm.Contact;
import com.funambol.mailclient.cm.ContactManager;
import com.funambol.mailclient.cm.ContactManagerException;
import com.funambol.mailclient.cm.ContactManagerFactory;
import com.funambol.mailclient.cm.rms.*;
import com.funambol.util.Log;
import java.util.Enumeration;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import jmunit.framework.cldc10.*;
public class SortTest extends TestCase {
private RMSContactManager rcm;
private Contact[] contactList;
private void testSearchIgnoreCase(String filter) throws Exception{
Log.info("3.Lower case search test");
Enumeration expected = rcm.searchContacts(filter);
int num = 0;
Contact c = null;
while (expected.hasMoreElements()) {
c = (Contact) expected.nextElement();
num++;
assertEquals(c.getNickName(), "beppe");
}
assertEquals(1, num);
Log.info("3.Lower case search test succesfull");
}
private void testSort() throws Exception{
Log.info("2.Sort Contact List test");
Enumeration expected = rcm.getContactList();
int num = 0;
while (expected.hasMoreElements()) {
contactList[num] = (Contact) expected.nextElement();
Log.debug(contactList[num].getNickName()+" "+contactList[num].
getLastName()+" "+contactList[num].getFirstName());
num++;
}
assertEquals(7, num);
assertEquals("anybody", contactList[0].getNickName());
assertTrue(contactList[0].getLastName()==null);
assertEquals("anonymous", contactList[0].getFirstName());
assertEquals("beppe", contactList[1].getNickName());
assertTrue(contactList[1].getLastName()==null);
assertEquals("Giuseppe", contactList[1].getFirstName());
assertEquals("Billy", contactList[2].getNickName());
assertEquals("Gates", contactList[2].getLastName());
assertEquals("Bill", contactList[2].getFirstName());
assertEquals("GangMan", contactList[3].getNickName());
assertEquals("Capone", contactList[3].getLastName());
assertEquals("Al", contactList[3].getFirstName());
assertEquals("Linus friend", contactList[4].getNickName());
assertEquals("Torvald", contactList[4].getLastName());
assertEquals("Adam", contactList[4].getFirstName());
assertEquals("Linux", contactList[5].getNickName());
assertEquals("Torvald", contactList[5].getLastName());
assertEquals("Linus", contactList[5].getFirstName());
assertEquals("Paul", contactList[6].getNickName());
assertEquals("McCartney", contactList[6].getLastName());
assertEquals("Paul", contactList[6].getFirstName());
Log.info("2.Sort Contact List test succesfull");
}
private void testFilter() throws Exception{
Log.info("1.Filter Contact List test");
for (int i=0; i<contactList.length; i++) {
rcm.addContact(contactList[i]);
}
Enumeration expected = rcm.searchContacts("Al");
int num = 0;
Contact c = null;
while (expected.hasMoreElements()) {
c = (Contact) expected.nextElement();
Log.debug(c.getVisibleName());
num++;
}
assertEquals(3, num);
Log.info("1.Filter Contact List test succesfull");
}
public SortTest() {
super(3,"RMSContactManagerTest");
try {
createTestObjects();
} catch (ContactManagerException ex) {
ex.printStackTrace();
}
}
public void test(int testNumber) throws Throwable {
switch(testNumber) {
case 0:
testFilter();
break;
case 1:
testSort();
break;
case 2:
testSearchIgnoreCase("BEPPE");
testSearchIgnoreCase("BePPE");
testSearchIgnoreCase("BEpPE");
testSearchIgnoreCase("BEppE");
testSearchIgnoreCase("BeppE");
testSearchIgnoreCase("Beppe");
testSearchIgnoreCase("beppe");
testSearchIgnoreCase("be");
testSearchIgnoreCase("Be");
testSearchIgnoreCase("bE");
testSearchIgnoreCase("BE");
break;
default:
break;
}
}
private void createTestObjects() throws ContactManagerException {
System.gc();
RecordStore rs = null;
try {
RecordStore.deleteRecordStore(RMSContactManager.CONTACT_STORE);
Log.info("Contact Store deleted");
} catch (Exception ex1) {
Log.info("Cannot delete Contact Store");
}
try {
rcm = (RMSContactManager)
ContactManagerFactory.getContactManager(ContactManager.RMS_TYPE);
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
contactList = new Contact[7];
contactList[0] = new Contact(
"GangMan",
"Al",
"Capone",
"alMail",
"",
"",
null,
null,
"");
contactList[1] = new Contact(
"Billy",
"Bill",
"Gates",
"BillMail",
"",
"",
null,
null,
null);
contactList[2] = new Contact(
"Linux",
"Linus",
"Torvald",
"LinusMail",
"",
"",
null,
null,
null);
contactList[3] = new Contact(
"Paul",
"Paul",
"McCartney",
"PaulMail",
null,
null,
null,
null,
null);
contactList[4] = new Contact(
"anybody",
"anonymous",
null,
"anonymousmail1",
null,
null,
"phone1",
null,
null);
contactList[5] = new Contact(
"beppe",
"Giuseppe",
null,
"beppemail1",
null,
null,
"phone1",
null,
null);
contactList[6] = new Contact(
"Linus friend",
"Adam",
"Torvald",
"adammail1",
null,
null,
"",
null,
null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -