@Test
  public void buildComponentsWithWrongRole() throws Exception {
    final XWikiRightService rightService = getMockery().mock(XWikiRightService.class);
    final BaseObject componentObject = getMockery().mock(BaseObject.class);

    getMockery()
        .checking(
            new Expectations() {
              {
                oneOf(componentDoc).getObject(COMPONENT_CLASS);
                will(returnValue(componentObject));
                oneOf(componentObject).getStringValue(COMPONENT_ROLE_TYPE_FIELD);
                will(returnValue("a.class.that.does.not.Exist"));
                oneOf(xwiki).getRightService();
                will(returnValue(rightService));
                oneOf(rightService).hasProgrammingRights(componentDoc, xwikiContext);
                will(returnValue(true));
              }
            });

    try {
      this.provider.buildComponents(DOC_REFERENCE);
      Assert.fail("Should have thrown an exception");
    } catch (WikiComponentException expected) {
      Assert.assertEquals(
          "The role class [a.class.that.does.not.Exist] could not be found", expected.getMessage());
    }
  }
  @Test
  public void buildComponentsWithoutProgrammingRights() throws Exception {
    final XWikiRightService rightService = getMockery().mock(XWikiRightService.class);

    getMockery()
        .checking(
            new Expectations() {
              {
                oneOf(componentDoc).getObject(COMPONENT_CLASS);
                will(returnValue(null));
                oneOf(xwiki).getRightService();
                will(returnValue(rightService));
                oneOf(rightService).hasProgrammingRights(componentDoc, xwikiContext);
                will(returnValue(false));
              }
            });

    try {
      this.provider.buildComponents(DOC_REFERENCE);
      Assert.fail("Should have thrown an exception");
    } catch (WikiComponentException expected) {
      Assert.assertEquals(
          "Registering wiki components requires programming rights", expected.getMessage());
    }
  }