View Javadoc
1   /******************************************************************************
2    * TestPlayer.java - Test the Player domain object 
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2011 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.2  2011/05/07 06:20:54  dick
10   * Test the rest of the domain package.
11   *
12   */
13  
14  /* 
15   * This program is free software: you can redistribute it and/or modify
16   * it under the terms of the GNU General Public License as published by
17   * the Free Software Foundation, either version 3 of the License, or
18   * (at your option) any later version.
19   *
20   * This program is distributed in the hope that it will be useful,
21   * but WITHOUT ANY WARRANTY; without even the implied warranty of
22   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   * GNU General Public License for more details.
24   *
25   * You should have received a copy of the GNU General Public License
26   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27   *
28   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
29   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
30   * 
31   */
32  package com.buckosoft.fibs.domain;
33  
34  import junit.framework.TestCase;
35  
36  import org.junit.Before;
37  import org.junit.Test;
38  
39  import com.buckosoft.fibs.domain.Player;
40  import com.buckosoft.fibs.domain.WinLoss;
41  
42  /** Test the {@link com.buckosoft.fibs.domain.Player} domain object
43   * @author dick
44   *
45   */
46  public class TestPlayer extends TestCase {
47  	private	Player p = null;
48  	private String s_TestPlayer = "TestPlayer";
49  	/**
50  	 * @throws java.lang.Exception
51  	 */
52  	@Before
53  	public void setUp() throws Exception {
54  		p = new Player();
55  	}
56  
57  	/**
58  	 * Test method for {@link com.buckosoft.fibs.domain.Player#Player()}.
59  	 */
60  	@Test
61  	public void testPlayer() {
62  		p = new Player();
63  		assertEquals(0, p.getId());
64  	}
65  
66  	/**
67  	 * Test method for {@link com.buckosoft.fibs.domain.Player#Player(java.lang.String)}.
68  	 */
69  	@Test
70  	public void testPlayerString() {
71  		p = new Player(s_TestPlayer);
72  		assertEquals(s_TestPlayer, p.getName());
73  	}
74  
75  	/**
76  	 * Test method for {@link com.buckosoft.fibs.domain.Player#getId()}.
77  	 */
78  	@Test
79  	public void testGetId() {
80  		p = new Player();
81  		assertEquals(0, p.getId());
82  	}
83  
84  	/**
85  	 * Test method for {@link com.buckosoft.fibs.domain.Player#setId(int)}.
86  	 */
87  	@Test
88  	public void testSetId() {
89  		p.setId(33);
90  		assertEquals(33, p.getId());
91  	}
92  
93  
94  	private static String psBroken = "5 rases bioman - 1 0 1736.07 12505 0 1304711466 cpe-69-207-165-55.rochester.res.rr.com 3DFiBs4.0.71";
95  	private static String ps0 = "5 rases bioman - 1 0 1736.07 12505 0 1304711466 cpe-69-207-165-55.rochester.res.rr.com 3DFiBs4.0.71 -";
96  	private static String psWatching = "5 BuckoFIBSa - Mahan 0 0 1682.77 5010 25 1304711865 75-144-150-169-NewEngland.hfc.comcastbusiness.net BuckoFIBS-0.7b -";
97  	private static String psReady = "5 BuckoFIBSa - - 1 0 1682.77 5010 2 1304717383 75-144-150-169-NewEngland.hfc.comcastbusiness.net BuckoFIBS-0.7b -";
98  	private static String psAway = "5 BuckoFIBSa - - 0 1 1682.77 5010 2 1304717383 75-144-150-169-NewEngland.hfc.comcastbusiness.net BuckoFIBS-0.7b -";
99  	/**
100 	 * Test method for {@link com.buckosoft.fibs.domain.Player#parsePlayer(java.lang.String)}.
101 	 */
102 	@Test
103 	public void testParsePlayer() {
104 		assertFalse(p.parsePlayer(psBroken));
105 		assertTrue(p.parsePlayer(ps0));
106 		assertEquals("rases", p.getName());
107 		assertEquals("bioman", p.getOpponent());
108 		assertEquals("", p.getWatching());
109 		assertTrue(p.parsePlayer(psWatching));
110 		assertEquals("Mahan", p.getWatching());
111 	}
112 
113 	/**
114 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getName()}.
115 	 */
116 	@Test
117 	public void testGetName() {
118 		p.setName(s_TestPlayer);
119 		assertEquals(s_TestPlayer, p.getName());
120 	}
121 
122 	/**
123 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setName(java.lang.String)}.
124 	 */
125 	@Test
126 	public void testSetName() {
127 		p.setName("Jane");
128 		assertEquals("Jane", p.getName());
129 	}
130 
131 	/**
132 	 * Test method for {@link com.buckosoft.fibs.domain.Player#isPlaying()}.
133 	 */
134 	@Test
135 	public void testIsPlaying() {
136 		p = new Player();
137 		assertFalse(p.isPlaying());
138 	}
139 
140 	/**
141 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getOpponent()}.
142 	 */
143 	@Test
144 	public void testGetOpponent() {
145 		assertTrue(p.parsePlayer(ps0));
146 		assertEquals("bioman", p.getOpponent());
147 		assertTrue(p.parsePlayer(psWatching));
148 		assertEquals("", p.getOpponent());
149 	}
150 
151 	/**
152 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getWatching()}.
153 	 */
154 	@Test
155 	public void testGetWatching() {
156 		assertTrue(p.parsePlayer(ps0));
157 		assertEquals("bioman", p.getOpponent());
158 		assertEquals("", p.getWatching());
159 		assertTrue(p.parsePlayer(psWatching));
160 		assertEquals("Mahan", p.getWatching());
161 	}
162 
163 	/**
164 	 * Test method for {@link com.buckosoft.fibs.domain.Player#isReady()}.
165 	 */
166 	@Test
167 	public void testIsReady() {
168 		assertTrue(p.parsePlayer(psReady));
169 		assertTrue(p.isReady());
170 	}
171 
172 	/**
173 	 * Test method for {@link com.buckosoft.fibs.domain.Player#isAway()}.
174 	 */
175 	@Test
176 	public void testIsAway() {
177 		assertTrue(p.parsePlayer(psWatching));
178 		assertFalse(p.isAway());
179 		assertTrue(p.parsePlayer(psReady));
180 		assertFalse(p.isAway());
181 		assertTrue(p.parsePlayer(psAway));
182 		assertTrue(p.isAway());
183 	}
184 
185 	/**
186 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getRating()}.
187 	 */
188 	@Test
189 	public void testGetRating() {
190 		assertTrue(p.parsePlayer(psWatching));
191 		assertEquals(1682.77, p.getRating());
192 	}
193 
194 	/**
195 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getExperience()}.
196 	 */
197 	@Test
198 	public void testGetExperience() {
199 		assertTrue(p.parsePlayer(psWatching));
200 		assertEquals(5010, p.getExperience());
201 	}
202 
203 	/**
204 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getIdleTime()}.
205 	 */
206 	@Test
207 	public void testGetIdleTime() {
208 		assertTrue(p.parsePlayer(psWatching));
209 		assertEquals(25, p.getIdleTime());
210 		assertTrue(p.parsePlayer(psReady));
211 		assertEquals(2, p.getIdleTime());
212 	}
213 
214 	/**
215 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getLoginTime()}.
216 	 */
217 	@Test
218 	public void testGetLoginTime() {
219 		assertTrue(p.parsePlayer(psWatching));
220 		assertEquals(1304711865, p.getLoginTime());
221 		assertTrue(p.parsePlayer(psReady));
222 		assertEquals(1304717383, p.getLoginTime());
223 	}
224 
225 	/**
226 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getHostName()}.
227 	 */
228 	@Test
229 	public void testGetHostName() {
230 		assertTrue(p.parsePlayer(psReady));
231 		assertEquals("75-144-150-169-NewEngland.hfc.comcastbusiness.net", p.getHostName());
232 		assertTrue(p.parsePlayer(ps0));
233 		assertEquals("cpe-69-207-165-55.rochester.res.rr.com", p.getHostName());
234 	}
235 
236 	/**
237 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getClient()}.
238 	 */
239 	@Test
240 	public void testGetClient() {
241 		assertTrue(p.parsePlayer(psReady));
242 		assertEquals("BuckoFIBS-0.7b", p.getClient());
243 		assertTrue(p.parsePlayer(ps0));
244 		assertEquals("3DFiBs4.0.71", p.getClient());
245 	}
246 
247 	/**
248 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setClient(java.lang.String)}.
249 	 */
250 	@Test
251 	public void testSetClient() {
252 		p.setClient("TestClient");
253 		assertEquals("TestClient", p.getClient());
254 	}
255 
256 	/**
257 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getEmail()}.
258 	 */
259 	@Test
260 	public void testGetEmail() {
261 		//XXX: fail("Not yet implemented");
262 	}
263 
264 	/**
265 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getWinLoss()}.
266 	 */
267 	@Test
268 	public void testGetWinLoss() {
269 		p = new Player();
270 		assertNull(p.getWinLoss());
271 		p.setWinLoss(0, 0);
272 		WinLoss wl = p.getWinLoss();
273 		assertEquals(0.0, wl.getValue());
274 		assertEquals("0-0", wl.toString());
275 		p.setWinLoss(3, 1);
276 		WinLoss wm = p.getWinLoss();
277 		assertEquals(3.0, wm.getValue());
278 		assertEquals("3-1", wm.toString());
279 		assertEquals(-1, wl.compareTo(wm));
280 		p.setWinLoss(0, 2);
281 		WinLoss wo = p.getWinLoss();
282 		assertEquals(-2.0, wo.getValue());
283 		assertEquals("0-2", wo.toString());
284 		assertEquals(-1, wo.compareTo(wl));
285 		assertEquals(1, wl.compareTo(wo));
286 		WinLoss we = new WinLoss();
287 		assertEquals(0, we.compareTo(we));
288 	}
289 
290 	/**
291 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setWinLoss(int, int)}.
292 	 */
293 	@Test
294 	public void testSetWinLoss() {
295 		p = new Player();
296 		assertNull(p.getWinLoss());
297 		p.setWinLoss(0, 0);
298 		WinLoss wl = p.getWinLoss();
299 		assertEquals(0.0, wl.getValue());
300 		assertEquals("0-0", wl.toString());
301 		p.setWinLoss(3, 1);
302 		WinLoss wm = p.getWinLoss();
303 		assertEquals(3.0, wm.getValue());
304 		assertEquals("3-1", wm.toString());
305 		assertEquals(-1, wl.compareTo(wm));
306 		assertEquals(1, wm.compareTo(wl));
307 	}
308 
309 	/**
310 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getBfFlag()}.
311 	 */
312 	@Test
313 	public void testGetBfFlag() {
314 		p.setBfFlag(0);
315 		assertEquals(0, p.getBfFlag());
316 	}
317 
318 	/**
319 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setBfFlag(int)}.
320 	 */
321 	@Test
322 	public void testSetBfFlag() {
323 		p.setBfFlag(0);
324 		assertEquals(0, p.getBfFlag());
325 	}
326 
327 	/**
328 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getBfStatus()}.
329 	 */
330 	@Test
331 	public void testGetBfStatus() {
332 		p.setBfStatus("Special");
333 		assertEquals("Special", p.getBfStatus());
334 	}
335 
336 	/**
337 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setBfStatus(java.lang.String)}.
338 	 */
339 	@Test
340 	public void testSetBfStatus() {
341 		p.setBfStatus("Special");
342 		assertEquals("Special", p.getBfStatus());
343 	}
344 
345 	/**
346 	 * Test method for {@link com.buckosoft.fibs.domain.Player#isInvited()}.
347 	 */
348 	@Test
349 	public void testIsInvited() {
350 		p = new Player();
351 		assertFalse(p.isInvited());
352 	}
353 
354 	/**
355 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setInvited(boolean)}.
356 	 */
357 	@Test
358 	public void testSetInvited() {
359 		p.setInvited(true);
360 		assertTrue(p.isInvited());
361 		p.setInvited(false);
362 		assertFalse(p.isInvited());
363 	}
364 
365 	/**
366 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getSavedMatch()}.
367 	 */
368 	@Test
369 	public void testGetSavedMatch() {
370 		p.setSavedMatch("SavedMatchTest");
371 		assertEquals("SavedMatchTest", p.getSavedMatch());
372 	}
373 
374 	/**
375 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setSavedMatch(java.lang.String)}.
376 	 */
377 	@Test
378 	public void testSetSavedMatch() {
379 		p.setSavedMatch("SavedMatchTest1");
380 		assertEquals("SavedMatchTest1", p.getSavedMatch());
381 	}
382 
383 	/**
384 	 * Test method for {@link com.buckosoft.fibs.domain.Player#getMissManners()}.
385 	 */
386 	@Test
387 	public void testGetMissManners() {
388 		p.setMissManners("TestMissManners");
389 		assertEquals("TestMissManners", p.getMissManners());
390 	}
391 
392 	/**
393 	 * Test method for {@link com.buckosoft.fibs.domain.Player#setMissManners(java.lang.String)}.
394 	 */
395 	@Test
396 	public void testSetMissManners() {
397 		p.setMissManners("TestMissManners1");
398 		assertEquals("TestMissManners1", p.getMissManners());
399 	}
400 
401 	/**
402 	 * Test method for {@link com.buckosoft.fibs.domain.Player#compareTo(com.buckosoft.fibs.domain.Player)}.
403 	 */
404 	@Test
405 	public void testCompareTo() {
406 		Player p1 = new Player("Alpha");
407 		Player p2 = new Player("Beta");
408 		assertEquals(-1, p1.compareTo(p2));
409 		assertEquals(1, p2.compareTo(p1));
410 		assertEquals(0, p1.compareTo(p1));
411 	}
412 
413 }