KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > async > LocationTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.kaha.impl.async;
19
20 import java.io.IOException JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23
24 import org.apache.activemq.kaha.impl.async.Location;
25 import org.apache.activemq.kaha.impl.async.JournalFacade.RecordLocationFacade;
26
27 import junit.framework.TestCase;
28
29 /**
30  * Tests the Location Class
31  *
32  * @version $Revision: 1.1 $
33  */

34 public class LocationTest extends TestCase {
35         
36     @SuppressWarnings JavaDoc("unchecked")
37     synchronized public void testRecordLocationImplComparison() throws IOException JavaDoc {
38         Location l1 = new Location();
39         l1.setDataFileId(0);
40         l1.setOffset(5);
41         Location l2 = new Location(l1);
42         l2.setOffset(10);
43         Location l3 = new Location(l2);
44         l3.setDataFileId(2);
45         l3.setOffset(0);
46
47         assertTrue( l1.compareTo(l2)<0 );
48         
49         // Sort them using a list. Put them in the wrong order.
50
ArrayList JavaDoc<RecordLocationFacade> l = new ArrayList JavaDoc<RecordLocationFacade>();
51         l.add(new RecordLocationFacade(l2));
52         l.add(new RecordLocationFacade(l3));
53         l.add(new RecordLocationFacade(l1));
54         Collections.sort(l);
55         
56         // Did they get sorted to the correct order?
57
System.out.println(l.get(0));
58         assertSame( l.get(0).getLocation(), l1 );
59         assertSame( l.get(1).getLocation(), l2 );
60         assertSame( l.get(2).getLocation(), l3 );
61     }
62 }
63
Popular Tags