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 MathConfigurationExceptionTest extends TestCase {
028    
029        public void testConstructor(){
030            MathConfigurationException ex = new MathConfigurationException();
031            assertNull(ex.getCause());
032            assertNull(ex.getMessage());
033            assertEquals(0, ex.getMessage(Locale.FRENCH).length());
034        }
035        
036        public void testConstructorPatternArguments(){
037            String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
038            Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
039            MathConfigurationException ex = new MathConfigurationException(pattern, arguments);
040            assertNull(ex.getCause());
041            assertEquals(pattern, ex.getPattern());
042            assertEquals(arguments.length, ex.getArguments().length);
043            for (int i = 0; i < arguments.length; ++i) {
044                assertEquals(arguments[i], ex.getArguments()[i]);
045            }
046            assertFalse(pattern.equals(ex.getMessage()));
047            assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
048        }
049        
050        public void testConstructorCause(){
051            String inMsg = "inner message";
052            Exception cause = new Exception(inMsg);
053            MathConfigurationException ex = new MathConfigurationException(cause);
054            assertEquals(cause, ex.getCause());
055        }
056    
057        public void testConstructorPatternArgumentsCause(){
058            String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
059            Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
060            String inMsg = "inner message";
061            Exception cause = new Exception(inMsg);
062            MathConfigurationException ex = new MathConfigurationException(cause, pattern, arguments);
063            assertEquals(cause, ex.getCause());
064            assertEquals(pattern, ex.getPattern());
065            assertEquals(arguments.length, ex.getArguments().length);
066            for (int i = 0; i < arguments.length; ++i) {
067                assertEquals(arguments[i], ex.getArguments()[i]);
068            }
069            assertFalse(pattern.equals(ex.getMessage()));
070            assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
071        }
072        
073    }