You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by fr...@apache.org on 2009/02/08 16:29:17 UTC

svn commit: r742121 - in /incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons: ErrorTypeTest.java ErrorsTest.java OptionEntryTest.java

Author: francisdb
Date: Sun Feb  8 15:29:17 2009
New Revision: 742121

URL: http://svn.apache.org/viewvc?rev=742121&view=rev
Log:
some more unit tests

Added:
    incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorTypeTest.java
    incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java
    incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/OptionEntryTest.java

Added: incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorTypeTest.java?rev=742121&view=auto
==============================================================================
--- incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorTypeTest.java (added)
+++ incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorTypeTest.java Sun Feb  8 15:29:17 2009
@@ -0,0 +1,20 @@
+package org.apache.empire.commons;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ErrorTypeTest
+{
+
+	@Test
+	public void testErrorType()
+	{
+		// TODO maybe we should find the highest param as some might not be in use (regex)
+		ErrorType errorType = new ErrorType("key", " {0} and {1} and {3} is {2}");
+		assertEquals(4, errorType.getNumParams());
+		assertEquals("key", errorType.getKey());
+		assertEquals(" {0} and {1} and {3} is {2}", errorType.getMessagePattern());
+	}
+
+}

Added: incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java?rev=742121&view=auto
==============================================================================
--- incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java (added)
+++ incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/ErrorsTest.java Sun Feb  8 15:29:17 2009
@@ -0,0 +1,71 @@
+package org.apache.empire.commons;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ErrorsTest
+{
+
+	
+	@Test
+	public void testGetErrorMessage()
+	{
+		
+		ErrorInfo info = new DummyErrorInfo(true, Errors.InvalidArg, new Object[]{"test", "testparam"});
+		assertEquals("Invalid Argument test for parameter testparam.", Errors.getErrorMessage(info));
+		
+		// TODO should we fail in this case?
+		// TODO find a way to force the correct number of params at compiletime
+		info = new DummyErrorInfo(true, Errors.InvalidArg, new Object[]{"test"});
+		assertEquals("Invalid Argument test for parameter {1}.", Errors.getErrorMessage(info));
+	
+		assertEquals("", Errors.getErrorMessage(null));		
+		
+		info = new DummyErrorInfo(false, Errors.Internal, null);
+		assertEquals("", Errors.getErrorMessage(info));
+		
+		info = new DummyErrorInfo(true, null, null);
+		assertEquals("", Errors.getErrorMessage(info));
+		
+		info = new DummyErrorInfo(true, Errors.None, null);
+		assertEquals("", Errors.getErrorMessage(info));
+	}
+	
+	private final class DummyErrorInfo implements ErrorInfo
+	{
+		private final boolean hasErrror;
+		private final ErrorType type;
+		private final Object[] params;
+		
+		public DummyErrorInfo(final boolean hasError, final ErrorType type, final Object[] params)
+		{
+			this.hasErrror = hasError;
+			this.type = type;
+			this.params = params;
+		}
+		
+		public Object[] getErrorParams()
+		{
+			return params;
+		}
+
+		public String getErrorSource()
+		{
+			return "JUnit";
+		}
+
+		public ErrorType getErrorType()
+		{
+			return type;
+		}
+
+		public boolean hasError()
+		{
+			return hasErrror;
+		}
+	}
+
+	
+
+}

Added: incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/OptionEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/OptionEntryTest.java?rev=742121&view=auto
==============================================================================
--- incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/OptionEntryTest.java (added)
+++ incubator/empire-db/branches/maven/empire-db/src/test/java/org/apache/empire/commons/OptionEntryTest.java Sun Feb  8 15:29:17 2009
@@ -0,0 +1,38 @@
+package org.apache.empire.commons;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class OptionEntryTest
+{
+
+	@Test
+	public void testOptionEntry()
+	{
+		OptionEntry entry = new OptionEntry(Boolean.TRUE, "junit");
+		assertEquals(Boolean.TRUE, entry.getValue());
+		assertEquals("junit", entry.getText());
+	}
+	
+	@Test
+	public void testGetValueString()
+	{
+		// TODO add javadoc to this method
+		OptionEntry entry = new OptionEntry(Boolean.TRUE, "junit");
+		assertEquals("true", entry.getValueString());
+		entry = new OptionEntry(null, "junit");
+		assertEquals("", entry.getValueString());
+	}
+
+	@Test
+	public void testGetSetText()
+	{
+		OptionEntry entry = new OptionEntry(Boolean.TRUE, "junit");
+		entry.setText(null);
+		assertEquals(null, entry.getText());
+		entry.setText("updated");
+		assertEquals("updated", entry.getText());
+	}
+
+}