mount

jindrichm 2016-07-22T06:11:04.000167Z

Hi, I just started using Mount. Probably a beginner's question: I wonder how do you avoid class cast exceptions when using Mount components as arguments of Java methods (i.e. mount.core.DerefableState cannot be cast to the.expected.class)?

arnout 2016-07-22T09:09:30.000170Z

@jindrichm: A DerefableState must be derefed to get to the actual value (which you can then pass in as an argument to any function or Java method). So, (.yourJavaMethod obj @your-state) would do the trick I guess.

jindrichm 2016-07-22T09:12:23.000171Z

@arnout: Yes, but that won't work once the component is started, because it would be already dereferenced.

arnout 2016-07-22T09:13:37.000172Z

So you are trying to pass an unstarted state to a Java method?

jindrichm 2016-07-22T09:16:20.000173Z

No. This is used in a function that expects the component to be already started. However, it doesn't work in contexts when the component doesn't need to be started and the function is not used, such as during testing. Then I get a class cast exception.

arnout 2016-07-22T09:17:48.000174Z

But if the function that expects the component to be started is not used, then I expect a class cast exception should not occur

jindrichm 2016-07-22T09:20:33.000175Z

That's correct. Actually I overlooked that the function is called indirectly during testing. My fault. So I need to start the component also during testing.

arnout 2016-07-22T09:21:46.000176Z

Ok, good luck 😄

jindrichm 2016-07-22T09:22:06.000177Z

Any tips for managing Mount in testing?

arnout 2016-07-22T09:26:29.000178Z

Eh, let me see, I use mount-lite, where combinations of (start (only ...)) and (start (substitute ...)) (so (start (only ...) (substitute ...))) are your friend. In mount this translates to use of (start-with ...) and (start ...), or with (-> (only ...) (swap ...) start)

arnout 2016-07-22T09:27:18.000179Z

So, in short, you get full control over what components need to be started for a certain test, and you can mock (substitute) them if necessary.

arnout 2016-07-22T09:29:03.000181Z

Does that make sense to you?

jindrichm 2016-07-22T09:29:56.000182Z

Yes, thanks for the tip.

tolitius 2016-07-22T13:36:17.000185Z

@jindrichm: a little more about composing states: https://github.com/tolitius/mount#composing-states

👍 1