I'm writing some tests and need to make some assertions based on values given during setup. Normally the setup and assertion hook methods live in the same class so is trivial to store data between them using local fields. However, in this case the setup and assertion methods live in different classes. For example:
Please put to one side the silliness of my example, I have simplified it from reality to the point where it looks ridiculous (doesn't even compile) but does demonstrate the key problem which is how to share the dataStore between classes.
I know that I could take a Map instance and wrap it up in a singleton, but I feel this is a problem that's likely already been solved so am looking for an 'off the shelf' solution. Perhaps Spring, or Guava, or Apache, or something else has a ready made solution?
Create your Map in one location, with a getMap() method; you can then send data from that location but in a read‑only format. You can't send anything the other way with the same Map, obviously. If you are working in a small team, your ordinary Map would do nicely.