diff options
Diffstat (limited to 'utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java')
-rw-r--r-- | utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java index e38c5c9c..cadeb055 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java +++ b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardYamlCoderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,11 @@ package org.onap.policy.common.utils.coder; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import java.io.File; import java.io.StringWriter; @@ -45,6 +48,25 @@ public class StandardYamlCoderTest { } @Test + public void testToPrettyJson() throws CoderException { + String expected = coder.encode(cont); + assertEquals(expected, coder.encode(cont, false)); + + String yaml = coder.encode(cont, true); + assertEquals(expected, yaml); + + Container cont2 = coder.decode(yaml, Container.class); + assertEquals(cont, cont2); + + // test exception cases + IllegalArgumentException expex = new IllegalArgumentException("expected exception"); + coder = spy(new StandardYamlCoder()); + when(coder.toJson(cont)).thenThrow(expex); + assertThatThrownBy(() -> coder.encode(cont, false)).isInstanceOf(CoderException.class).hasCause(expex); + assertThatThrownBy(() -> coder.encode(cont, true)).isInstanceOf(CoderException.class).hasCause(expex); + } + + @Test public void testToJsonObject() throws CoderException { String yaml = coder.encode(cont); @@ -75,6 +97,12 @@ public class StandardYamlCoderTest { } @Test + public void testFromJsonDoubleToInteger() throws Exception { + Object value = coder.decode("20", Object.class); + assertEquals(Integer.valueOf(20), value); + } + + @Test public void testStandardTypeAdapter() throws Exception { String yaml = "abc: def\n"; StandardCoderObject sco = coder.fromJson(yaml, StandardCoderObject.class); |