Skip to content

Commit

Permalink
Merge branch 'jetty-9.4.x' into jetty-10.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
olamy committed May 24, 2019
2 parents 49356bb + a3b7558 commit a5859fb
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 0 deletions.
103 changes: 103 additions & 0 deletions jetty-util/src/test/java/org/eclipse/jetty/util/ArrayUtilTest.java
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));
}

}
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 jetty-util/src/test/java/org/eclipse/jetty/util/LoaderTest.java
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"));
}

}

0 comments on commit a5859fb

Please sign in to comment.