Commits

Stephen McKamey  committed c47e525

- stubbing out more tests

  • Participants
  • Parent commits 5b7a049

Comments (0)

Files changed (2)

File src/org/duelengine/duel/DuelData.java

 	 * @return
 	 */
 	public static boolean coerceBoolean(Object data) {
-		return
-			!(data == null ||
-			Boolean.FALSE.equals(data) ||
-			"".equals(data) ||
-			ZERO.equals(data) ||
-			NaN.equals(data));
+		if (data == null || Boolean.FALSE.equals(data) || "".equals(data)) {
+			return false;
+		}
+
+		if (data instanceof Number) {
+			data = ((Number)data).doubleValue();
+			return !(ZERO.equals(data) || NaN.equals(data));
+		}
+
+		return true;
 	}
 
 	/**

File test/org/duelengine/duel/DuelDataTests.java

+package org.duelengine.duel;
+
+import static org.junit.Assert.*;
+import java.util.Date;
+import org.junit.Test;
+
+public class DuelDataTests {
+
+	@Test
+	public void coerceBooleanNullTest() {
+		Object input = null;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanFalseTest() {
+		Object input = false;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanEmptyStringTest() {
+		Object input = "";
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanZeroIntTest() {
+		Object input = 0;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanZeroDoubleTest() {
+		Object input = 0.0;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanZeroLongTest() {
+		Object input = 0L;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanNaNTest() {
+		Object input = Double.NaN;
+
+		boolean expected = false;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanTrueTest() {
+		Object input = true;
+
+		boolean expected = true;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanOneTest() {
+		Object input = 1.0;
+
+		boolean expected = true;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+
+	@Test
+	public void coerceBooleanDateTest() {
+		Object input = new Date();
+
+		boolean expected = true;
+
+		boolean actual = DuelData.coerceBoolean(input);
+
+		assertEquals(expected, actual);
+	}
+}