Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/unit assert_raises on java exceptions doesn't work on 9k #3949

Closed
oblutak opened this issue Jun 1, 2016 · 1 comment
Closed

test/unit assert_raises on java exceptions doesn't work on 9k #3949

oblutak opened this issue Jun 1, 2016 · 1 comment

Comments

@oblutak
Copy link

oblutak commented Jun 1, 2016

require 'test/unit'

class FooBar <  Test::Unit::TestCase
  def test_raise_java_exception
    exception_caught = false
    begin
      raise java.util.NoSuchElementException.new("Bad param")
    rescue Java::JavaUtil::NoSuchElementException
      exception_caught = true
    end
    assert exception_caught
  end

  def test_assert_raises_on_java_exception
    assert_raises Java::JavaUtil::NoSuchElementException do
      raise java.util.NoSuchElementException.new("Bad param")
    end
  end

  def test_assert_raises_on_exception
    assert_raises RuntimeError do
      raise RuntimeError.new('error')
    end
  end
end

all tests passed for jruby 1.7

jruby 1.7.23 (1.9.3p551) 2015-11-24 f496dd5 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_91-b14 +jit [darwin-x86_64]

but 9k gives an error on test_assert_raises_on_java_exception

jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 +jit [darwin-x86_64]

Failure:
  Should expect a class of exception, Java::JavaUtil::NoSuchElementException.
  <nil> is not true.
test_assert_raises_on_java_exception(FooBar)
@oblutak oblutak changed the title test/unit assert_raises on java exception don't work on 9k test/unit assert_raises on java exceptions doesn't work on 9k Jun 1, 2016
@kares
Copy link
Member

kares commented Jun 2, 2016

on JRuby 1.7 you have the "built-in" test-unit (which used to be part of Ruby stdlib - also known as 1.x)
since Ruby 2.x you do have the test-unit gem bundled which is a successor of test-unit (started as 2.x) these days at version number 3.x ... safe to say that its a completely different piece of code. if you install test-unit gem on JRuby 1.7 (3.1 won't work but < 3.0 should) it might fail the same.

suggest you report this JRuby specific "regression" to test-unit itself - seems like (haven't looked) that its a simple arg validation - could be skipped or a condition (on JRuby) might be added checking whether arg.is_a?(java.lang.Throwable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants