001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.utils; 021 022import org.junit.Assert; 023import org.junit.Test; 024 025/** 026 * Test for {@link Size2D}. 027 * @author <a href="mailto:cher@riedquat.de">Christian Hujer</a> 028 */ 029@SuppressWarnings("FeatureEnvy") 030// This is a test. It has feature envy by definition. 031public class Size2DTest { 032 033 /** 034 * Test case for {@link Size2D#Size2D(int, int)}. 035 */ 036 @Test 037 public void testSize2D() { 038 final Size2D size = new Size2D(100, 200); 039 Assert.assertEquals("width MUST be stored", 100, size.getWidth()); 040 Assert.assertEquals("height MUST be stored", 200, size.getHeight()); 041 } 042 043 /** 044 * Test case for {@link Size2D#equals(Object)}. 045 */ 046 @Test 047 public void testEquals() { 048 final Size2D size1 = new Size2D(100, 200); 049 final Size2D size2 = new Size2D(100, 200); 050 final Size2D size3 = new Size2D(100, 200); 051 final Size2D differWidth = new Size2D(50, 200); 052 final Size2D differHeight = new Size2D(100, 80); 053 final Size2D differBoth = new Size2D(50, 80); 054 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size1, size2); 055 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size1, size3); 056 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size2, size1); 057 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size2, size3); 058 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size3, size1); 059 Assert.assertEquals("Sizes with identical width and height MUST be equal.", size3, size2); 060 Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differBoth)); 061 Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differWidth)); 062 Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differHeight)); 063 } 064 065 /** 066 * Test case for {@link Size2D#hashCode()}. 067 */ 068 @Test 069 public void testHashCode() { 070 final Size2D size1 = new Size2D(100, 200); 071 final Size2D size2 = new Size2D(100, 200); 072 Assert.assertEquals("Equal sizes MUST return the same hashCode.", size1.hashCode(), size2.hashCode()); 073 } 074 075 /** 076 * Test case for {@link Size2D#getWidth()}. 077 */ 078 @Test 079 public void testGetWidth() { 080 final Size2D size = new Size2D(100, 200); 081 Assert.assertEquals("width MUST be stored", 100, size.getWidth()); 082 } 083 084 /** 085 * Test case for {@link Size2D#getHeight()}. 086 */ 087 @Test 088 public void testGetHeight() { 089 final Size2D size = new Size2D(100, 200); 090 Assert.assertEquals("height MUST be stored", 200, size.getHeight()); 091 } 092 093}