### Question:
JavaScriptUtils { public static Number jsToNumber( Object value, String classType ) { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { return (Double) Context.jsToJava( value, Double.class ); } catch ( Exception e ) { String string = Context.toString( value ); return Double.parseDouble( Const.trim( string ) ); } } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return nb.doubleValue(); } else { Number nb = (Number) value; return nb.doubleValue(); } }  static Object convertFromJs( Object value, int type, String fieldName ); static Number jsToNumber( Object value, String classType ); static Long jsToInteger( Object value, Class<?> clazz ); static String jsToString( Object value, String classType ); static Date jsToDate( Object value, String classType ); static BigDecimal jsToBigNumber( Object value, String classType );  }### Answer:
@Test public void jsToNumber_Undefined() throws Exception { assertNull( JavaScriptUtils.jsToNumber( null, UNDEFINED ) ); }
@Test public void jsToNumber_NativeJavaObject_Double() throws Exception { Scriptable value = getDoubleValue(); Number number = JavaScriptUtils.jsToNumber( value, JAVA_OBJECT ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }
@Test public void jsToNumber_NativeJavaObject_Int() throws Exception { Scriptable value = getIntValue(); Number number = JavaScriptUtils.jsToNumber( value, JAVA_OBJECT ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }
@Test public void jsToNumber_NativeNumber() throws Exception { Scriptable value = Context.toObject( 1.0, scope ); Number number = JavaScriptUtils.jsToNumber( value, NATIVE_NUMBER ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }
@Test public void jsToNumber_JavaNumber() throws Exception { Number number = JavaScriptUtils.jsToNumber( 1.0, Double.class.getName() ); assertEquals( 1.0, number.doubleValue(), 1e-6 ); }