Created
January 12, 2010 18:19
-
-
Save nicksieger/275434 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require 'java' | |
| puts "Starting array_enum" | |
| class ArrayEnumeration | |
| include java.util.Enumeration | |
| def initialize(arr) | |
| @arr = arr | |
| @pos = 0 | |
| end | |
| def hasMoreElements | |
| @pos < @arr.length | |
| end | |
| def nextElement | |
| raise java.util.NoSuchElementException.new("no more elements") unless hasMoreElements | |
| pos = @pos | |
| @pos += 1 | |
| @arr[pos] | |
| end | |
| end | |
| class ProducesEnumeration | |
| def makeEnum | |
| ArrayEnumeration.new([]) | |
| end | |
| end | |
| java_src = <<SRC | |
| import java.util.Enumeration; | |
| public class UsesEnumeration { | |
| public static interface ProducesEnumeration { | |
| Enumeration makeEnum(); | |
| } | |
| public static Enumeration makeEnum(ProducesEnumeration pe) { | |
| return pe.makeEnum(); | |
| } | |
| } | |
| SRC | |
| File.open("UsesEnumeration.java", "wb") {|f| f << java_src} | |
| system("javac -d . UsesEnumeration.java") | |
| import "UsesEnumeration" | |
| require 'test/unit' | |
| class ArrayEnumerationTest < Test::Unit::TestCase | |
| def test_has_underscored_methods | |
| array_enum = UsesEnumeration.makeEnum(ProducesEnumeration.new) | |
| p array_enum | |
| p array_enum.methods.grep(/has|next/) | |
| assert_nothing_raised { | |
| assert !array_enum.has_more_elements | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment