JRUBY-1613: Tweak Java method aliasing in JavaClass to apply ? suffix to any method...
[jruby.git] / spec / java_integration / methods / naming_spec.rb
blobeb008e2a19f2d1cf00e7f04873f4f3fbef4247db
1 require File.dirname(__FILE__) + "/../spec_helper"
3 import "java_integration.fixtures.MethodNames"
5 describe "Java static method names" do
6   it "should present as both camel-case and ruby-case" do
7     methods = MethodNames.methods
8     
9     methods.should include("lowercase1")
10     methods.should include("camelCase1")
11     methods.should include("camel_case1")
12     methods.should include("camelWithUPPER1")
13     methods.should include("camel_with_upper1")
14     methods.should include("camelWITHUpper1")
15     methods.should include("CAMELWithUpper1")
16     
17     pending("broken") do
18       methods.should_not include("camel_withupper1")
19       methods.should_not include("camelwith_upper1")
20     end
21   end
22   
23   it "should present javabean properties as attribute readers and writers" do
24     methods = MethodNames.methods
25     
26     methods.should include("getValue1")
27     methods.should include("get_value1")
28     methods.should include("value1")
29     
30     methods.should include("setValue1")
31     methods.should include("set_value1")
32     methods.should include("value1=")
33     
34     methods.should include("getValues1")
35     methods.should include("get_values1")
36     methods.should_not include("values1")
37     
38     methods.should include("setValues1")
39     methods.should include("set_values1")
40     methods.should_not include("values1=")
41   end
43   it "should present boolean javabean property accessors as '?' method" do
44     methods = MethodNames.methods
45     
46     methods.should include("isFirst1")
47     methods.should include("first1")
48     methods.should include("first1?")
50     methods.should include("isSecond1")
51     methods.should include("second1")
52     methods.should include("second1?")
53     
54     methods.should include("hasThird1")
55     methods.should include("has_third1")
56     methods.should include("has_third1?")
58     methods.should include("hasFourth1")
59     methods.should include("has_fourth1");
60     methods.should include("has_fourth1?");
62     pending("not implemented") do
63       methods.should include("third1?")
64     end
65     methods.should_not include("fourth1?")
66   end
67   
68   it "should not overwrite critical core Ruby methods" do
69     pending("need a better way to separate class and instance methods in the java code")
70   end
71 end
73 describe "Java instance method names" do
74   it "should present as both camel-case and ruby-case" do
75     methods = MethodNames.instance_methods
76     
77     methods.should include("lowercase2")
78     methods.should include("camelCase2")
79     methods.should include("camel_case2")
80     methods.should include("camelWithUPPER2")
81     methods.should include("camel_with_upper2")
82     methods.should include("camelWITHUpper2")
83     methods.should include("CAMELWithUpper2")
84     
85     pending("broken") do
86       methods.should_not include("camel_withupper2")
87       methods.should_not include("camelwith_upper2")
88     end
89   end
90   
91   it "should present javabean properties as attribute readers and writers" do
92     methods = MethodNames.instance_methods
93     
94     methods.should include("getValue2")
95     methods.should include("get_value2")
96     methods.should include("value2")
97     
98     methods.should include("setValue2")
99     methods.should include("set_value2")
100     methods.should include("value2=")
101     
102     methods.should include("getValues2")
103     methods.should include("get_values2")
104     methods.should_not include("values2")
105     
106     methods.should include("setValues2")
107     methods.should include("set_values2")
108     methods.should_not include("values2=")
109   end
110   
111   it "should treat consecutive caps as part of one property name" do
112     methods = MethodNames.instance_methods
114     methods.should include("jconsecutive_caps")
115     methods.should include("jconsecutive_caps=")
116   end
117   
118   it "should present boolean javabean property accessors as '?' method" do
119     methods = MethodNames.instance_methods
120     
121     methods.should include("isFirst2")
122     methods.should include("first2")
123     methods.should include("first2?")
125     methods.should include("isSecond2")
126     methods.should include("second2")
127     methods.should include("second2?")
128     
129     methods.should include("hasThird2")
130     methods.should include("has_third2")
131     methods.should include("has_third2?")
133     methods.should include("hasFourth2")
134     methods.should include("has_fourth2")
135     methods.should include("has_fourth2?")
137     pending("not implemented") do
138       methods.should include("third2?")
139     end
140     methods.should_not include("fourth2?")
141   end
142   
143   it "should not overwrite critical core Ruby methods" do
144     obj = MethodNames.new
145     
146     obj.send(:initialize).should_not == "foo"
147     obj.object_id.should_not == "foo"
148     obj.__id__.should_not == "foo"
149     lambda {obj.__send__}.should raise_error(ArgumentError)
150   end