From 1340eb67de9e303584705b46658e815aac5cef4e Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Fri, 22 Dec 2023 06:46:27 +0100 Subject: [PATCH] refactor: Extract custom test context (cherry picked from commit 10e529ee764c67e65dbde481a6e17773412cbb11) --- .../InterpreterContextExpressionTest.scala | 10 +------ .../InterpreterListExpressionTest.scala | 11 +------- .../impl/interpreter/MyCustomContext.scala | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 src/test/scala/org/camunda/feel/impl/interpreter/MyCustomContext.scala diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala index 225074ef2..e52435ac4 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala @@ -61,20 +61,12 @@ class InterpreterContextExpressionTest it should "access a previous entry if there is a variable with the same name (custom context)" in { evaluateExpression( expression = "{a:1, b:a+1}", - context = new MyContext(Map("a" -> 0)) + context = new MyCustomContext(Map("a" -> 0)) ) should returnResult( Map("a" -> 1, "b" -> 2) ) } - class MyContext(val vars: Map[String, Any]) extends CustomContext { - override def variableProvider: VariableProvider = new VariableProvider { - override def getVariable(name: String): Option[Any] = vars.get(name) - - override def keys: Iterable[String] = vars.keys - } - } - it should "be compared with '='" in { evaluateExpression("{} = {}") should returnResult(true) evaluateExpression("{x:1} = {x:1}") should returnResult(true) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterListExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterListExpressionTest.scala index 2d17114e6..2982fe4b8 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterListExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterListExpressionTest.scala @@ -421,17 +421,8 @@ class InterpreterListExpressionTest {"loanId" : "AAA002", "amount" : 20}, {"loanId" : "AAA001", "amount" : 50} ]}.loans[loanId = id].amount)""", - context = new MyContext(Map("id" -> "AAA002", "loanId" -> "AAA002")) + context = new MyCustomContext(Map("id" -> "AAA002", "loanId" -> "AAA002")) ) should returnResult(20) } - - class MyContext(val vars: Map[String, Any]) extends CustomContext { - override def variableProvider: VariableProvider = new VariableProvider { - override def getVariable(name: String): Option[Any] = vars.get(name) - - override def keys: Iterable[String] = vars.keys - } - } - } diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/MyCustomContext.scala b/src/test/scala/org/camunda/feel/impl/interpreter/MyCustomContext.scala new file mode 100644 index 000000000..8412c663a --- /dev/null +++ b/src/test/scala/org/camunda/feel/impl/interpreter/MyCustomContext.scala @@ -0,0 +1,27 @@ +/* + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. Camunda licenses this file to you under the Apache License, + * Version 2.0; you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.camunda.feel.impl.interpreter + +import org.camunda.feel.context.{CustomContext, VariableProvider} + +class MyCustomContext(val vars: Map[String, Any]) extends CustomContext { + override def variableProvider: VariableProvider = new VariableProvider { + override def getVariable(name: String): Option[Any] = vars.get(name) + + override def keys: Iterable[String] = vars.keys + } +}