TCK tests

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
diff --git a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsongeneratortests/ClientTests.java b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsongeneratortests/ClientTests.java
index 616dece..fc47578 100644
--- a/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsongeneratortests/ClientTests.java
+++ b/tck/tck-tests/src/main/java/jakarta/jsonp/tck/api/jsongeneratortests/ClientTests.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -2139,4 +2139,49 @@
     result.eval();
   }
 
+  /*
+   * @testName: jsonGeneratorStreamNotClosedTest
+   */
+  @Test
+  public void jsonGeneratorStreamNotClosedTest() throws Fault {
+    ByteArrayOutputStreamCloseChecker stream = new ByteArrayOutputStreamCloseChecker();
+    JsonGenerator gen = Json.createGenerator(stream);
+    try {
+          gen.writeStartObject();
+          gen.write("foo", "bar");
+          // no end object
+          gen.close();
+          throw new Fault("It is expected a JsonGenerationException");
+    } catch (JsonGenerationException e) {
+          if (stream.closed) {
+              // Stream should not be closed
+              throw new Fault("The underlying stream is closed but it shouldn't because JSON object was not completed");
+          }
+    } 
+  }
+
+  /*
+   * @testName: jsonGeneratorStreamClosedTest
+   */
+  @Test
+  public void jsonGeneratorStreamClosedTest() throws Fault {
+    ByteArrayOutputStreamCloseChecker stream = new ByteArrayOutputStreamCloseChecker();
+    JsonGenerator gen = Json.createGenerator(stream);
+    gen.writeStartObject();
+    gen.write("foo", "bar");
+    gen.writeEnd();
+    gen.close();
+    if (!stream.closed) {
+        // Stream should be closed
+        throw new Fault("The underlying stream has to be closed because JSON object was completed");
+    }
+  }
+
+  private static class ByteArrayOutputStreamCloseChecker extends ByteArrayOutputStream {
+    private boolean closed = false;
+    @Override
+    public void close() throws IOException {
+        closed = true;
+    }
+  }
 }