#!/bin/java bsh.Interpreter

source("TestHarness.bsh");

// test static method selection
assert( MethodSelection.get_static( (int)5 ) == Integer.TYPE );
assert( MethodSelection.get_static( (short)5 ) == Short.TYPE );
assert( MethodSelection.get_static( (long)5 ) == Long.TYPE );
assert( MethodSelection.get_static( (byte)5 ) == Byte.TYPE );
assert( MethodSelection.get_static( "foo" ) == String.class );
assert( MethodSelection.get_static( new Object() ) == Object.class );
assert( MethodSelection.get_static() == Void.TYPE);

// test dynamic method selection
m=new MethodSelection();
assert( m.get_dynamic( (int)5 ) == Integer.TYPE );
assert( m.get_dynamic( (short)5 ) == Short.TYPE );
assert( m.get_dynamic( (long)5 ) == Long.TYPE );
assert( m.get_dynamic( (byte)5 ) == Byte.TYPE );
assert( m.get_dynamic( "foo" ) == String.class );
assert( m.get_dynamic( new Object() ) == Object.class );
assert( m.get_dynamic() == Void.TYPE );

// bsh should recognize a less specific java compatible match over an
// extended (autoboxed, BeanShell specific, etc.) match 
// Should be Integer.class not primitive Integer.TYPE (both available) 
assert( m.get_dynamic( new Integer(4) ) == Integer.class );

// test constructor selection
m=new MethodSelection( (int)5 );
assert( m.constructedWith == Integer.TYPE );
m=new MethodSelection( (short)5 );
assert( m.constructedWith == Short.TYPE );
m=new MethodSelection( (long)5 );
assert( m.constructedWith == Long.TYPE );
m=new MethodSelection( (byte)5 );
assert( m.constructedWith == Byte.TYPE );
m=new MethodSelection( "foo" );
assert( m.constructedWith == String.class );
m=new MethodSelection( new Object() );
assert( m.constructedWith == Object.class );

// Test method selection with null parameter
// Issue #132
Object x = null;
String str = String.valueOf(x);
assert("null".equals(str));
 
complete();

