/* * FormulaFunction_MidTest.java * JUnit based test * * Created on August 9, 2006, 9:50 AM */ package com.accountingenhancements.formula; import com.accountingenhancements.common.SupportParameters; import junit.framework.*; import java.text.ParseException; import java.util.HashMap; /** * * @author lofgren */ public class FormulaFunction_MidTest extends TestCase { public FormulaFunction_MidTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(FormulaFunction_MidTest.class); return suite; } /** * Test of solve method, of class com.accountingenhancements.formula.FormulaFunction_Mid. */ public void testFunction() throws Exception { System.out.println("function"); FormulaVariableList variableList = null; int iteration = 0; SupportParameters supportParameters = null; FormulaFunctionList functionList = null; int resolveEverythingAboveLevel = 0; FormulaFunction instance = new FormulaFunction_Mid(new FormulaVariable("","Mid(\"Hi There\",3,4)",0,true)); String expResult = "Ther"; FormulaVariable result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result.getString()); instance = new FormulaFunction_Mid(new FormulaVariable("","Mid(\"Hi There\",3,10)",0,true)); expResult = "There"; result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result.getString()); instance = new FormulaFunction_Mid(new FormulaVariable("","Mid(\"Hi There\",-1,10)",0,true)); expResult = "Hi There"; result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result.getString()); instance = new FormulaFunction_Mid(new FormulaVariable("","Mid(\"Hi There\",3,0)",0,true)); expResult = ""; result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result.getString()); instance = new FormulaFunction_Mid(new FormulaVariable("","Mid(\"Hi There\",10,1)",0,true)); expResult = ""; result = instance.function(variableList, iteration, supportParameters, functionList, resolveEverythingAboveLevel); assertEquals(expResult, result.getString()); } /** * Test of getName method, of class com.accountingenhancements.formula.FormulaFunction_Mid. */ public void testGetName()throws Exception { System.out.println("getName"); Class thisClass = Class.forName("com.accountingenhancements.formula.FormulaFunction_Mid"); String expResult = "Mid"; String result = (String)thisClass.getMethod("getName").invoke(thisClass); assertTrue("Was: <"+result+"> Expected: <"+expResult+">",expResult.equals(result)); } /** * Test of getRequiredSupportParameters method, of class com.accountingenhancements.formula.FormulaFunction_Mid. */ public void testGetRequiredSupportParameters()throws Exception { System.out.println("getRequiredSupportParameters"); String[][] result = FormulaFunction_Mid.getRequiredSupportParameters(); assertEquals(0, result.length); } /** * Test of getRequiredFormulaVariables method, of class com.accountingenhancements.formula.FormulaFunction_Mid. */ public void testGetRequiredFormulaVariables()throws Exception { System.out.println("getRequiredFormulaVariables"); String[][] result = FormulaFunction_Mid.getRequiredFormulaVariables(); assertEquals(0, result.length); } /** * Test of getRequiredArguments method, of class com.accountingenhancements.formula.FormulaFunction_Mid. */ public void testGetRequiredArguments()throws Exception { System.out.println("getRequiredArguments"); String expResult = null; String[][] result = FormulaFunction_Mid.getRequiredArguments(); assertEquals(3,result.length); assertEquals(2,result[0].length); assertEquals(2,result[1].length); assertEquals(2,result[2].length); expResult="ARG1: The source String from which the middle is to be returned"; assertEquals(expResult,result[0][0]); expResult="TYPE_?"; assertEquals(expResult,result[0][1]); expResult="ARG2: The starting position of the source from which the result is to be return. If the source is less than this starting point then an empty string will be returned"; assertEquals(expResult,result[1][0]); expResult="TYPE_LONG"; assertEquals(expResult,result[1][1]); expResult="ARG3(Optional): The Length of the segment t be returned. If the end of the String is reached before this size is reached, the string will be shorter than this size."; assertEquals(expResult,result[2][0]); expResult="TYPE_LONG"; assertEquals(expResult,result[2][1]); } /** * Test of getReturnValueDescription method, of class com.accountingenhancements.formula.FormulaFunction_IIF. */ public void testGetReturnValueDescription()throws Exception { System.out.println("getReturnValueDescription"); String[] returnValueDescription = {"Middle section of string ARG1 starting at position ARG2 and not exceeding the length specified in ARG3.","TYPE_STRING"}; assertEquals(returnValueDescription[0],FormulaFunction_Mid.getReturnValueDescription()[0]); assertEquals(returnValueDescription[1],FormulaFunction_Mid.getReturnValueDescription()[1]); } }