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 junit.framework.TestCase;
21  
22  import java.util.Locale;
23  
24  /**
25   * @version $Revision: 746578 $ $Date: 2009-02-21 15:01:14 -0500 (Sat, 21 Feb 2009) $
26   */
27  public class MathConfigurationExceptionTest extends TestCase {
28  
29      public void testConstructor(){
30          MathConfigurationException ex = new MathConfigurationException();
31          assertNull(ex.getCause());
32          assertNull(ex.getMessage());
33          assertEquals(0, ex.getMessage(Locale.FRENCH).length());
34      }
35      
36      public void testConstructorPatternArguments(){
37          String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
38          Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
39          MathConfigurationException ex = new MathConfigurationException(pattern, arguments);
40          assertNull(ex.getCause());
41          assertEquals(pattern, ex.getPattern());
42          assertEquals(arguments.length, ex.getArguments().length);
43          for (int i = 0; i < arguments.length; ++i) {
44              assertEquals(arguments[i], ex.getArguments()[i]);
45          }
46          assertFalse(pattern.equals(ex.getMessage()));
47          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
48      }
49      
50      public void testConstructorCause(){
51          String inMsg = "inner message";
52          Exception cause = new Exception(inMsg);
53          MathConfigurationException ex = new MathConfigurationException(cause);
54          assertEquals(cause, ex.getCause());
55      }
56  
57      public void testConstructorPatternArgumentsCause(){
58          String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
59          Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
60          String inMsg = "inner message";
61          Exception cause = new Exception(inMsg);
62          MathConfigurationException ex = new MathConfigurationException(cause, pattern, arguments);
63          assertEquals(cause, ex.getCause());
64          assertEquals(pattern, ex.getPattern());
65          assertEquals(arguments.length, ex.getArguments().length);
66          for (int i = 0; i < arguments.length; ++i) {
67              assertEquals(arguments[i], ex.getArguments()[i]);
68          }
69          assertFalse(pattern.equals(ex.getMessage()));
70          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
71      }
72      
73  }