/**
   * Create a mock CmisObject using Mockito that will contain the provided properties
   *
   * @param properties Array of arrays in the form of {{propertyId, displayName, propertyValue}}
   * @param clazz Class object in the CmisObject hierarchy that has to be created
   * @return The mocked CmisObject
   */
  protected <T extends CmisObject> T createMockedCmisObject(Object[][] properties, Class<T> clazz) {
    T object = mock(clazz);
    List<Property<?>> documentProperties = new ArrayList<Property<?>>();
    for (Object[] mockProp : properties) {
      Property prop = createMockedProperty(mockProp[0], mockProp[1], mockProp[2]);
      documentProperties.add(prop);
      when(object.getProperty(mockProp[0].toString())).thenReturn(prop);

      if (PropertyIds.NAME.equals(mockProp[0])) {
        when(object.getName()).thenReturn(mockProp[2].toString());
      }
    }
    when(object.getProperties()).thenReturn(documentProperties);

    return object;
  }
  /**
   * 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);

    // 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;
  }
예제 #3
0
 public boolean matches(T number) {
   return number.intValue() == 0 || number.intValue() == 1;
 }