Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [golo-dev] golo-dev Digest, Vol 32, Issue 5

Hello,

My brain still has to get used switching between static vs dynamic programming :)

I can simply cast to gololang.Union and write code like this:

Union u = (Union)detectPlayerInvoker.invoke(bluOsDetector);

Tuple unionMembers = u.destruct();
assertEquals(1, unionMembers.size());

DynamicObject foundPlayer = (DynamicObject)unionMembers.get(0);
assertEquals("SearchedPlayer", (String)foundPlayer.get("name"));
assertEquals("audiostreamerscrobbler.maintypes.Player.types.PlayerTypes$BluOs", foundPlayer.get("playerType").getClass().getName());

Regards,
Vincent

 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Mon, 23 Apr 2018 01:04:46 +0200
> From: Vincent <vvanderleun@xxxxxxxxxxxx>
> To: golo-dev@xxxxxxxxxxx
> Subject: [golo-dev] Using unions in Java code?
> Message-ID:
> 	<1524438286.3296310.1346903624.26E3C52D@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Content-Type: text/plain; charset="utf-8"
> 
> Hello,
> 
> I could not think of a way to write unit tests in Golo, so for my Scrobbler 
> project, so I've chosen to write them in Java and JUnit. Had lots of troubles 
> with setting up an Eclipse IDE project, but I found a workaround.
> 
> I've now hit a brick wall, that I cannot seem to fix.
> 
> I have the following module in my Golo code:
> 
> module audiostreamerscrobbler.states.detector.MainTypes
> 
> union DetectorStateTypes = {
> 	PlayerNotFound
> 	PlayerFound = { Player }
> }
> 
> In my Java unit test code I need to check whether a functions returns an
> instance of DetectorStateTypes.PlayerNotFound, so I added following 
> import statement:
> 
> import 
> audiostreamerscrobbler.states.detector.MainTypes.types.DetectorStateTypes.PlayerNotFound;
> 
> In Eclipse IDE, there's a red line from audiostreamerscrobbler to types. 
> It reports the following error: 
> "audiostreamerscrobbler.states.detector.DetectorStateTypes.types cannot be 
> resolved". Gradle reports the following error:
>  "xxx\BluOsPlayerDetectorTests.java:6: error: cannot find symbol, where the ^
> carrot is under the "t" of types.
> 
> Can unions be used in Java at all?
> 
> I have the impression that this is caused by the Golo compiler, which compiles 
> a (in this particular case seemingly unneccessary) MainTypes.class file in the 
> build\classes\audiostreamerscrobbler\states\detector directory and Java,
> unlike Golo, apparently does not like having a class name that matches with 
> a part of the package name.
> 
> Is there any clean solution, did I misunderstood things, or do I need to resort
> to reflections to check a union return value in Java unit tests?
> 
> Best regards,
> Vincent


Back to the top