MATH-361.

Added a check to avoid triggering a "NullPointerException" if the argument
list is "null".
Added unit tests.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@958551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2010-06-28 12:01:35 +00:00
parent 4102ba5dfb
commit f6fd043072
5 changed files with 142 additions and 5 deletions

View File

@ -72,11 +72,13 @@ public class MathIllegalArgumentException extends IllegalArgumentException {
*/
private List<Object> flatten(Object[] array) {
final List<Object> list = new ArrayList<Object>();
for (Object o : array) {
if (o instanceof Object[]) {
list.addAll(flatten((Object[]) o));
} else {
list.add(o);
if (array != null) {
for (Object o : array) {
if (o instanceof Object[]) {
list.addAll(flatten((Object[]) o));
} else {
list.add(o);
}
}
}
return list;

View File

@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.exception;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for {@link DimensionMismatchException}.
*
* @version $Revision$ $Date$
*/
public class DimensionMismatchExceptionTest {
@Test
public void testAccessors() {
final DimensionMismatchException e = new DimensionMismatchException(1, 2);
Assert.assertEquals(1, e.getArgument());
Assert.assertEquals(2, e.getDimension());
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.exception;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for {@link NotPositiveException}.
*
* @version $Revision$ $Date$
*/
public class NotPositiveExceptionTest {
@Test
public void testAccessors() {
final NotPositiveException e = new NotPositiveException(-1);
Assert.assertEquals(-1, e.getArgument());
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.exception;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for {@link NotStrictlyPositiveException}.
*
* @version $Revision$ $Date$
*/
public class NotStrictlyPositiveExceptionTest {
@Test
public void testAccessors() {
final NotStrictlyPositiveException e = new NotStrictlyPositiveException(0);
Assert.assertEquals(0, e.getArgument());
}
}

View File

@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.exception;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for {@link OutOfRangeException}.
*
* @version $Revision$ $Date$
*/
public class OutOfRangeExceptionTest {
@Test
public void testAccessors() {
final OutOfRangeException e = new OutOfRangeException(-1, 0, 2);
Assert.assertEquals(-1, e.getArgument());
Assert.assertEquals(0, e.getLo());
Assert.assertEquals(2, e.getHi());
}
}