Skip to content

Commit

Permalink
refactor: Extract custom test context
Browse files Browse the repository at this point in the history
(cherry picked from commit 10e529e)
  • Loading branch information
saig0 authored and github-actions[bot] committed Jan 2, 2024
1 parent cb4624c commit 1340eb6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

}
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 1340eb6

Please sign in to comment.