-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jetty-9.4.x' into jetty-10.0.x
- Loading branch information
Showing
3 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
jetty-util/src/test/java/org/eclipse/jetty/util/ArrayUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
/** | ||
* Unit tests for class {@link ArrayUtil}. | ||
* | ||
* @see ArrayUtil | ||
*/ | ||
public class ArrayUtilTest | ||
{ | ||
|
||
@Test | ||
public void testAddToArrayWithEmptyArray() | ||
{ | ||
String[] stringArray = new String[0]; | ||
String[] resultArray = ArrayUtil.addToArray(stringArray, "Ca?", Object.class); | ||
|
||
assertEquals(0, stringArray.length); | ||
assertEquals(1, resultArray.length); | ||
|
||
assertNotSame(stringArray, resultArray); | ||
assertNotSame(resultArray, stringArray); | ||
|
||
assertFalse(resultArray.equals(stringArray)); | ||
assertEquals(String.class, resultArray[0].getClass()); | ||
} | ||
|
||
@Test | ||
public void testAddUsingNull() | ||
{ | ||
String[] stringArray = new String[7]; | ||
String[] stringArrayTwo = ArrayUtil.add(stringArray, null); | ||
|
||
assertEquals(7, stringArray.length); | ||
assertEquals(7, stringArrayTwo.length); | ||
|
||
assertSame(stringArray, stringArrayTwo); | ||
assertSame(stringArrayTwo, stringArray); | ||
} | ||
|
||
@Test | ||
public void testAddWithNonEmptyArray() | ||
{ | ||
Object[] objectArray = new Object[3]; | ||
Object[] objectArrayTwo = ArrayUtil.add(objectArray, objectArray); | ||
|
||
assertEquals(3, objectArray.length); | ||
assertEquals(6, objectArrayTwo.length); | ||
|
||
assertNotSame(objectArray, objectArrayTwo); | ||
assertNotSame(objectArrayTwo, objectArray); | ||
|
||
assertFalse(objectArrayTwo.equals(objectArray)); | ||
} | ||
|
||
@Test | ||
public void testRemoveFromNullArrayReturningNull() | ||
{ | ||
assertNull(ArrayUtil.removeFromArray((Integer[])null, new Object())); | ||
} | ||
|
||
@Test | ||
public void testRemoveNulls() | ||
{ | ||
Object[] objectArray = new Object[2]; | ||
objectArray[0] = new Object(); | ||
Object[] resultArray = ArrayUtil.removeNulls(objectArray); | ||
|
||
assertEquals(2, objectArray.length); | ||
assertEquals(1, resultArray.length); | ||
|
||
assertNotSame(objectArray, resultArray); | ||
assertNotSame(resultArray, objectArray); | ||
|
||
assertFalse(resultArray.equals(objectArray)); | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
jetty-util/src/test/java/org/eclipse/jetty/util/IntrospectionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Unit tests for class {@link IntrospectionUtil}. | ||
* | ||
* @see IntrospectionUtil | ||
*/ | ||
public class IntrospectionUtilTest | ||
{ | ||
|
||
@Test | ||
public void testIsTypeCompatibleWithTwoTimesString() | ||
{ | ||
assertTrue(IntrospectionUtil.isTypeCompatible(String.class, String.class, true)); | ||
} | ||
|
||
@Test | ||
public void testIsSameSignatureWithNull() | ||
{ | ||
assertFalse(IntrospectionUtil.isSameSignature(null, null)); | ||
} | ||
|
||
@Test | ||
public void testFindMethodWithEmptyString() | ||
{ | ||
assertThrows(NoSuchMethodException.class, | ||
() -> IntrospectionUtil.findMethod(Integer.class, "", null, false, false)); | ||
} | ||
|
||
@Test | ||
public void testFindMethodWithNullMethodParameter() | ||
{ | ||
assertThrows(NoSuchMethodException.class, | ||
() -> IntrospectionUtil.findMethod(String.class, null, (Class<Integer>[])Array.newInstance(Class.class, 3), true, true)); | ||
} | ||
|
||
@Test | ||
public void testFindMethodWithNullClassParameter() throws NoSuchMethodException | ||
{ | ||
assertThrows(NoSuchMethodException.class, | ||
() -> IntrospectionUtil.findMethod(null, "subSequence", (Class<Object>[])Array.newInstance(Class.class, 9), false, false)); | ||
} | ||
|
||
@Test | ||
public void testIsJavaBeanCompliantSetterWithNull() | ||
{ | ||
assertFalse(IntrospectionUtil.isJavaBeanCompliantSetter(null)); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
jetty-util/src/test/java/org/eclipse/jetty/util/LoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Locale; | ||
import java.util.MissingResourceException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Unit tests for class {@link Loader}. | ||
* | ||
* @see Loader | ||
*/ | ||
public class LoaderTest | ||
{ | ||
|
||
@Test | ||
public void testGetResourceBundleThrowsMissingResourceException() | ||
{ | ||
assertThrows(MissingResourceException.class, () -> Loader.getResourceBundle("nothing", true, Locale.ITALIAN)); | ||
} | ||
|
||
@Test | ||
public void testLoadClassThrowsClassNotFoundException() | ||
{ | ||
assertThrows(ClassNotFoundException.class, () -> Loader.loadClass(Object.class, "String")); | ||
} | ||
|
||
@Test | ||
public void testLoadClassSucceeds() throws ClassNotFoundException | ||
{ | ||
assertEquals(LazyList.class, Loader.loadClass(Object.class, "org.eclipse.jetty.util.LazyList")); | ||
} | ||
|
||
} |