0
|
1 /*
|
|
2 * ConnectBot: simple, powerful, open-source SSH client for Android
|
|
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
|
|
4 *
|
|
5 * Licensed under the Apache License, Version 2.0 (the "License");
|
|
6 * you may not use this file except in compliance with the License.
|
|
7 * You may obtain a copy of the License at
|
|
8 *
|
|
9 * http://www.apache.org/licenses/LICENSE-2.0
|
|
10 *
|
|
11 * Unless required by applicable law or agreed to in writing, software
|
|
12 * distributed under the License is distributed on an "AS IS" BASIS,
|
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14 * See the License for the specific language governing permissions and
|
|
15 * limitations under the License.
|
|
16 */
|
|
17
|
|
18 package com.five_ten_sg.connectbot;
|
|
19
|
|
20 import com.five_ten_sg.connectbot.bean.HostBean;
|
|
21 import com.five_ten_sg.connectbot.mock.BeanTestCase;
|
|
22
|
|
23 import android.test.AndroidTestCase;
|
|
24
|
|
25 /**
|
|
26 * @author Kenny Root
|
|
27 *
|
|
28 */
|
|
29 public class HostBeanTest extends AndroidTestCase {
|
|
30 private static final String[] FIELDS = { "nickname", "username",
|
|
31 "hostname", "port"
|
|
32 };
|
|
33
|
|
34 HostBean host1;
|
|
35 HostBean host2;
|
|
36
|
|
37 @Override
|
|
38 protected void setUp() throws Exception {
|
|
39 super.setUp();
|
|
40 host1 = new HostBean();
|
|
41 host1.setNickname("Home");
|
|
42 host1.setUsername("bob");
|
|
43 host1.setHostname("server.example.com");
|
|
44 host1.setPort(22);
|
|
45 host2 = new HostBean();
|
|
46 host2.setNickname("Home");
|
|
47 host2.setUsername("bob");
|
|
48 host2.setHostname("server.example.com");
|
|
49 host2.setPort(22);
|
|
50 }
|
|
51
|
|
52 @Override
|
|
53 protected void tearDown() throws Exception {
|
|
54 super.tearDown();
|
|
55 }
|
|
56
|
|
57 public void testIdEquality() {
|
|
58 host1.setId(1);
|
|
59 host2.setId(1);
|
|
60 assertTrue(host1.equals(host2));
|
|
61 assertTrue(host1.hashCode() == host2.hashCode());
|
|
62 }
|
|
63
|
|
64 public void testIdInequality() {
|
|
65 host1.setId(1);
|
|
66 host2.setId(2);
|
|
67 // HostBeans shouldn't be equal when their IDs are not the same
|
|
68 assertFalse("HostBeans are equal when their ID is different", host1
|
|
69 .equals(host2));
|
|
70 assertFalse("HostBean hash codes are equal when their ID is different",
|
|
71 host1.hashCode() == host2.hashCode());
|
|
72 }
|
|
73
|
|
74 public void testIdEquality2() {
|
|
75 host1.setId(1);
|
|
76 host2.setId(1);
|
|
77 host2.setNickname("Work");
|
|
78 host2.setUsername("alice");
|
|
79 host2.setHostname("client.example.com");
|
|
80 assertTrue(
|
|
81 "HostBeans are not equal when their ID is the same but other fields are different!",
|
|
82 host1.equals(host2));
|
|
83 assertTrue(
|
|
84 "HostBeans hashCodes are not equal when their ID is the same but other fields are different!",
|
|
85 host1.hashCode() == host2.hashCode());
|
|
86 }
|
|
87
|
|
88 public void testBeanMeetsEqualsContract() {
|
|
89 BeanTestCase.assertMeetsEqualsContract(HostBean.class, FIELDS);
|
|
90 }
|
|
91
|
|
92 public void testBeanMeetsHashCodeContract() {
|
|
93 BeanTestCase.assertMeetsHashCodeContract(HostBean.class, FIELDS);
|
|
94 }
|
|
95 }
|