1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.math;
19  
20  import java.util.Locale;
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * @version $Revision: 592705 $ $Date: 2007-11-07 04:10:22 -0700 (Wed, 07 Nov 2007) $
26   */
27  public class FunctionEvaluationExceptionTest extends TestCase {
28      
29      public void testConstructor(){
30          FunctionEvaluationException ex = new FunctionEvaluationException(0.0);
31          assertNull(ex.getCause());
32          assertNotNull(ex.getMessage());
33          assertTrue(ex.getMessage().indexOf("0") > 0);
34          assertEquals(0.0, ex.getArgument(), 0);
35      }
36      
37      public void testConstructorPatternArguments(){
38          String pattern = "Evaluation failed for argument = {0}";
39          Object[] arguments = { new Double(0.0) };
40          FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments);
41          assertNull(ex.getCause());
42          assertEquals(pattern, ex.getPattern());
43          assertEquals(arguments.length, ex.getArguments().length);
44          for (int i = 0; i < arguments.length; ++i) {
45              assertEquals(arguments[i], ex.getArguments()[i]);
46          }
47          assertFalse(pattern.equals(ex.getMessage()));
48          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
49      }
50  
51      public void testConstructorPatternArgumentsCause(){
52          String pattern = "Evaluation failed for argument = {0}";
53          Object[] arguments = { new Double(0.0) };
54          String inMsg = "inner message";
55          Exception cause = new Exception(inMsg);
56          FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments, cause);
57          assertEquals(cause, ex.getCause());
58          assertEquals(pattern, ex.getPattern());
59          assertEquals(arguments.length, ex.getArguments().length);
60          for (int i = 0; i < arguments.length; ++i) {
61              assertEquals(arguments[i], ex.getArguments()[i]);
62          }
63          assertFalse(pattern.equals(ex.getMessage()));
64          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
65      }
66  
67      public void testConstructorArgumentCause(){
68          String inMsg = "inner message";
69          Exception cause = new Exception(inMsg);
70          FunctionEvaluationException ex = new FunctionEvaluationException(0.0, cause);
71          assertEquals(cause, ex.getCause());
72          assertTrue(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
73      }
74  
75  }