Commits

Mark Lassau committed fbf8d97

testGetSingularObjectFromString

  • Participants
  • Parent commits ad11842

Comments (0)

Files changed (1)

File src/test/java/com/example/plugins/tutorial/jira/customfields/MoneyCustomFieldTest.java

 package com.example.plugins.tutorial.jira.customfields;
 
-import org.junit.After;
-import org.junit.Before;
+import com.atlassian.jira.issue.customfields.impl.FieldValidationException;
 import org.junit.Test;
-import com.example.plugins.tutorial.jira.customfields.MoneyCustomField;
 
 import java.math.BigDecimal;
 
-import static org.mockito.Mockito.*;
-import static junit.framework.TestCase.*;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.fail;
 
 public class MoneyCustomFieldTest {
 
         assertEquals("3.03", moneyCustomField.getSingularObjectFromString("3.03").toString());
         assertEquals("3.20", moneyCustomField.getSingularObjectFromString("3.2").toString());
         // Now test the errors:
-        assertFieldValidationException("", moneyCustomField.getSingularObjectFromString("3.203"));
-        
-        assertEquals("3.202", moneyCustomField.getSingularObjectFromString("3.203").toString());
+        try
+        {
+            moneyCustomField.getSingularObjectFromString("3 dollars");
+            fail("Validation should have failed.");
+        }
+        catch (FieldValidationException ex)
+        {
+            assertEquals("Not a valid number.", ex.getMessage());
+        }
+        try
+        {
+            moneyCustomField.getSingularObjectFromString("3.203");
+            fail("Validation should have failed.");
+        }
+        catch (FieldValidationException ex)
+        {
+            assertEquals("Maximum of 2 decimal places are allowed.", ex.getMessage());
+        }
     }
 
-    private void assertFieldValidationException(final String expectedMessage, final BigDecimal singularObjectFromString) {}
-
 }