2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.model.tosca.converters;
23 import org.junit.Test;
25 import java.util.Collections;
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;
32 public class ToscaFloatConverterTest {
35 public void convertEmptyString_returnNull() {
36 assertNull(executeFloatConversion(""));
40 public void convertNull_returnNull() {
41 assertNull(executeFloatConversion(null));
45 public void convertWholeNumber() {
46 assertThat(executeFloatConversion("1234"))
51 public void convertFloatNumber() {
52 assertThat(executeFloatConversion("3.141"))
57 public void convertNotValidFloat() {
58 assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("123.55.66"));
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"));
70 public void convertNonNumeric() {
71 assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("1234ABC"));
75 public void convertNumericWithCapitalFloatSign() {
76 assertThat(executeFloatConversion("1234F"))
81 public void convertNumericWithSmallLetterFloatSign() {
82 assertThat(executeFloatConversion("1234f"))
87 public void convertNumericWithFloatSignNotAtTheEnd_ThrowsException() {
88 assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> executeFloatConversion("12f34"));
91 private String executeFloatConversion(String s) {
92 return ToscaFloatConverter.getInstance().convert(s, null, Collections.emptyMap());