### Question:
JavaScriptUtils { public static Date jsToDate( Object value, String classType ) throws HopValueException { double dbl; if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else { if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) { dbl = Context.toNumber( value ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) || classType.equalsIgnoreCase( "java.util.Date" ) ) { try { Date dat = (Date) Context.jsToJava( value, java.util.Date.class ); dbl = dat.getTime(); } catch ( Exception e ) { try { String string = Context.toString( value ); return XmlHandler.stringToDate( string ); } catch ( Exception e3 ) { throw new HopValueException( "Can't convert a string to a date" ); } } } else if ( classType.equalsIgnoreCase( "java.lang.Double" ) ) { dbl = (Double) value; } else { String string = (String) Context.jsToJava( value, String.class ); dbl = Double.parseDouble( string ); } long lng = Math.round( dbl ); return new Date( lng ); } }  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 jsToDate_Undefined() throws Exception { assertNull( JavaScriptUtils.jsToDate( null, UNDEFINED ) ); }
@Test public void jsToDate_NativeDate() throws Exception { Date date = new Date( 1 ); Scriptable value = ctx.newObject( scope, "Date", new Object[] { date.getTime() } ); assertEquals( date, JavaScriptUtils.jsToDate( value, "org.mozilla.javascript.NativeDate" ) ); }
@Test public void jsToDate_NativeJavaObject() throws Exception { Scriptable value = Context.toObject( new Date( 1 ), scope ); assertEquals( new Date( 1 ), JavaScriptUtils.jsToDate( value, JAVA_OBJECT ) ); }
@Test public void jsToDate_Double() throws Exception { assertEquals( new Date( 1 ), JavaScriptUtils.jsToDate( 1.0, Double.class.getName() ) ); }
@Test public void jsToDate_String() throws Exception { assertEquals( new Date( 1 ), JavaScriptUtils.jsToDate( "1.0", String.class.getName() ) ); }
@Test( expected = NumberFormatException.class ) public void jsToDate_String_Unparseable() throws Exception { JavaScriptUtils.jsToDate( "qwerty", String.class.getName() ); }