001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.math;
019    
020    import junit.framework.TestCase;
021    
022    import java.util.Locale;
023    
024    /**
025     * @version $Revision: 746578 $ $Date: 2009-02-21 15:01:14 -0500 (Sat, 21 Feb 2009) $
026     */
027    public class ConvergenceExceptionTest extends TestCase {
028    
029        public void testConstructor(){
030            ConvergenceException ex = new ConvergenceException();
031            assertNull(ex.getCause());
032            assertNotNull(ex.getMessage());
033            assertNotNull(ex.getMessage(Locale.FRENCH));
034            assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
035        }
036        
037        public void testConstructorPatternArguments(){
038            String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
039            Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
040            ConvergenceException ex = new ConvergenceException(pattern, arguments);
041            assertNull(ex.getCause());
042            assertEquals(pattern, ex.getPattern());
043            assertEquals(arguments.length, ex.getArguments().length);
044            for (int i = 0; i < arguments.length; ++i) {
045                assertEquals(arguments[i], ex.getArguments()[i]);
046            }
047            assertFalse(pattern.equals(ex.getMessage()));
048            assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
049        }
050        
051        public void testConstructorCause(){
052            String inMsg = "inner message";
053            Exception cause = new Exception(inMsg);
054            ConvergenceException ex = new ConvergenceException(cause);
055            assertEquals(cause, ex.getCause());
056        }
057    
058        public void testConstructorPatternArgumentsCause(){
059            String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
060            Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
061            String inMsg = "inner message";
062            Exception cause = new Exception(inMsg);
063            ConvergenceException ex = new ConvergenceException(cause, pattern, arguments);
064            assertEquals(cause, ex.getCause());
065            assertEquals(pattern, ex.getPattern());
066            assertEquals(arguments.length, ex.getArguments().length);
067            for (int i = 0; i < arguments.length; ++i) {
068                assertEquals(arguments[i], ex.getArguments()[i]);
069            }
070            assertFalse(pattern.equals(ex.getMessage()));
071            assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
072        }
073        
074    }