https://kotlinlang.org logo
Title
m

Matheus

10/24/2018, 2:22 PM
pass clientProvider to TestService?
t

Tsvetozar Bonev

10/24/2018, 2:25 PM
Maybe make the TestService a lateinit val and initialize it in an init { } block when you have the cleintProviderInterface available
h

Hexa

10/24/2018, 2:28 PM
thanks can you i tried but got an error saying
late init
modifier is not allowed on primary constructor parameters
can you provide example as I think I may have misunderstood?
t

Tsvetozar Bonev

10/24/2018, 2:30 PM
Oh, sorry, turns out lateinit can't be in the constructor. Why do you need to pass so many things in the constructor though, surely you can build the needed dependency and then pass it
m

Matheus

10/24/2018, 2:31 PM
nah, I re-read the code. i don't think my suggestion would help, as you depend on other stuff to generate the client
h

Hexa

10/24/2018, 2:31 PM
yep I tried passing in the clientProvider to TestService and it didnt work too
I guess my whole Handler class architecture is wrong or what? Maybe there's another way
m

Matheus

10/24/2018, 2:32 PM
but why do you have 2 testServices? can't you use the one you got in the constructor at line 9?
h

Hexa

10/24/2018, 2:32 PM
Ah my mistake
yes the other testService is not needed
I only need the one in the constructor
m

Matheus

10/24/2018, 2:33 PM
ah ok. can you refactor it so the constructor doesn't depend on the client?
t

Tsvetozar Bonev

10/24/2018, 2:33 PM
I don't see why you're passing in the clientProvider as well as the testService
either just pass the provider and build the service inside or build it outside and pass it in
h

Hexa

10/24/2018, 2:38 PM
@Matheus you mean refactor so that I remove this line completely
val testService: TestService = TestServiceImpl(client))
m

Matheus

10/24/2018, 2:40 PM
The problem is that you need a client, which is built on TestHandler's constructor, to build another dependency from TestHandler. So either do that outside this class (build the client and build TestService), or make it so that TestService's constructor doesn't depend on client (maybe the methods could receive a client? can't really say much without seeing the rest of the code).
h

Hexa

10/24/2018, 2:48 PM
okay, just for my understanding if I just not inject
testService
in the constructor. and I use
val testService: TestService = TestServiceImpl(client)
in line 9 that would make my Handler less testable as Im depending on a concrete implementation, is that right? @Matheus
m

Matheus

10/24/2018, 2:49 PM
yes, you wouldn't be able to mock TestService to test this class