Search in sources :

Example 1 with StringUtils

use of org.kie.workbench.common.stunner.bpmn.client.forms.util.StringUtils in project kie-wb-common by kiegroup.

the class AssignmentBaseTest method setUp.

public void setUp() throws Exception {
    // Prevent runtime GWT.create() error at DesignerEditorConstants.INSTANCE
    GWTMockUtilities.disarm();
    // MockDesignerEditorConstants replaces DesignerEditorConstants.INSTANCE
    final Answer answer = invocation -> invocation.getMethod().getName();
    final StunnerFormsClientFieldsConstants constants = mock(StunnerFormsClientFieldsConstants.class, answer);
    setFinalStaticField(StunnerFormsClientFieldsConstants.class.getDeclaredField("CONSTANTS"), constants);
    // Prevent GWT calls in StringUtils
    URL url = mock(URL.class);
    when(url.decodeQueryString(any())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        return urlDecode((String) args[0]);
    });
    when(url.encodeQueryString(any())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        return urlEncode((String) args[0]);
    });
    StringUtils.setURL(url);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) URLDecoder(java.net.URLDecoder) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) StunnerFormsClientFieldsConstants(org.kie.workbench.common.stunner.bpmn.client.forms.fields.i18n.StunnerFormsClientFieldsConstants) Answer(org.mockito.stubbing.Answer) URLEncoder(java.net.URLEncoder) GWTMockUtilities(com.google.gwt.junit.GWTMockUtilities) StringUtils(org.kie.workbench.common.stunner.bpmn.client.forms.util.StringUtils) Modifier(java.lang.reflect.Modifier) URL(org.kie.workbench.common.stunner.bpmn.client.forms.util.URL) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Mockito.mock(org.mockito.Mockito.mock) Answer(org.mockito.stubbing.Answer) StunnerFormsClientFieldsConstants(org.kie.workbench.common.stunner.bpmn.client.forms.fields.i18n.StunnerFormsClientFieldsConstants) URL(org.kie.workbench.common.stunner.bpmn.client.forms.util.URL)

Aggregations

GWTMockUtilities (com.google.gwt.junit.GWTMockUtilities)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 URLDecoder (java.net.URLDecoder)1 URLEncoder (java.net.URLEncoder)1 StunnerFormsClientFieldsConstants (org.kie.workbench.common.stunner.bpmn.client.forms.fields.i18n.StunnerFormsClientFieldsConstants)1 StringUtils (org.kie.workbench.common.stunner.bpmn.client.forms.util.StringUtils)1 URL (org.kie.workbench.common.stunner.bpmn.client.forms.util.URL)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Answer (org.mockito.stubbing.Answer)1