Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
- implement the test for #976 in Java and .NET (PASSED)
- port `canLeverageIndirectInterfacePolymorphsm` to python (PASSED)
  • Loading branch information
Elad Ben-Israel committed Nov 13, 2019
1 parent eb278fb commit 334eff8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,13 @@ public void VariadicCallbacksAreHandledCorrectly()
Assert.Equal(new double[]{2d, 3d, 4d}, invoker.AsArray(1, 2, 3));
}

[Fact(DisplayName = Prefix + nameof(ReturnSubclassThatImplementsInterface976))]
public void ReturnSubclassThatImplementsInterface976()
{
var obj = SomeTypeJsii976.ReturnReturn();
Assert.Equal(obj.Foo, 333);
}

private sealed class OverrideVariadicMethod : VariadicMethod
{
public override double[] AsArray(double first, params double[] others)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,12 @@ public void correctlyDeserializesStructUnions() {
assertTrue(StructUnionConsumer.isStructB(b1));
}

@Test
public void returnSubclassThatImplementsInterface976() {
IReturnJsii976 obj = SomeTypeJsii976.returnReturn();
assertEquals(obj.getFoo(), 333);
}

static class PartiallyInitializedThisConsumerImpl extends PartiallyInitializedThisConsumer {
@Override
public String consumePartiallyInitializedThis(final ConstructorPassesThisOut obj,
Expand Down
10 changes: 9 additions & 1 deletion packages/jsii-python-runtime/tests/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
StructA,
StructB,
StructUnionConsumer,
SomeTypeJsii976
SomeTypeJsii976,
AnonymousImplementationProvider,
IAnonymousImplementationProvider
)
from scope.jsii_calc_lib import IFriendly, EnumFromScopedModule, Number

Expand Down Expand Up @@ -1013,6 +1015,12 @@ def test_can_pass_nested_struct_as_dict():
}
)

def test_can_leverage_indirect_interface_polymorphism():
provider = AnonymousImplementationProvider()
assert provider.provide_as_class().value == 1337
assert provider.provide_as_interface().value == 1337
assert provider.provide_as_interface().verb() == "to implement"

# https://github.com/aws/jsii/issues/976
def test_return_subclass_that_implements_interface_976():
obj = SomeTypeJsii976.return_return()
Expand Down

0 comments on commit 334eff8

Please sign in to comment.