harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Loenko" <mloe...@gmail.com>
Subject Re: [classlib][util] HARMONY-574: Java 5 Enhancement:new class java.util.PriorityQueue
Date Fri, 16 Jun 2006 04:36:04 GMT
One more wtih the tests:

    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    public void test_SerializationCompatibility() throws Exception {
        Integer[] array = { 2, 45, 7, -12, 9, 23, 17, 1118, 10, 16, 39 };
        List<Integer> list = Arrays.asList(array);
        PriorityQueue<Integer> srcIntegerQueue = new PriorityQueue<Integer>(
                list);
        PriorityQueue<Integer> destStringQueue =
(PriorityQueue<Integer>) SerializationTester
                .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
    }

    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    public void test_SerializationCompatibility_cast() throws Exception {
        Integer[] array = { 2, 45, 7, -12, 9, 23, 17, 1118, 10, 16, 39 };
        List<Integer> list = Arrays.asList(array);
        PriorityQueue<Integer> srcIntegerQueue = new PriorityQueue<Integer>(
                list);
        PriorityQueue<String> destStringQueue =
(PriorityQueue<String>) SerializationTester
                .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);

        // will not incur class cast exception.
        Object o = destStringQueue.peek();
        Arrays.sort(array);
        Integer I = (Integer) o;
        assertEquals(array[0], I);
    }

the first test differs from the beginning of the second one in the
following lines:
--- first test
        PriorityQueue<Integer> destStringQueue =
(PriorityQueue<Integer>) SerializationTester
                .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
--- second test
        PriorityQueue<String> destStringQueue =
(PriorityQueue<String>) SerializationTester
                .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);

But these line in both cases compile into the following:

   160:	invokestatic	#88; //Method
tests/util/SerializationTester.readObject:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
   163:	checkcast	#2; //class PriorityQueue
   166:	astore	4

So the first test is a subset of the second one and thus I'll remove it.

Thanks,
Mikhail

2006/6/16, Mikhail Loenko <mloenko@gmail.com>:
> Hi Paulex!
>
> fyi the following method:
>
>        public int compare(Object object1, Object object2) {
>            // test cast
>            E e1 = (E) object1;
>            E e2 = (E) object2;
>            return 0;
>        }
>
> compiles to the following bytecode:
>
>   0:   aload_1
>   1:   astore_3
>   2:   aload_2
>   3:   astore  4
>   5:   iconst_0
>   6:   ireturn
>
> So, it does not have any cast testing.
>
> I'll slightly update the test if you don't mind
>
> Thanks,
> Mikhail
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message