blob: 641d0a85ba7cc7d2ac8b57190bcf47c7d8d94544 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
******************************************************************************/
package org.eclipse.scout.commons;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import org.junit.Test;
/**
* JUnit tests for {@link ClassIdentifier}
*/
public class ClassIdentifierTest {
@Test(expected = IllegalArgumentException.class)
public void testEmptyConstructor() {
new ClassIdentifier();
}
@Test(expected = IllegalArgumentException.class)
public void testNullConstructor() {
new ClassIdentifier((Class<?>[]) null);
}
@Test
public void testAbstractClass() {
ClassIdentifier cid = new ClassIdentifier(Template.class);
assertArrayEquals(new Class[]{Template.class}, cid.getClasses());
}
@Test
public void testTemplateClassUsingFullPath() {
ClassIdentifier aid = new ClassIdentifier(Foo.A.class, Foo.A.InnerClass.class);
ClassIdentifier bid = new ClassIdentifier(Foo.B.class, Foo.B.InnerClass.class);
assertFalse(aid.equals(bid));
assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
assertSame(aid.getLastSegment(), bid.getLastSegment());
}
@Test
public void testTemplateClassUsingShortestPath() {
ClassIdentifier aid = new ClassIdentifier(Foo.A.class, Template.InnerClass.class);
ClassIdentifier bid = new ClassIdentifier(Foo.B.class, Template.InnerClass.class);
assertFalse(aid.equals(bid));
assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
assertSame(aid.getLastSegment(), bid.getLastSegment());
}
@Test
public void testConvertClassArray_nullArgument() {
ClassIdentifier[] cids = ClassIdentifier.convertClassArrayToClassIdentifierArray((Class<?>[]) null);
assertNotNull(cids);
assertArrayEquals(new ClassIdentifier[0], cids);
}
@Test
public void testConvertClassArray_emptyArgument() {
ClassIdentifier[] cids = ClassIdentifier.convertClassArrayToClassIdentifierArray();
assertNotNull(cids);
assertArrayEquals(new ClassIdentifier[0], cids);
}
@Test
public void testConvertClassArray_nullClasses() {
ClassIdentifier[] cids = ClassIdentifier.convertClassArrayToClassIdentifierArray(String.class, null, Integer.class);
assertNotNull(cids);
assertEquals(2, cids.length);
assertArrayEquals(new ClassIdentifier[]{new ClassIdentifier(String.class), new ClassIdentifier(Integer.class)}, cids);
}
public abstract static class Template {
public class InnerClass {
}
}
public static class Foo {
public class A extends Template {
}
public class B extends Template {
}
}
}