Repository: influxdata/influxdb-client-java
Pull request #136 (2020-07-27 07:17:05)

fix: Data Point: measurement name is requiring in constructor
Related-to #135

## Proposed Changes

The `measurement name` has to be specified.

## Checklist

<!-- Checkboxes below this note can be erased if not applicable to your Pull Request. -->

- [x] CHANGELOG.md updated
- [x] Rebased/mergeable
- [x] A test has been added if appropriate
- [x] `mvn test` completes successfully
- [x] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)
- [x] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)


codecov-commenter: # [Codecov](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=h1) Report
> Merging [#136](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=desc) into [master](https://codecov.io/gh/influxdata/influxdb-client-java/commit/536b82f020e654f301be57cb1f019434c710cea0&el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136/graphs/tree.svg?width=650&height=150&src=pr&token=s7s2Mr6Q9E)](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master     #136   +/-   ##
=========================================
  Coverage     91.31%   91.31%           
  Complexity      441      441           
=========================================
  Files           137      137           
  Lines          5388     5389    +1     
  Branches        202      202           
=========================================
+ Hits           4920     4921    +1     
  Misses          389      389           
  Partials         79       79           
```


| [Impacted Files](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...src/main/java/com/influxdb/client/write/Point.java](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136/diff?src=pr&el=tree#diff-Y2xpZW50L3NyYy9tYWluL2phdmEvY29tL2luZmx1eGRiL2NsaWVudC93cml0ZS9Qb2ludC5qYXZh) | `98.03% <100.00%> (+0.01%)` | `0.00 <0.00> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=footer). Last update [536b82f...2241fc5](https://codecov.io/gh/influxdata/influxdb-client-java/pull/136?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60a50d255d..d464843988 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 ## 1.11.0 [unreleased]
 
+### Bug Fixes
+1. [#136](https://github.com/influxdata/influxdb-client-java/pull/136): Data Point: measurement name is requiring in constructor
+
 ## 1.10.0 [2020-07-17]
 
 ### Bug Fixes
diff --git a/client/src/main/java/com/influxdb/client/write/Point.java b/client/src/main/java/com/influxdb/client/write/Point.java
index 65cb7f8815..990339c37d 100644
--- a/client/src/main/java/com/influxdb/client/write/Point.java
+++ b/client/src/main/java/com/influxdb/client/write/Point.java
@@ -72,6 +72,18 @@ public final class Point {
     private Number time;
     private WritePrecision precision = DEFAULT_WRITE_PRECISION;
 
+    /**
+     * Create a new Point with specified a measurement name.
+     *
+     * @param measurementName the measurement name
+     */
+    public Point(@Nonnull final String measurementName) {
+
+        Arguments.checkNotNull(measurementName, "measurement");
+
+        this.name = measurementName;
+    }
+
     /**
      * Create a new Point withe specified a measurement name.
      *
@@ -83,10 +95,7 @@ public final class Point {
 
         Arguments.checkNotNull(measurementName, "measurement");
 
-        Point point = new Point();
-        point.name = measurementName;
-
-        return point;
+        return new Point(measurementName);
     }
 
     /**


Test patch:
diff --git a/client/src/test/java/com/influxdb/client/write/PointTest.java b/client/src/test/java/com/influxdb/client/write/PointTest.java
index 30be6d6ab8..8102897621 100644
--- a/client/src/test/java/com/influxdb/client/write/PointTest.java
+++ b/client/src/test/java/com/influxdb/client/write/PointTest.java
@@ -64,6 +64,23 @@ class PointTest {
         Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2\\,o,location=europe level=2i");
     }
 
+    @Test
+    public void createByConstructor() {
+        Point point = new Point("h2o")
+                .addTag("location", "europe")
+                .addField("level", 2);
+
+        Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe level=2i");
+    }
+
+    @SuppressWarnings("ConstantConditions")
+    @Test
+    public void createByConstructorMeasurementRequired() {
+        Assertions.assertThatThrownBy(() -> new Point(null))
+                .isInstanceOf(NullPointerException.class)
+                .hasMessage("Expecting a not null reference for measurement");
+    }
+
     @Test
     void tagEmptyKey() {
 
@@ -124,7 +141,7 @@ class PointTest {
                 .addField("integer", 7)
                 .addField("integerObject", Integer.valueOf("8"))
                 .addField("boolean", false)
-                .addField("booleanObject", Boolean.parseBoolean("true"))
+                .addField("booleanObject", Boolean.TRUE)
                 .addField("string", "string value");
 
         String expected = "h2o,location=europe bigDecimal=33.45,boolean=false,booleanObject=true,double=2.0,doubleObject=5.0,"