### Question:
JavaScriptUtils { public static Long jsToInteger( Object value, Class<?> clazz ) { if ( Number.class.isAssignableFrom( clazz ) ) { return ( (Number) value ).longValue(); } else { String classType = clazz.getName(); if ( classType.equalsIgnoreCase( "java.lang.String" ) ) { return ( new Long( (String) value ) ); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) { return null; } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) { Number nb = Context.toNumber( value ); return nb.longValue(); } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) { try { Value v = (Value) Context.jsToJava( value, Value.class ); return v.getInteger(); } catch ( Exception e2 ) { String string = Context.toString( value ); return Long.parseLong( Const.trim( string ) ); } } else { return Long.parseLong( value.toString() ); } } }  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 jsToInteger_Undefined() throws Exception { assertNull( JavaScriptUtils.jsToInteger( null, Undefined.class ) ); }
@Test public void jsToInteger_NaturalNumbers() throws Exception { Number[] naturalNumbers = new Number[] { (byte) 1, (short) 1, 1, (long) 1 }; for ( Number number : naturalNumbers ) { assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( number, number.getClass() ) ); } }
@Test public void jsToInteger_String() throws Exception { assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( "1", String.class ) ); }
@Test( expected = NumberFormatException.class ) public void jsToInteger_String_Unparseable() throws Exception { JavaScriptUtils.jsToInteger( "q", String.class ); }
@Test public void jsToInteger_Double() throws Exception { assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( 1.0, Double.class ) ); }
@Test public void jsToInteger_NativeJavaObject_Int() throws Exception { Scriptable value = getIntValue(); assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( value, NativeJavaObject.class ) ); }
@Test public void jsToInteger_NativeJavaObject_Double() throws Exception { Scriptable value = getDoubleValue(); assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( value, NativeJavaObject.class ) ); }
@Test public void jsToInteger_Other_Int() throws Exception { assertEquals( Long.valueOf( 1 ), JavaScriptUtils.jsToInteger( 1, getClass() ) ); }
@Test( expected = NumberFormatException.class ) public void jsToInteger_Other_String() throws Exception { JavaScriptUtils.jsToInteger( "qwerty", getClass() ); }