Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs from Evan Light for reflected method invocation. JRUBY-2569.
git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@6813 961051c9-f516-0410-bf72-c9f7e237a7b7
- Loading branch information
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class PackageInstanceMethod { | ||
String thePackageScopeMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class PackageStaticMethod { | ||
static String thePackageScopeMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class PrivateInstanceMethod { | ||
private String thePrivateMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class PrivateStaticMethod { | ||
public static String thePrivateMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class ProtectedInstanceMethod { | ||
protected String theProtectedMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package java_integration.fixtures; | ||
|
||
public class ProtectedStaticMethod { | ||
protected static String theProtectedMethod() { | ||
return "42"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
import 'java_integration.fixtures.PrivateInstanceMethod' | ||
import 'java_integration.fixtures.PrivateStaticMethod' | ||
import 'java_integration.fixtures.ProtectedInstanceMethod' | ||
import 'java_integration.fixtures.ProtectedStaticMethod' | ||
import 'java_integration.fixtures.PackageInstanceMethod' | ||
import 'java_integration.fixtures.PackageStaticMethod' | ||
|
||
describe "A JavaMethod" do | ||
describe "given a private Java class method" do | ||
before(:each) do | ||
@method = PrivateStaticMethod.java_class.declared_method_smart :thePrivateMethod | ||
@method.accessible = true | ||
end | ||
|
||
it "should provide a shortcut to invoke the method" do | ||
lambda { @method.invoke_static }.should_not raise_error | ||
end | ||
|
||
it "should allow invocation with a Ruby nil method" do | ||
pending "invoke currently requires a JavaObject" do | ||
lambda { @method.invoke nil }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should allow invocation with a Java null method" do | ||
lambda { @method.invoke Java.ruby_to_java(nil) }.should_not raise_error | ||
end | ||
end | ||
|
||
describe "given a protected Java class method" do | ||
before(:each) do | ||
@method = ProtectedStaticMethod.java_class.declared_method_smart :theProtectedMethod | ||
@method.accessible = true | ||
end | ||
|
||
it "should provide a shortcut to invoke protected Java class methods" do | ||
lambda { @method.invoke_static }.should_not raise_error | ||
end | ||
|
||
it "should allow invocation with a Ruby nil method" do | ||
pending "invoke currently requires a JavaObject" do | ||
lambda { @method.invoke nil }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should allow invocation with a Java null method" do | ||
lambda { @method.invoke Java.ruby_to_java(nil) }.should_not raise_error | ||
end | ||
end | ||
|
||
describe "given a package scope Java class method" do | ||
before(:each) do | ||
@method = PackageStaticMethod.java_class.declared_method_smart :thePackageScopeMethod | ||
@method.accessible = true | ||
end | ||
|
||
it "should provide a shortcut to invoke package scope Java class methods" do | ||
lambda { @method.invoke_static }.should_not raise_error | ||
end | ||
|
||
it "should allow invocation with a Ruby nil method" do | ||
pending "invoke currently requires a JavaObject" do | ||
lambda { @method.invoke nil }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should allow invocation with a Java null method" do | ||
lambda { @method.invoke Java.ruby_to_java(nil) }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should provide the ability to invoke private Java instance methods on a Ruby object" do | ||
pending "invoke fails immediately if not provided a JavaObject" do | ||
o = PrivateInstanceMethod.new | ||
method = PrivateInstanceMethod.java_class.declared_method_smart :thePrivateMethod | ||
method.accessible = true | ||
lambda { method.invoke(o) }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should provide the ability to invoke protected Java instance methods on a Ruby object" do | ||
pending "invoke fails immediately if not provided a JavaObject" do | ||
o = ProtectedInstanceMethod.new | ||
method = ProtectedInstanceMethod.java_class.declared_method_smart :theProtectedMethod | ||
method.accessible = true | ||
lambda { method.invoke(o) }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should provide the ability to invoke package scope Java instance methods on a Ruby object" do | ||
pending "invoke fails immediately if not provided a JavaObject" do | ||
o = PackageInstanceMethod.new | ||
method = PackageInstanceMethod.java_class.declared_method_smart :thePackageScopeMethod | ||
method.accessible = true | ||
lambda { method.invoke(o) }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should provide the ability to invoke private Java instance methods on a JavaObject" do | ||
o = PrivateInstanceMethod.new | ||
method = PrivateInstanceMethod.java_class.declared_method_smart :thePrivateMethod | ||
method.accessible = true | ||
lambda { method.invoke(o.java_object) }.should_not raise_error | ||
end | ||
|
||
it "should provide the ability to invoke protected Java instance methods on a JavaObject" do | ||
o = ProtectedInstanceMethod.new | ||
method = ProtectedInstanceMethod.java_class.declared_method_smart :theProtectedMethod | ||
method.accessible = true | ||
lambda { method.invoke(o.java_object) }.should_not raise_error | ||
end | ||
|
||
it "should provide the ability to invoke package scope Java instance methods on a JavaObject" do | ||
o = PackageInstanceMethod.new | ||
method = PackageInstanceMethod.java_class.declared_method_smart :thePackageScopeMethod | ||
method.accessible = true | ||
lambda { method.invoke(o.java_object) }.should_not raise_error | ||
end | ||
end |