Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1d90f9fe8817
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a9f22e3be1e
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 15, 2015

  1. Copy the full SHA
    84a2051 View commit details
  2. Copy the full SHA
    27dc383 View commit details
  3. Copy the full SHA
    db7c111 View commit details
  4. Copy the full SHA
    6a9f22e View commit details
8 changes: 4 additions & 4 deletions spec/java_integration/ant/ant_spec.rb
Original file line number Diff line number Diff line change
@@ -28,19 +28,19 @@
end

it "adds tools.jar to the CLASSPATH when JAVA_HOME is set and it exists" do
stubs_file!
stub_File!
Ant.load
$CLASSPATH.should include("file:#{@tools_jar}")
end

it "adds classes.zip to the CLASSPATH when JAVA_HOME is set and it exists" do
stubs_file!
stub_File!
Ant.load
$CLASSPATH.should include("file:#{@classes_zip}")
end

def stubs_file!
File.stub!(:exist?).and_return false
def stub_File!
File.stub(:exist?).and_return false
File.should_receive(:exist?).with(ENV['JAVA_HOME']).and_return true
File.should_receive(:exist?).with(@tools_jar).and_return true
File.should_receive(:exist?).with(@classes_zip).and_return true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package java_integration.fixtures.iface;

public interface SingleMethodInterfaceWith4Args {
public static class Caller {
public static Object[] call(SingleMethodInterfaceWith4Args iface) {
return iface.doIt(Caller.class, "hello", "world", 42);
}
}

<T> Object[] doIt(final T arg1, String arg2, Object arg3, int arg4) ;
}
20 changes: 10 additions & 10 deletions spec/java_integration/interfaces/executor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
require File.dirname(__FILE__) + "/../spec_helper"

EXECUTOR_TEST_VALUE = 101

describe "java.util.concurrent.Executors" do

EXECUTOR_TEST_VALUE = 101

before do
@executor = java.util.concurrent.Executors.newSingleThreadExecutor
end


after { @executor.shutdown }

it "accepts a class that implements Callable interface" do
cls = Class.new do
include java.util.concurrent.Callable
@@ -15,12 +18,9 @@ def call
EXECUTOR_TEST_VALUE
end
end
lambda { @future = @executor.submit(cls.new) }.should_not raise_error(TypeError)
@future.get.should == EXECUTOR_TEST_VALUE
end

after do
@executor.shutdown
future = nil
lambda { future = @executor.submit(cls.new) }.should_not raise_error
future.get.should == EXECUTOR_TEST_VALUE
end

end
30 changes: 19 additions & 11 deletions spec/java_integration/interfaces/implementation_spec.rb
Original file line number Diff line number Diff line change
@@ -200,17 +200,25 @@ def callIt

caller.call { |arg| arg.should == 42 }
caller.call('x') { |arg| arg.should == 'x' }

Java::java_integration.fixtures.iface.SingleMethodInterfaceWith4Args::Caller.call do
|arg1, arg2, arg3, arg4|
arg2.should == 'hello'
arg3.should == 'world'
arg4.should == 42
[ arg2, arg3, arg4 ] # return Object[]
end
end

it "should maintain Ruby object equality when passed through Java and back" do
result = SingleMethodInterface.impl { |name| name }
callable = mock "callable"
callable = double "callable"
callable.should_receive(:call).and_return result
UsesSingleMethodInterface.new.callIt3(callable).should == result
end

it "coerces to that interface after duck-typed implementation has happened" do
callable = mock "SingleMethodInterfaceImpl"
callable = double "SingleMethodInterfaceImpl"
callable.should_receive(:callIt).and_return :callIt
UsesSingleMethodInterface.callIt(callable).should == :callIt

@@ -551,15 +559,15 @@ def value; 1; end

describe "Coercion of normal ruby objects" do
it "should allow an object passed to a java method to be coerced to the interface" do
ri = mock "returns interface"
ri = double "returns interface"
consumer = ReturnsInterfaceConsumer.new
consumer.set_returns_interface ri
ri.should be_kind_of(ReturnsInterface)
end


it "should return the original ruby object when returned back to Ruby" do
obj = mock "ruby object"
obj = double "ruby object"
cti = CoerceToInterface.new
result = cti.returnArgumentBackToRuby(JRuby.runtime, obj)
obj.should be_kind_of(Java::JavaLang::Runnable)
@@ -568,32 +576,32 @@ def value; 1; end
end

it "should return the original ruby object when converted back to Ruby" do
obj = mock "ruby object"
obj = double "ruby object"
cti = CoerceToInterface.new
result = cti.coerceArgumentBackToRuby(JRuby.runtime, obj)
obj.should be_kind_of(Java::JavaLang::Runnable)
result.should == obj
end

it "should pass the original ruby object when converted back to Ruby and used as an argument to another Ruby object" do
obj = mock "ruby object"
callable = mock "callable"
obj = double "ruby object"
callable = double "callable"
callable.should_receive(:call).with(obj)
cti = CoerceToInterface.new
cti.passArgumentToInvokableRubyObject(callable, obj)
obj.should be_kind_of(Java::JavaLang::Runnable)
end

it "should allow an object passed to a java constructor to be coerced to the interface" do
ri = mock "returns interface"
ri = double "returns interface"
ReturnsInterfaceConsumer.new(ri)
ri.should be_kind_of(ReturnsInterface)
end

it "should allow an object to be coerced as a return type of a java method" do
ri = mock "returns interface"
value = mock "return value runnable"
ri.stub!(:getRunnable).and_return value
ri = double "returns interface"
value = double "return value runnable"
ri.stub(:getRunnable).and_return value

consumer = ReturnsInterfaceConsumer.new(ri)
runnable = consumer.getRunnable