001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.jump.common;
025:
026: import junit.framework.*;
027:
028: import java.util.HashSet;
029:
030: public class JUMPApplicationTest extends TestCase {
031:
032: /*
033: * Just a simple test to verify equals() and hashcode().
034: */
035:
036: JUMPApplication[] set1; // different app type
037:
038: HashSet hash = new HashSet();
039:
040: public void setUp() {
041:
042: set1 = new JUMPApplication[4];
043: set1[0] = new JUMPApplication("app1", null, JUMPAppModel.XLET,
044: 1);
045: set1[1] = new JUMPApplication("app1", null, JUMPAppModel.MAIN,
046: 1);
047: set1[2] = new JUMPApplication("app1", null,
048: JUMPAppModel.MIDLET, 1);
049: set1[3] = new JUMPApplication("app1", null,
050: JUMPAppModel.MIDLET, -1);
051: }
052:
053: public void testSet1_equals() {
054: for (int i = 0; i < (set1.length - 1); i++) {
055: assertFalse(set1[i].equals(set1[i + 1]));
056: }
057: }
058:
059: public void testSet1_hash() {
060: hash.clear();
061: for (int i = 0; i < set1.length; i++) {
062: hash.add(set1[i]);
063: }
064:
065: assert (hash.size() == set1.length);
066:
067: for (int i = 0; i < (set1.length - 1); i++) {
068: hash.remove(set1[i]);
069: }
070:
071: assert (hash.size() == 1);
072: assert (hash.contains(set1[set1.length - 1]));
073: }
074:
075: public void testSet1_copy() {
076: for (int i = 0; i < set1.length; i++) {
077: JUMPApplication app = set1[i];
078:
079: byte[] appArray = app.toByteArray();
080:
081: JUMPApplication app2 = JUMPApplication
082: .fromByteArray(appArray);
083:
084: assert (!(app == app2));
085: assert (app.equals(app2));
086: assert (app.hashCode() == app2.hashCode());
087: }
088: }
089:
090: public void test_bytearray() {
091: try {
092: JUMPApplication app = JUMPApplication
093: .fromByteArray(new byte[0]);
094: fail("JUMPApplication created from an empty byte array"
095: + app);
096: } catch (IllegalArgumentException e) {
097: //success
098: }
099: }
100: }
|