influxdb-java icon indicating copy to clipboard operation
influxdb-java copied to clipboard

Point should have accessor for Tags and Fields

Open RusmanCool opened this issue 6 years ago • 3 comments

Currently Point class has only package-private accessors for getTags() and getFields(). Thus, it makes it very hard to test whether my data from POJO has been properly converted or used at all. The only option is to use lineProtocol() that returns a String in lineProtocol format, which I would need to parse to extract values to compare to what I have provided.

RusmanCool avatar Oct 22 '19 19:10 RusmanCool

This was intentionally to keep Point immutable.

majst01 avatar Oct 23 '19 07:10 majst01

@majst01 You actually do modify the Point from within BatchPoints class. Nevertheless, you can return Collections.unmodifableMaps to kepp the data still unmutable as an example. And without the access to getters, it is impossible to test the conversion between POJOs and Point using very helpful method from Point class.

RusmanCool avatar Oct 25 '19 09:10 RusmanCool

Fully agree with @RusmanCool !

While writing my tests I was forced to use reflection to access Point's details.

Package-private getters are not the only way to keep your class immutable (see for example Bloch's 'Effective Java', item 17 & 50)

mario45211 avatar Mar 01 '21 14:03 mario45211