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 ConvergenceExceptionTest extends TestCase {
28  
29      public void testConstructor(){
30          ConvergenceException ex = new ConvergenceException();
31          assertNull(ex.getCause());
32          assertNotNull(ex.getMessage());
33          assertNotNull(ex.getMessage(Locale.FRENCH));
34          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
35      }
36      
37      public void testConstructorPatternArguments(){
38          String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
39          Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
40          ConvergenceException ex = new ConvergenceException(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 testConstructorCause(){
52          String inMsg = "inner message";
53          Exception cause = new Exception(inMsg);
54          ConvergenceException ex = new ConvergenceException(cause);
55          assertEquals(cause, ex.getCause());
56      }
57  
58      public void testConstructorPatternArgumentsCause(){
59          String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
60          Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
61          String inMsg = "inner message";
62          Exception cause = new Exception(inMsg);
63          ConvergenceException ex = new ConvergenceException(cause, pattern, arguments);
64          assertEquals(cause, ex.getCause());
65          assertEquals(pattern, ex.getPattern());
66          assertEquals(arguments.length, ex.getArguments().length);
67          for (int i = 0; i < arguments.length; ++i) {
68              assertEquals(arguments[i], ex.getArguments()[i]);
69          }
70          assertFalse(pattern.equals(ex.getMessage()));
71          assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
72      }
73      
74  }