/** * Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class * * @param <C> the class type * @param argument Value * @param expectedClass Class * @param name The name of the argument * @return value cast to the specified Class * @throws IllegalArgumentException If value is not an instance of theClass. */ // due to cast in return public static <C> C getInstanceOf( Object argument, Class<C> expectedClass, String name ) { isInstanceOf(argument, expectedClass, name); return expectedClass.cast(argument); }
/** * Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class * * @param <C> the class type * @param argument Value * @param expectedClass Class * @param name The name of the argument * @return value cast to the specified Class * @throws IllegalArgumentException If value is not an instance of theClass. */ // due to cast in return public static <C> C getInstanceOf( Object argument, Class<C> expectedClass, String name ) { isInstanceOf(argument, expectedClass, name); return expectedClass.cast(argument); }
/** * Checks that the object is an instance of the specified Class and then returns the object cast to the specified Class * * @param <C> the class type * @param argument Value * @param expectedClass Class * @param name The name of the argument * @return value cast to the specified Class * @throws IllegalArgumentException If value is not an instance of theClass. */ // due to cast in return public static <C> C getInstanceOf( Object argument, Class<C> expectedClass, String name ) { isInstanceOf(argument, expectedClass, name); return expectedClass.cast(argument); }
@Test public void isInstanceOfShouldNotThrowExceptionIfReferenceIsInstanceOfTheSuppliedClass() { CheckArg.isInstanceOf(this, this.getClass(), "test"); }
@Test( expected = IllegalArgumentException.class ) public void isInstanceOfShouldNotThrowExceptionIfReferenceIsNotInstanceOfTheSuppliedClass() { CheckArg.isInstanceOf(" ", this.getClass(), "test"); }
@Test( expected = IllegalArgumentException.class ) public void isInstanceOfShouldNotThrowExceptionIfReferenceIsNull() { CheckArg.isInstanceOf(null, this.getClass(), "test"); }
CheckArg.hasSizeOfAtLeast(arguments, 1, "arguments"); CheckArg.hasSizeOfAtMost(arguments, 2, "arguments"); CheckArg.isInstanceOf(arguments[0], String.class, "arguments[0]"); CheckArg.isInstanceOf(arguments[1], String.class, "arguments[1]"); primaryNodeTypeName = (String)arguments[1];
CheckArg.hasSizeOfAtLeast(arguments, 1, "arguments"); CheckArg.hasSizeOfAtMost(arguments, 2, "arguments"); CheckArg.isInstanceOf(arguments[0], String.class, "arguments[0]"); CheckArg.isInstanceOf(arguments[1], String.class, "arguments[1]"); primaryNodeTypeName = (String)arguments[1];