diff --git a/src/test/java/org/robotframework/javalib/reflection/KeywordInvokerGroupingArgumentsTest.java b/src/test/java/org/robotframework/javalib/reflection/KeywordInvokerGroupingArgumentsTest.java index e5e3f13..f9764f2 100644 --- a/src/test/java/org/robotframework/javalib/reflection/KeywordInvokerGroupingArgumentsTest.java +++ b/src/test/java/org/robotframework/javalib/reflection/KeywordInvokerGroupingArgumentsTest.java @@ -17,17 +17,63 @@ package org.robotframework.javalib.reflection; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertIterableEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.Arrays; +import java.util.HashMap; import java.util.List; - +import java.util.Map; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertIterableEquals; -import static org.mockito.Mockito.*; - public class KeywordInvokerGroupingArgumentsTest { private static TestKeywordInvoker testKeywordInvoker = new TestKeywordInvoker(); + @Test + public void testSingleArgumentWithMapForKeywordInvoker() { + Parameter mockParam = mock(Parameter.class); + doReturn(Map.class).when(mockParam).getType(); + when(mockParam.getName()).thenReturn("arg0"); + Parameter[] parameters = new Parameter[]{mockParam}; + Method mockedMethod = mock(Method.class); + when(mockedMethod.getParameterCount()).thenReturn(1); + when(mockedMethod.getParameters()).thenReturn(parameters); + doReturn(new Class[]{Map.class}).when(mockedMethod).getParameterTypes(); + KeywordInvoker keywordInvoker = new KeywordInvoker(new Object(), mockedMethod); + List parameterNames = keywordInvoker.getParameterNames(); + assertEquals(1, parameterNames.size()); + assertEquals("**arg0", parameterNames.get(0)); + + List args = Arrays.asList(buildHashMap()); + ArgumentCollector argumentCollector = new ArgumentCollector(mockedMethod.getParameterTypes(), parameterNames); + + List collectedArgs = argumentCollector.collectArguments(args, null); + // since the map has 3 entries + assertEquals(1, collectedArgs.size()); + assertEquals(3, ((HashMap) collectedArgs.get(0)).size()); + } + + private Map buildHashMap() { + Map map = new HashMap(); + map.put("key1", "value1"); + map.put("key2", "value2"); + map.put("key3", "value3"); + return map; + } + + private Parameter[] buildParameters() { + Parameter mockParam = mock(Parameter.class); + doReturn(Map.class).when(mockParam).getType(); + when(mockParam.getName()).thenReturn("arg0"); + return new Parameter[]{mockParam}; + } + @Test public void testGroupsRestOfTheArgumentsIfProvidedArgumentCountIsGreaterThanActualArgumentCount() { List providedArguments = Arrays.asList("arg1", "arg2", "arg3"); diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000..1f0955d --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline