1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.lib.uno.environments.remote;
25 
26 import java.util.Arrays;
27 
28 import org.junit.Test;
29 import static org.junit.Assert.*;
30 
31 public final class ThreadId_Test {
32     @Test
test()33     public void test() {
34         ThreadId i1 = ThreadId.createFresh();
35         assertTrue(i1.equals(i1));
36         assertTrue(!i1.equals(null));
37         assertTrue(!i1.equals(new Object()));
38         assertTrue(i1.hashCode() == i1.hashCode());
39         byte[] i1bytes = i1.getBytes();
40         assertTrue(i1bytes != null);
41         assertTrue(
42             i1bytes.length >= 5 && i1bytes[0] == 'j' && i1bytes[1] == 'a'
43             && i1bytes[2] == 'v' && i1bytes[3] == 'a' && i1bytes[4] == ':');
44         assertTrue(Arrays.equals(i1bytes, i1.getBytes()));
45 
46         ThreadId i2 = ThreadId.createFresh();
47         assertTrue(!i1.equals(i2));
48         assertTrue(!i2.equals(i1));
49         assertTrue(!Arrays.equals(i1bytes, i2.getBytes()));
50 
51         ThreadId i3 = new ThreadId(i1bytes);
52         assertTrue(i3.equals(i1));
53         assertTrue(!i3.equals(i2));
54         assertTrue(i1.equals(i3));
55         assertTrue(i1.hashCode() == i3.hashCode());
56         assertTrue(Arrays.equals(i1bytes, i3.getBytes()));
57     }
58 }
59