fapifta commented on a change in pull request #701: HDDS-2691. Ozone Shell code 
cleanup
URL: https://github.com/apache/hadoop-ozone/pull/701#discussion_r397302299
 
 

 ##########
 File path: 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/web/utils/TestJsonUtils.java
 ##########
 @@ -15,38 +15,33 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.hadoop.ozone.web.ozShell;
+package org.apache.hadoop.ozone.web.utils;
 
 import java.io.IOException;
-import java.time.Instant;
-import java.util.ArrayList;
 
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.ozone.client.OzoneVolume;
-import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.hdds.client.OzoneQuota;
 
-import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Test the json object printer.
  */
-public class TestObjectPrinter {
+public class TestJsonUtils {
 
   @Test
   public void printObjectAsJson() throws IOException {
+    OzoneQuota quota = new OzoneQuota(123, OzoneQuota.Units.MB);
+
+    String result = JsonUtils.toJsonStringWithDefaultPrettyPrinter(quota);
+
+    assertContains(result, "\"size\" : 123");
+    assertContains(result, "\"unit\" : \"MB\"");
+  }
 
-    OzoneConfiguration conf = new OzoneConfiguration();
-    OzoneVolume volume =
-        new OzoneVolume(conf, Mockito.mock(ClientProtocol.class), "name",
-            "admin", "owner", 1L, Instant.EPOCH.toEpochMilli(),
-            new ArrayList<>());
-
-    String result = ObjectPrinter.getObjectAsJson(volume);
-    Assert.assertTrue("Result is not a proper json",
-        result.contains("\"owner\""));
-    Assert.assertTrue("Result is not a proper json",
-        result.contains("\"1970-01-01T00:00:00Z\""));
+  private static void assertContains(String str, String part) {
+    assertTrue(str.contains(part),
+        () -> "Expected JSON to contain '" + part + "', but didn't: " + str);
 
 Review comment:
   Not necessary at all :) Thank you for clarifying though. I was just curious 
as I do not see any real benefit, but yeah, if it is only the evaluation time 
of the string concatenation, then that really is not much in a JUnit test.
   Also if we remove the `() ->` part we loose even this advantage ;)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to