File: method_spec.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (109 lines) | stat: -rw-r--r-- 4,250 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
      lambda { @method.invoke nil }.should_not raise_error
    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
      lambda { @method.invoke nil }.should_not raise_error
    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
      lambda { @method.invoke nil }.should_not raise_error
    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
    o = PrivateInstanceMethod.new
    method = PrivateInstanceMethod.java_class.declared_method_smart :thePrivateMethod
    method.accessible = true
    lambda { method.invoke(o) }.should_not raise_error
  end
  
  it "should provide the ability to invoke protected Java instance methods on a Ruby object" do
    o = ProtectedInstanceMethod.new
    method = ProtectedInstanceMethod.java_class.declared_method_smart :theProtectedMethod
    method.accessible = true
    lambda { method.invoke(o) }.should_not raise_error
  end
  
  it "should provide the ability to invoke package scope Java instance methods on a Ruby object" do
    o = PackageInstanceMethod.new
    method = PackageInstanceMethod.java_class.declared_method_smart :thePackageScopeMethod
    method.accessible = true
    lambda { method.invoke(o) }.should_not raise_error
  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