Added oparent to sdc main
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / tosca / converters / ToscaFloatConverterTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. 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.openecomp.sdc.be.model.tosca.converters;
22
23 import org.junit.Test;
24
25 import java.util.Collections;
26
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
29 import static org.junit.Assert.assertNull;
30
31
32 public class ToscaFloatConverterTest {
33
34     @Test
35     public void convertEmptyString_returnNull() {
36         assertNull(executeFloatConversion(""));
37     }
38
39     @Test
40     public void convertNull_returnNull() {
41         assertNull(executeFloatConversion(null));
42     }
43
44     @Test
45     public void convertWholeNumber() {
46         assertThat(executeFloatConversion("1234"))
47                 .isEqualTo("1234");
48     }
49
50     @Test
51     public void convertFloatNumber() {
52         assertThat(executeFloatConversion("3.141"))
53                 .isEqualTo("3.141");
54     }
55
56     @Test
57     public void convertNotValidFloat() {
58         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123.55.66"));
59     }
60
61     @Test
62     public void convertNumericWithSpecialChars() {
63         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123,55"));
64         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123&55"));
65         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123$$55"));
66         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123#55"));
67     }
68
69     @Test
70     public void convertNonNumeric() {
71         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("1234ABC"));
72     }
73
74     @Test
75     public void convertNumericWithCapitalFloatSign() {
76         assertThat(executeFloatConversion("1234F"))
77                 .isEqualTo("1234");
78     }
79
80     @Test
81     public void convertNumericWithSmallLetterFloatSign() {
82         assertThat(executeFloatConversion("1234f"))
83                 .isEqualTo("1234");
84     }
85
86     @Test
87     public void convertNumericWithFloatSignNotAtTheEnd_ThrowsException() {
88         assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("12f34"));
89     }
90
91     private String executeFloatConversion(String s) {
92         return ToscaFloatConverter.getInstance().convert(s, null, Collections.emptyMap());
93     }
94 }