Skip to content
Browse files

java coercion

  • Loading branch information...
1 parent e5843f6 commit e26666280ccf8c1f45fbbdd70d1d4e82ae18735d Marc Peabody committed Oct 2, 2010
Showing with 30 additions and 0 deletions.
  1. +15 −0 koans/about_java_interop.rb
  2. +15 −0 src/about_java_interop.rb
View
15 koans/about_java_interop.rb
@@ -95,6 +95,21 @@ def test_however_most_methods_returning_strings_return_ruby_strings
assert_equal __, java_array.toString.is_a?(java.lang.String)
end
+ def test_some_ruby_objects_can_be_coerced_to_java
+ assert_equal __, "ruby string".to_java.class
+ assert_equal __, 1.to_java.class
+ assert_equal __, 9.32.to_java.class
+ assert_equal __, false.to_java.class
+ end
+
+ def test_some_ruby_objects_can_NOT_be_coerced_to_java
+ [[], {}, Object.new].each do |ruby_object|
+ assert_raise(___) do
+ ruby_object.to_java_class
+ end
+ end
+ end
+
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"
View
15 src/about_java_interop.rb
@@ -95,6 +95,21 @@ def test_however_most_methods_returning_strings_return_ruby_strings
assert_equal __(false), java_array.toString.is_a?(java.lang.String)
end
+ def test_some_ruby_objects_can_be_coerced_to_java
+ assert_equal __(Java::JavaLang::String), "ruby string".to_java.class
+ assert_equal __(Java::JavaLang::Long), 1.to_java.class
+ assert_equal __(Java::JavaLang::Double), 9.32.to_java.class
+ assert_equal __(Java::JavaLang::Boolean), false.to_java.class
+ end
+
+ def test_some_ruby_objects_can_NOT_be_coerced_to_java
+ [[], {}, Object.new].each do |ruby_object|
+ assert_raise(___(NoMethodError)) do
+ ruby_object.to_java_class
+ end
+ end
+ end
+
def test_java_collections_are_enumerable
java_array = java.util.ArrayList.new
java_array << "one" << "two" << "three"

0 comments on commit e266662

Please sign in to comment.
Something went wrong with that request. Please try again.