create tests for ScalarUnitValidator.java
[sdc.git] / common / onap-tosca-datatype / src / test / java / org / onap / sdc / tosca / datatypes / model / ScalarUnitValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 AT&T. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.tosca.datatypes.model;
22
23 import org.junit.jupiter.api.Test;
24 import static org.junit.jupiter.api.Assertions.assertNotNull;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27
28 public class ScalarUnitValidatorTest {
29
30     @Test
31     public void shouldGetAnInstance() {
32         assertNotNull(ScalarUnitValidator.getInstance());
33     }
34
35     @Test
36     public void testScalarUnit() {
37         ScalarUnitValidator validator = ScalarUnitValidator.getInstance();
38         assertTrue(validator.isScalarUnit(null));
39         assertTrue(validator.isScalarUnit("1y"));
40         assertTrue(validator.isScalarUnit("2ye"));
41         assertTrue(validator.isScalarUnit("3yes"));
42
43         assertFalse(validator.isScalarUnit("no"));
44         assertFalse(validator.isScalarUnit("1nooo"));
45     }
46
47     @Test
48     public void testValueScalarUnit() {
49         ScalarUnitValidator validator = ScalarUnitValidator.getInstance();
50         assertTrue(validator.isValueScalarUnit("2B", TestEnum.class));
51
52         assertFalse(validator.isValueScalarUnit("1val", TestEnum.class));
53         assertFalse(validator.isValueScalarUnit("null", null));
54         assertFalse(validator.isValueScalarUnit(null, null));
55     }
56 }
57
58 enum TestEnum {
59     B, KB
60 }