Skip to content

Commit

Permalink
BL-968 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Jan 22, 2025
1 parent a12734b commit 897c04e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,11 @@ private static Optional<?> coerceAttempt( IBoxContext context, Class<?> expected
String expectedClass = expected.getSimpleName().toLowerCase();
String actualClass = actual.getSimpleName().toLowerCase();

// Check if we have a boxed type and we just need an unboxed type. We can't unbox it here since we need to return an Object, but the unboxing will happen automatically when it's used
if ( PRIMITIVE_MAP.containsKey( actual ) && PRIMITIVE_MAP.get( actual ).equals( expected ) ) {
return Optional.of( value );
}

// Primitive to Wrapper Type
expected = WRAPPERS_MAP.getOrDefault( expected, expected );
actual = WRAPPERS_MAP.getOrDefault( actual, actual );
Expand Down Expand Up @@ -2239,12 +2244,14 @@ private static Optional<?> coerceAttempt( IBoxContext context, Class<?> expected
}

// EXPECTED: BOOLEAN
// If it's a boolean and the actual is in the booleanTargets list, we can coerce it
// If we expect a boolean, we can coerce it from a boolean, number or string
if ( Boolean.class.isAssignableFrom( expected )
&&
booleanTargets.contains( actualClass )
&&
Number.class.isAssignableFrom( actual ) ) {
( Boolean.class.isAssignableFrom( actual )
||
booleanTargets.contains( actualClass )
||
Number.class.isAssignableFrom( actual ) ) ) {

// logger.debug( "Coerce attempt: Castable to boolean " + actualClass );
CastAttempt<Boolean> booleanAttempt = BooleanCaster.attempt( value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwa

// Use use the default invocations
if ( method != null ) {
return coerceReturnValue( invoke( Key.of( method.getName() ), args ), method.getReturnType(), method.getName() );
return coerceReturnValue( invoke( args ), method.getReturnType(), method.getName() );
} else {
return invoke( args );
}
Expand All @@ -75,7 +75,7 @@ public Object invoke( Object proxy, Method method, Object[] args ) throws Throwa
* @return The coerced return value
*/
private Object coerceReturnValue( Object returnValue, Class<?> returnType, String methodName ) {
if ( returnType == null ) {
if ( returnValue == null ) {
return returnValue;
}
Object[] args = new Object[] { returnValue };
Expand Down

0 comments on commit 897c04e

Please sign in to comment.