@Test
  public void testRegisterWikiMacroWhenGlobalVisibilityAndAllowed() throws Exception {
    final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL);

    // Simulate a user with programming rights
    getMockery()
        .checking(
            new Expectations() {
              {
                allowing(mockDocumentAccessBridge).getCurrentWiki();
                will(returnValue("wiki"));
                allowing(mockDocumentAccessBridge).getCurrentUser();
                will(returnValue("dummy"));
                allowing(mockDocumentAccessBridge).setCurrentUser("dummy");
                allowing(mockWikiMacroFactory)
                    .isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL);
                will(returnValue(true));
              }
            });

    Assert.assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));

    wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
    Assert.assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));

    Macro<?> registeredMacro = macroManager.getMacro(new MacroId("testwikimacro"));
    Assert.assertEquals(0, registeredMacro.compareTo(wikiMacro));

    wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference());
    Assert.assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));

    Assert.assertFalse(macroManager.exists(new MacroId("testwikimacro")));
  }
  @org.junit.Test(expected = InsufficientPrivilegesException.class)
  public void testRegisterWikiMacroWhenGlobalVisibilityAndNotAllowed() throws Exception {
    final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL);

    // Simulate a user without programming rights
    getMockery()
        .checking(
            new Expectations() {
              {
                allowing(mockWikiMacroFactory)
                    .isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL);
                will(returnValue(false));
              }
            });

    wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
  }
  @org.junit.Test
  public void testRegisterWikiMacroWhenUserVisibilityAndNotAllowed() throws Exception {
    final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.USER);

    // Simulate a user without edit rights
    getMockery()
        .checking(
            new Expectations() {
              {
                allowing(mockWikiMacroFactory)
                    .isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.USER);
                will(returnValue(true));
                allowing(mockDocumentAccessBridge).getCurrentWiki();
                will(returnValue("wiki"));
                allowing(mockDocumentAccessBridge).getCurrentUser();
                will(returnValue("dummy"));
              }
            });

    wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
  }