From 5015e7fd771db2e0a2d01f5634e5e66a25dc93f8 Mon Sep 17 00:00:00 2001 From: Wojciech Potiopa Date: Fri, 21 Jun 2019 17:41:45 +0200 Subject: [PATCH 1/3] Tests for defaulted parameters in classes (#12) --- ...tions.ceylon => ClassInjectionTest.ceylon} | 8 ++++-- .../defaultParametersDependencies.ceylon | 7 ++++++ .../model/DefaultParametersModel.ceylon | 21 ++++++++++++++++ .../engine/integration/model/fixture.ceylon | 5 ++++ .../herd/depin/engine/model/package.ceylon | 1 - .../engine/poc/DefaultedParameterTest.ceylon | 25 +++++++++++++++++++ .../engine/{ => poc}/InvocationTest.ceylon | 4 ++- .../engine/{ => poc}/TypeParameterTest.ceylon | 0 .../engine/{ => poc}/TypeRetreivalTest.ceylon | 10 +++++--- .../engine/poc/model/DefaultedClass.ceylon | 1 + .../{ => poc}/model/Parametrized.ceylon | 0 .../depin/engine/{ => poc}/model/Plain.ceylon | 0 .../engine/{ => poc}/model/annotations.ceylon | 0 .../engine/{ => poc}/model/fixtures.ceylon | 0 .../depin/engine/poc/model/package.ceylon | 1 + .../engine/poc/model/testFunctions.ceylon | 2 ++ .../test/herd/depin/engine/poc/package.ceylon | 1 + .../herd/depin/engine/testFunctions.ceylon | 5 ---- 18 files changed, 78 insertions(+), 13 deletions(-) rename test/test/herd/depin/engine/integration/{ClassSimpleInjections.ceylon => ClassInjectionTest.ceylon} (69%) create mode 100644 test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon create mode 100644 test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon delete mode 100644 test/test/herd/depin/engine/model/package.ceylon create mode 100644 test/test/herd/depin/engine/poc/DefaultedParameterTest.ceylon rename test/test/herd/depin/engine/{ => poc}/InvocationTest.ceylon (89%) rename test/test/herd/depin/engine/{ => poc}/TypeParameterTest.ceylon (100%) rename test/test/herd/depin/engine/{ => poc}/TypeRetreivalTest.ceylon (81%) create mode 100644 test/test/herd/depin/engine/poc/model/DefaultedClass.ceylon rename test/test/herd/depin/engine/{ => poc}/model/Parametrized.ceylon (100%) rename test/test/herd/depin/engine/{ => poc}/model/Plain.ceylon (100%) rename test/test/herd/depin/engine/{ => poc}/model/annotations.ceylon (100%) rename test/test/herd/depin/engine/{ => poc}/model/fixtures.ceylon (100%) create mode 100644 test/test/herd/depin/engine/poc/model/package.ceylon create mode 100644 test/test/herd/depin/engine/poc/model/testFunctions.ceylon create mode 100644 test/test/herd/depin/engine/poc/package.ceylon delete mode 100644 test/test/herd/depin/engine/testFunctions.ceylon diff --git a/test/test/herd/depin/engine/integration/ClassSimpleInjections.ceylon b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon similarity index 69% rename from test/test/herd/depin/engine/integration/ClassSimpleInjections.ceylon rename to test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon index 214cd36..bbed9df 100644 --- a/test/test/herd/depin/engine/integration/ClassSimpleInjections.ceylon +++ b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon @@ -9,9 +9,10 @@ import herd.depin.engine { import test.herd.depin.engine.integration.model { Person, fixture, - DataSource + DataSource, + DefaultParametersModel } -shared class ClassSimpleInjections() { +shared class ClassInjectionTest() { Depin depin=Depin().include{ inclusions = {`package test.herd.depin.engine.integration.dependencies`}; @@ -24,5 +25,8 @@ shared class ClassSimpleInjections() { shared test void shouldInjectMysqlDataSource(){ assert(depin.inject(`DataSource`)==fixture.dataSouce.mysqlDataSource); } + shared test void shouldInjectNonDefaultParameters(){ + assert(depin.inject(`DefaultParametersModel`)==fixture.defaultParameter.instance); + } } \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon b/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon new file mode 100644 index 0000000..52f7aca --- /dev/null +++ b/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon @@ -0,0 +1,7 @@ +import test.herd.depin.engine.integration.model { + fixture +} +import herd.depin.engine { + dependency +} +shared dependency String nonDefault=fixture.defaultParameter.nonDefault; \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon b/test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon new file mode 100644 index 0000000..ec0a8ee --- /dev/null +++ b/test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon @@ -0,0 +1,21 @@ +shared class DefaultParametersModel(shared String nonDefault,shared String defaultedParameter=fixture.defaultParameter.text) { + + + shared actual Boolean equals(Object that) { + if (is DefaultParametersModel that) { + return nonDefault==that.nonDefault && + defaultedParameter==that.defaultedParameter; + } + else { + return false; + } + } + + shared actual Integer hash { + variable value hash = 1; + hash = 31*hash + nonDefault.hash; + hash = 31*hash + defaultedParameter.hash; + return hash; + } + +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/fixture.ceylon b/test/test/herd/depin/engine/integration/model/fixture.ceylon index 41cab65..8a83e25 100644 --- a/test/test/herd/depin/engine/integration/model/fixture.ceylon +++ b/test/test/herd/depin/engine/integration/model/fixture.ceylon @@ -11,4 +11,9 @@ shared object fixture { url = "jdbc:mysql://localhost:3306/myDb?createDatabaseIfNotExist=true"; }; } + shared object defaultParameter{ + shared String nonDefault="Abc"; + shared String text="abc"; + shared DefaultParametersModel instance=DefaultParametersModel(nonDefault,text) ; + } } \ No newline at end of file diff --git a/test/test/herd/depin/engine/model/package.ceylon b/test/test/herd/depin/engine/model/package.ceylon deleted file mode 100644 index 5588a45..0000000 --- a/test/test/herd/depin/engine/model/package.ceylon +++ /dev/null @@ -1 +0,0 @@ -shared package test.herd.depin.engine.model; diff --git a/test/test/herd/depin/engine/poc/DefaultedParameterTest.ceylon b/test/test/herd/depin/engine/poc/DefaultedParameterTest.ceylon new file mode 100644 index 0000000..7056d85 --- /dev/null +++ b/test/test/herd/depin/engine/poc/DefaultedParameterTest.ceylon @@ -0,0 +1,25 @@ +import ceylon.test { + test +} +import test.herd.depin.engine.poc.model { + DefaultedClass +} +shared class DefaultedParameterTest() { + + shared test void shouldInstantiateDefaultedClassWithoutProvidedParameters(){ + value apply = `DefaultedClass`.apply(); + assert(apply.defaulted=="abc"); + } + shared test void shouldInstantiateDefaultedClassWithoutProvidedParametersViaConstructor(){ + assert(exists constructor=`DefaultedClass`.defaultConstructor); + value apply=constructor.apply(); + assert(apply.defaulted=="abc"); + } + + + shared test void shouldInstantiateDefaultedClassWithoutProvidedParametersViaDeclaration(){ + value defaultConstructor = `class DefaultedClass`.defaultConstructor; + assert(is DefaultedClass apply=defaultConstructor.invoke()); + assert(apply.defaulted=="abc"); + } +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/InvocationTest.ceylon b/test/test/herd/depin/engine/poc/InvocationTest.ceylon similarity index 89% rename from test/test/herd/depin/engine/InvocationTest.ceylon rename to test/test/herd/depin/engine/poc/InvocationTest.ceylon index 197f79f..f89740b 100644 --- a/test/test/herd/depin/engine/InvocationTest.ceylon +++ b/test/test/herd/depin/engine/poc/InvocationTest.ceylon @@ -1,7 +1,9 @@ import ceylon.test { test } -import test.herd.depin.engine.model { + +import test.herd.depin.engine.poc.model { + parametrizedReturnType, Parametrized, fixtures } diff --git a/test/test/herd/depin/engine/TypeParameterTest.ceylon b/test/test/herd/depin/engine/poc/TypeParameterTest.ceylon similarity index 100% rename from test/test/herd/depin/engine/TypeParameterTest.ceylon rename to test/test/herd/depin/engine/poc/TypeParameterTest.ceylon diff --git a/test/test/herd/depin/engine/TypeRetreivalTest.ceylon b/test/test/herd/depin/engine/poc/TypeRetreivalTest.ceylon similarity index 81% rename from test/test/herd/depin/engine/TypeRetreivalTest.ceylon rename to test/test/herd/depin/engine/poc/TypeRetreivalTest.ceylon index 3b30060..e303461 100644 --- a/test/test/herd/depin/engine/TypeRetreivalTest.ceylon +++ b/test/test/herd/depin/engine/poc/TypeRetreivalTest.ceylon @@ -1,11 +1,13 @@ -import test.herd.depin.engine.model { - Parametrized +import ceylon.language.meta.model { + Type } import ceylon.test { test } -import ceylon.language.meta.model { - Type + +import test.herd.depin.engine.poc.model { + parametrizedReturnType, + Parametrized } diff --git a/test/test/herd/depin/engine/poc/model/DefaultedClass.ceylon b/test/test/herd/depin/engine/poc/model/DefaultedClass.ceylon new file mode 100644 index 0000000..a1ea66d --- /dev/null +++ b/test/test/herd/depin/engine/poc/model/DefaultedClass.ceylon @@ -0,0 +1 @@ +shared class DefaultedClass(shared String defaulted="abc") {} \ No newline at end of file diff --git a/test/test/herd/depin/engine/model/Parametrized.ceylon b/test/test/herd/depin/engine/poc/model/Parametrized.ceylon similarity index 100% rename from test/test/herd/depin/engine/model/Parametrized.ceylon rename to test/test/herd/depin/engine/poc/model/Parametrized.ceylon diff --git a/test/test/herd/depin/engine/model/Plain.ceylon b/test/test/herd/depin/engine/poc/model/Plain.ceylon similarity index 100% rename from test/test/herd/depin/engine/model/Plain.ceylon rename to test/test/herd/depin/engine/poc/model/Plain.ceylon diff --git a/test/test/herd/depin/engine/model/annotations.ceylon b/test/test/herd/depin/engine/poc/model/annotations.ceylon similarity index 100% rename from test/test/herd/depin/engine/model/annotations.ceylon rename to test/test/herd/depin/engine/poc/model/annotations.ceylon diff --git a/test/test/herd/depin/engine/model/fixtures.ceylon b/test/test/herd/depin/engine/poc/model/fixtures.ceylon similarity index 100% rename from test/test/herd/depin/engine/model/fixtures.ceylon rename to test/test/herd/depin/engine/poc/model/fixtures.ceylon diff --git a/test/test/herd/depin/engine/poc/model/package.ceylon b/test/test/herd/depin/engine/poc/model/package.ceylon new file mode 100644 index 0000000..ad4290b --- /dev/null +++ b/test/test/herd/depin/engine/poc/model/package.ceylon @@ -0,0 +1 @@ +shared package test.herd.depin.engine.poc.model; diff --git a/test/test/herd/depin/engine/poc/model/testFunctions.ceylon b/test/test/herd/depin/engine/poc/model/testFunctions.ceylon new file mode 100644 index 0000000..8d0f5c4 --- /dev/null +++ b/test/test/herd/depin/engine/poc/model/testFunctions.ceylon @@ -0,0 +1,2 @@ + +shared Parametrized parametrizedReturnType() => fixtures.parametrzied.strParametrized; \ No newline at end of file diff --git a/test/test/herd/depin/engine/poc/package.ceylon b/test/test/herd/depin/engine/poc/package.ceylon new file mode 100644 index 0000000..50af13c --- /dev/null +++ b/test/test/herd/depin/engine/poc/package.ceylon @@ -0,0 +1 @@ +shared package test.herd.depin.engine.poc; diff --git a/test/test/herd/depin/engine/testFunctions.ceylon b/test/test/herd/depin/engine/testFunctions.ceylon deleted file mode 100644 index ac6a613..0000000 --- a/test/test/herd/depin/engine/testFunctions.ceylon +++ /dev/null @@ -1,5 +0,0 @@ -import test.herd.depin.engine.model { - Parametrized, - fixtures -} -Parametrized parametrizedReturnType() => fixtures.parametrzied.strParametrized; \ No newline at end of file From 0027f08f23292ff508215b3c598fd2c5125ed070 Mon Sep 17 00:00:00 2001 From: Wojciech Potiopa Date: Fri, 21 Jun 2019 18:23:29 +0200 Subject: [PATCH 2/3] Implement defaulted parameters handling, introduced filtering for non existance paramameters in incjectable implementations (#12) --- source/herd/depin/api/Injectable.ceylon | 16 ++++-- source/herd/depin/api/Provider.ceylon | 3 -- .../herd/depin/engine/DefaultCreator.ceylon | 11 ++-- .../herd/depin/engine/DefaultProvider.ceylon | 50 +++---------------- .../herd/depin/engine/DefaultScanner.ceylon | 3 +- .../injectable/ConstructorInjectable.ceylon | 32 ++++++++++++ .../injectable/FunctionInjectable.ceylon | 31 ++++++++++++ .../engine/injectable/ValueInjectable.ceylon | 29 +++++++++++ .../depin/engine/injectable/package.ceylon | 1 + 9 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 source/herd/depin/engine/injectable/ConstructorInjectable.ceylon create mode 100644 source/herd/depin/engine/injectable/FunctionInjectable.ceylon create mode 100644 source/herd/depin/engine/injectable/ValueInjectable.ceylon create mode 100644 source/herd/depin/engine/injectable/package.ceylon diff --git a/source/herd/depin/api/Injectable.ceylon b/source/herd/depin/api/Injectable.ceylon index ff5b154..e4ef20a 100644 --- a/source/herd/depin/api/Injectable.ceylon +++ b/source/herd/depin/api/Injectable.ceylon @@ -1,6 +1,3 @@ -import ceylon.language.meta.model { - Type -} import ceylon.language.meta.declaration { Declaration } @@ -12,8 +9,17 @@ shared abstract class Injectable(Declaration declaration){ - shared class Error(Declaration declaration,Type<> type,Dependency description,Throwable? cause=null) - extends Exception("Can't inject ``declaration`` of type ``type`` described as ``description``",cause){} + shared class Error extends Exception{ + shared new member(Throwable? cause=null,Anything container=null,{Anything*} parameters={}) + extends Exception("Can't inject into ``container else "null"`` ``declaration`` with available parameters: ``parameters``",cause){} + shared new (Throwable? cause=null,{Anything*} parameters={}) + extends Exception("Can't inject ``declaration`` with available parameters: ``parameters``",cause){} + + + + } + + string => declaration.string; } diff --git a/source/herd/depin/api/Provider.ceylon b/source/herd/depin/api/Provider.ceylon index 692f547..f1a684d 100644 --- a/source/herd/depin/api/Provider.ceylon +++ b/source/herd/depin/api/Provider.ceylon @@ -1,7 +1,4 @@ -import ceylon.language.meta.model { - Type -} import ceylon.language.meta.declaration { Declaration } diff --git a/source/herd/depin/engine/DefaultCreator.ceylon b/source/herd/depin/engine/DefaultCreator.ceylon index 8954761..9025083 100644 --- a/source/herd/depin/engine/DefaultCreator.ceylon +++ b/source/herd/depin/engine/DefaultCreator.ceylon @@ -6,16 +6,15 @@ import herd.depin.api { import ceylon.language.meta.declaration { Declaration } + shared class DefaultCreator(Registry registry,Resolver resolver) satisfies Creator{ + + shared actual Anything create(Declaration declaration) { value dependency = resolver.resolve(declaration); - if(exists injectable = registry.get(dependency)){ - return injectable.inject(this); - } - throw Exception("Dependency [``dependency``] not found in registry did You made a scan ? Available dependencies:\n +``registry``"); + return registry.get(dependency)?.inject(this); } - - + } \ No newline at end of file diff --git a/source/herd/depin/engine/DefaultProvider.ceylon b/source/herd/depin/engine/DefaultProvider.ceylon index a7a9356..22e4396 100644 --- a/source/herd/depin/engine/DefaultProvider.ceylon +++ b/source/herd/depin/engine/DefaultProvider.ceylon @@ -1,11 +1,9 @@ import ceylon.language.meta.declaration { Declaration, - FunctionOrValueDeclaration, FunctionDeclaration, ValueDeclaration, CallableConstructorDeclaration, ClassDeclaration, - NestableDeclaration, ConstructorDeclaration, GenericDeclaration } @@ -14,8 +12,12 @@ import herd.depin.api { Provider, Injectable, Dependency, - Registry, - Creator + Registry +} +import herd.depin.engine.injectable { + ConstructorInjectable, + FunctionInjectable, + ValueInjectable } shared class DefaultProvider(Registry registry) satisfies Provider{ shared actual Injectable provide(Declaration declaration, Dependency dependency) { @@ -36,7 +38,7 @@ shared class DefaultProvider(Registry registry) satisfies Provider{ if(exists defaultConstructor= declaration.defaultConstructor){ return ConstructorInjectable(defaultConstructor); } - value constructors=declaration.constructorDeclarations().select((ConstructorDeclaration element) => element.annotated()); + ConstructorDeclaration[] constructors=declaration.constructorDeclarations().select((ConstructorDeclaration element) => element.annotated()); if(constructors.size==0){ throw Exception("Can't select injection target, no default constructor or annotated `` `class TargetAnnotation` ``"); } @@ -52,42 +54,4 @@ shared class DefaultProvider(Registry registry) satisfies Provider{ } } -class ConstructorInjectable(CallableConstructorDeclaration declaration) extends Injectable(declaration){ - shared actual Anything inject(Creator injector) { - value parameters = declaration.parameterDeclarations.collect((FunctionOrValueDeclaration element) => injector.create(element)); - if(declaration.container.container is NestableDeclaration){ - assert(is Object container = injector.create(declaration.container)); - return declaration.memberInvoke(container,[], parameters); - } - return declaration.invoke([],*parameters); - } - - -} -class FunctionInjectable(FunctionDeclaration declaration) extends Injectable(declaration){ - shared actual Anything inject(Creator injector) { - value parameters = declaration.parameterDeclarations.collect((FunctionOrValueDeclaration element) => injector.create(element)); - if(is NestableDeclaration containerDeclaration=declaration.container){ - assert(exists container = injector.create(containerDeclaration)); - return declaration.memberInvoke(container,[],parameters); - }else{ - return declaration.invoke([],*parameters); - } - } - - -} -class ValueInjectable(ValueDeclaration declaration) extends Injectable(declaration){ - shared actual Anything inject(Creator injector) { - if(is NestableDeclaration containerDeclaration=declaration.container){ - assert(exists container = injector.create(containerDeclaration)); - return declaration.memberGet(container); - }else{ - return declaration.get(); - } - } - - - -} diff --git a/source/herd/depin/engine/DefaultScanner.ceylon b/source/herd/depin/engine/DefaultScanner.ceylon index 709d70d..be8e461 100644 --- a/source/herd/depin/engine/DefaultScanner.ceylon +++ b/source/herd/depin/engine/DefaultScanner.ceylon @@ -1,7 +1,6 @@ import herd.depin.api { Scope, - Scanner, - Dependency + Scanner } import ceylon.language.meta.declaration { Declaration, diff --git a/source/herd/depin/engine/injectable/ConstructorInjectable.ceylon b/source/herd/depin/engine/injectable/ConstructorInjectable.ceylon new file mode 100644 index 0000000..46908b2 --- /dev/null +++ b/source/herd/depin/engine/injectable/ConstructorInjectable.ceylon @@ -0,0 +1,32 @@ +import ceylon.language.meta.declaration { + NestableDeclaration, + CallableConstructorDeclaration, + FunctionOrValueDeclaration +} +import herd.depin.api { + Injectable, + Creator +} +shared class ConstructorInjectable(CallableConstructorDeclaration declaration) extends Injectable(declaration){ + shared actual Anything inject(Creator injector) { + value parameters = declaration.parameterDeclarations + .map((FunctionOrValueDeclaration element) => element->injector.create(element)) + .filter((FunctionOrValueDeclaration elementKey -> Anything elementItem) => !elementKey.defaulted || elementItem exists) + .collect((FunctionOrValueDeclaration elementKey -> Anything elementItem) => elementItem); + if(declaration.container.container is NestableDeclaration){ + assert(is Object container = injector.create(declaration.container)); + try{ + return declaration.memberInvoke(container,[], parameters); + }catch(Exception x){ + throw Error.member(x,container,parameters); + } + } + try{ + return declaration.invoke([],*parameters); + }catch(Exception x){ + throw Error(x,parameters); + } + } + + +} \ No newline at end of file diff --git a/source/herd/depin/engine/injectable/FunctionInjectable.ceylon b/source/herd/depin/engine/injectable/FunctionInjectable.ceylon new file mode 100644 index 0000000..a4803a9 --- /dev/null +++ b/source/herd/depin/engine/injectable/FunctionInjectable.ceylon @@ -0,0 +1,31 @@ +import ceylon.language.meta.declaration { + NestableDeclaration, + FunctionOrValueDeclaration, + FunctionDeclaration +} +import herd.depin.api { + Injectable, + Creator +} +shared class FunctionInjectable(FunctionDeclaration declaration) extends Injectable(declaration){ + shared actual Anything inject(Creator injector) { + value parameters = declaration.parameterDeclarations + .map((FunctionOrValueDeclaration element) => element->injector.create(element)) + .filter((FunctionOrValueDeclaration elementKey -> Anything elementItem) => !elementKey.defaulted || elementItem exists) + .collect((FunctionOrValueDeclaration elementKey -> Anything elementItem) => elementItem); + if(is NestableDeclaration containerDeclaration=declaration.container){ + assert(exists container = injector.create(containerDeclaration)); + try{ + return declaration.memberInvoke(container,[],parameters); + }catch(Exception x){ + throw Error.member(x,container,parameters); + } + }else{ + try{ + return declaration.invoke([],*parameters); + }catch(Exception x){ + throw Error(x,parameters); + } + } + } +} \ No newline at end of file diff --git a/source/herd/depin/engine/injectable/ValueInjectable.ceylon b/source/herd/depin/engine/injectable/ValueInjectable.ceylon new file mode 100644 index 0000000..34157c8 --- /dev/null +++ b/source/herd/depin/engine/injectable/ValueInjectable.ceylon @@ -0,0 +1,29 @@ +import ceylon.language.meta.declaration { + NestableDeclaration, + ValueDeclaration +} +import herd.depin.api { + Injectable, + Creator +} +shared class ValueInjectable(ValueDeclaration declaration) extends Injectable(declaration){ + shared actual Anything inject(Creator injector) { + if(is NestableDeclaration containerDeclaration=declaration.container){ + assert(exists container = injector.create(containerDeclaration)); + try{ + return declaration.memberGet(container); + }catch(Exception x){ + throw Error.member(x,container); + } + }else{ + try{ + return declaration.get(); + }catch(Exception x){ + throw Error(x); + } + } + } + + + +} \ No newline at end of file diff --git a/source/herd/depin/engine/injectable/package.ceylon b/source/herd/depin/engine/injectable/package.ceylon new file mode 100644 index 0000000..ff79be7 --- /dev/null +++ b/source/herd/depin/engine/injectable/package.ceylon @@ -0,0 +1 @@ +package herd.depin.engine.injectable; From f25fe81166b88b877094682472286f8d5c167f74 Mon Sep 17 00:00:00 2001 From: Wojciech Potiopa Date: Fri, 21 Jun 2019 18:39:47 +0200 Subject: [PATCH 3/3] More integration tests for defaulted parameters (#12) --- .../integration/ClassInjectionTest.ceylon | 13 ++++++++++--- .../defaultParametersDependencies.ceylon | 7 ++++++- ...lon => DefaultParametersConstructor.ceylon} | 4 ++-- .../model/DefaultedParameterFunction.ceylon | 18 ++++++++++++++++++ .../model/DefaultedParametersByFunction.ceylon | 15 +++++++++++++++ .../engine/integration/model/fixture.ceylon | 9 ++++++++- 6 files changed, 59 insertions(+), 7 deletions(-) rename test/test/herd/depin/engine/integration/model/{DefaultParametersModel.ceylon => DefaultParametersConstructor.ceylon} (65%) create mode 100644 test/test/herd/depin/engine/integration/model/DefaultedParameterFunction.ceylon create mode 100644 test/test/herd/depin/engine/integration/model/DefaultedParametersByFunction.ceylon diff --git a/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon index bbed9df..522b48d 100644 --- a/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon +++ b/test/test/herd/depin/engine/integration/ClassInjectionTest.ceylon @@ -10,7 +10,9 @@ import test.herd.depin.engine.integration.model { Person, fixture, DataSource, - DefaultParametersModel + DefaultParametersConstructor, + DefaultedParametersByFunction, + DefaultedParameterFunction } shared class ClassInjectionTest() { @@ -26,7 +28,12 @@ shared class ClassInjectionTest() { assert(depin.inject(`DataSource`)==fixture.dataSouce.mysqlDataSource); } shared test void shouldInjectNonDefaultParameters(){ - assert(depin.inject(`DefaultParametersModel`)==fixture.defaultParameter.instance); + assert(depin.inject(`DefaultParametersConstructor`)==fixture.defaultParameter.instance); + } + shared test void shouldInjectDefaultedParameterFromFunction(){ + assert(depin.inject(`DefaultedParametersByFunction`)==fixture.defaultedParameterByFunction.instance); + } + shared test void shouldInjectDefaultedParameterClassFunction(){ + assert(depin.inject(`DefaultedParameterFunction`).fun()==fixture.defaultedParameterFunction.param); } - } \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon b/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon index 52f7aca..38b8135 100644 --- a/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon +++ b/test/test/herd/depin/engine/integration/dependencies/defaultParametersDependencies.ceylon @@ -4,4 +4,9 @@ import test.herd.depin.engine.integration.model { import herd.depin.engine { dependency } -shared dependency String nonDefault=fixture.defaultParameter.nonDefault; \ No newline at end of file +shared dependency String nonDefault=fixture.defaultParameter.nonDefault; + + +shared dependency String defaultedByFunction(String defaulted=fixture.defaultedParameterByFunction.param){ + return defaulted; +} diff --git a/test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon b/test/test/herd/depin/engine/integration/model/DefaultParametersConstructor.ceylon similarity index 65% rename from test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon rename to test/test/herd/depin/engine/integration/model/DefaultParametersConstructor.ceylon index ec0a8ee..fea3693 100644 --- a/test/test/herd/depin/engine/integration/model/DefaultParametersModel.ceylon +++ b/test/test/herd/depin/engine/integration/model/DefaultParametersConstructor.ceylon @@ -1,8 +1,8 @@ -shared class DefaultParametersModel(shared String nonDefault,shared String defaultedParameter=fixture.defaultParameter.text) { +shared class DefaultParametersConstructor(shared String nonDefault,shared String defaultedParameter=fixture.defaultParameter.text) { shared actual Boolean equals(Object that) { - if (is DefaultParametersModel that) { + if (is DefaultParametersConstructor that) { return nonDefault==that.nonDefault && defaultedParameter==that.defaultedParameter; } diff --git a/test/test/herd/depin/engine/integration/model/DefaultedParameterFunction.ceylon b/test/test/herd/depin/engine/integration/model/DefaultedParameterFunction.ceylon new file mode 100644 index 0000000..ac2fb69 --- /dev/null +++ b/test/test/herd/depin/engine/integration/model/DefaultedParameterFunction.ceylon @@ -0,0 +1,18 @@ +shared class DefaultedParameterFunction(shared String fun()=> fixture.defaultedParameterFunction.param) { + + shared actual Boolean equals(Object that) { + if (is DefaultedParameterFunction that) { + return true; + } + else { + return false; + } + } + + shared actual Integer hash { + variable value hash = 1; + return hash; + } + + +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/DefaultedParametersByFunction.ceylon b/test/test/herd/depin/engine/integration/model/DefaultedParametersByFunction.ceylon new file mode 100644 index 0000000..d8bb710 --- /dev/null +++ b/test/test/herd/depin/engine/integration/model/DefaultedParametersByFunction.ceylon @@ -0,0 +1,15 @@ +shared class DefaultedParametersByFunction(shared String defaultedByFunction) { + + + shared actual Boolean equals(Object that) { + if (is DefaultedParametersByFunction that) { + return defaultedByFunction==that.defaultedByFunction; + } + else { + return false; + } + } + + shared actual Integer hash => defaultedByFunction.hash; + +} \ No newline at end of file diff --git a/test/test/herd/depin/engine/integration/model/fixture.ceylon b/test/test/herd/depin/engine/integration/model/fixture.ceylon index 8a83e25..82b990e 100644 --- a/test/test/herd/depin/engine/integration/model/fixture.ceylon +++ b/test/test/herd/depin/engine/integration/model/fixture.ceylon @@ -14,6 +14,13 @@ shared object fixture { shared object defaultParameter{ shared String nonDefault="Abc"; shared String text="abc"; - shared DefaultParametersModel instance=DefaultParametersModel(nonDefault,text) ; + shared DefaultParametersConstructor instance=DefaultParametersConstructor(nonDefault,text) ; + } + shared object defaultedParameterByFunction{ + shared String param="abc"; + shared DefaultedParametersByFunction instance= DefaultedParametersByFunction(param); + } + shared object defaultedParameterFunction { + shared String param = "abc"; } } \ No newline at end of file