2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.onap.so.bpmn.core.internal;
22 import static org.hamcrest.CoreMatchers.containsString;
23 import static org.junit.Assert.*;
24 import static org.mockito.ArgumentMatchers.contains;
26 import java.util.Optional;
27 import org.junit.Test;
29 public class VariableNameExtractorTest {
32 public void shouldExtractVariableName() throws Exception {
34 String name = "A_different_NAME123";
35 String variable = "${A_different_NAME123}";
36 VariableNameExtractor extractor = new VariableNameExtractor(variable);
38 Optional<String> extracted = extractor.extract();
40 assertTrue(extracted.isPresent());
41 assertThat(extracted.get(), containsString(name));
45 public void shouldExtractVariableNameFromWhitespaces() throws Exception {
48 String variable = " \n\t$ \n\t{ \n\tname \n\t} \n\t";
49 VariableNameExtractor extractor = new VariableNameExtractor(variable);
51 Optional<String> extracted = extractor.extract();
53 assertTrue(extracted.isPresent());
54 assertThat(extracted.get(), containsString(name));
58 public void shouldReturnEmptyIfThereIsMoreThanVariable() throws Exception {
60 String variable = "a ${test}";
61 VariableNameExtractor extractor = new VariableNameExtractor(variable);
63 Optional<String> extracted = extractor.extract();
65 assertFalse(extracted.isPresent());
69 public void shouldReturnEmptyIfVariableNameIsIncorrect() throws Exception {
71 String variable = "${name with space}";
72 VariableNameExtractor extractor = new VariableNameExtractor(variable);
74 Optional<String> extracted = extractor.extract();
76 assertFalse(extracted.isPresent());
80 public void shouldReturnEmptyIfTwoVariablesPresent() throws Exception {
82 String variable = "${var1} ${var2}";
83 VariableNameExtractor extractor = new VariableNameExtractor(variable);
85 Optional<String> extracted = extractor.extract();
87 assertFalse(extracted.isPresent());