src/test/java/com/sourcesense/confluence/cmis/macros/AbstractMacroBaseUnitTestCase.java
protected <T extends BaseCMISMacro> T createCMISMockMacro(Class<T> clazz) throws MacroException
    {
        T mockMacro = mock(clazz);

        // VelocityUtils would brake with null pointers, override that
        when(mockMacro.render(anyString(), (RenderContext) anyObject())).thenAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                Object[] args = invocation.getArguments();

                String template = (String) args[0];
                RenderContext context = (RenderContext) args[1];

                for (Map.Entry<Object, Object> entry : context.getParams().entrySet())
                {
                    String key = (String) entry.getKey();
                    vc.put(key, entry.getValue());
                }

                return renderTemplate(template);
            }
        });

        when(mockMacro.fetchDocumentLink((ConfluenceCMISRepository) anyObject(), (Session) anyObject(), anyString(), anyBoolean())).thenReturn("http://www.sourcesense.com");

        // let the real business logic be executed, it's usually under test
        when(mockMacro.executeImpl(anyMap(), anyString(), (RenderContext) anyObject(), (ConfluenceCMISRepository) anyObject())).thenCallRealMethod();
        when(mockMacro.getTemplate()).thenCallRealMethod();

        return mockMacro;
    }
/**
     * Create a stubbed CMIS macro that allows testing without starting Confluence
     *
     * @param clazz The concrete Macro implementation to mock
     * @return The stubbed CMIS macro
     * @throws MacroException If the concrete macro logic fails
     */
Create a stubbed CMIS macro that allows testing without starting Confluence
@param clazz The concrete Macro implementation to mock
@return The stubbed CMIS macro
@throws MacroException If the concrete macro logic fails
Create a stubbed CMIS macro that allows testing without starting Confluence @param clazz The concrete Macro implementation to mock @return The stubbed CMIS macro @throws MacroException If the concrete macro logic fails
protected <T extends BaseCMISMacro> T createCMISMockMacro(Class<T> clazz) throws MacroException
    {
        T mockMacro = mock(clazz);
        when(mockMacro.render(anyString(), (RenderContext) anyObject())).thenAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                Object[] args = invocation.getArguments();
                String template = (String) args[0];
                RenderContext context = (RenderContext) args[1];
                for (Map.Entry<Object, Object> entry : context.getParams().entrySet())
                {
                    String key = (String) entry.getKey();
                    vc.put(key, entry.getValue());
                }
                return renderTemplate(template);
            }
        });
        when(mockMacro.fetchDocumentLink((ConfluenceCMISRepository) anyObject(), (Session) anyObject(), anyString(), anyBoolean())).thenReturn("http://www.sourcesense.com");
        when(mockMacro.executeImpl(anyMap(), anyString(), (RenderContext) anyObject(), (ConfluenceCMISRepository) anyObject())).thenCallRealMethod();
        when(mockMacro.getTemplate()).thenCallRealMethod();
        return mockMacro;
    }
protected < T extends BaseCMISMacro > T createCMISMockMacro ( Class < T > clazz ) throws MacroException { T mockMacro = mock ( clazz ) ; when ( mockMacro . render ( anyString ( ) , ( RenderContext ) anyObject ( ) ) ) . thenAnswer ( new Answer ( ) { public Object answer ( InvocationOnMock invocation ) throws Throwable { Object [ ] args = invocation . getArguments ( ) ; String template = ( String ) args [ 0 ] ; RenderContext context = ( RenderContext ) args [ 1 ] ; for ( Map . Entry < Object , Object > entry : context . getParams ( ) . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; vc . put ( key , entry . getValue ( ) ) ; } return renderTemplate ( template ) ; } } ) ; when ( mockMacro . fetchDocumentLink ( ( ConfluenceCMISRepository ) anyObject ( ) , ( Session ) anyObject ( ) , anyString ( ) , anyBoolean ( ) ) ) . thenReturn ( "http://www.sourcesense.com" ) ; when ( mockMacro . executeImpl ( anyMap ( ) , anyString ( ) , ( RenderContext ) anyObject ( ) , ( ConfluenceCMISRepository ) anyObject ( ) ) ) . thenCallRealMethod ( ) ; when ( mockMacro . getTemplate ( ) ) . thenCallRealMethod ( ) ; return mockMacro ; }
Create a stubbed CMIS macro that allows testing without starting Confluence
 @param clazz The concrete Macro implementation to mock
 @return The stubbed CMIS macro
 @throws MacroException If the concrete macro logic fails
Create a stubbed CMIS macro that allows testing without starting Confluence @param clazz The concrete Macro implementation to mock @return The stubbed CMIS macro @throws MacroException If the concrete macro logic fails
// VelocityUtils would brake with null pointers, override that // let the real business logic be executed, it's usually under test