### Question:
InstalledExtensionDocumentListener extends AbstractEventListener { @SuppressWarnings("unchecked") @Override public void onEvent(Event event, Object source, Object data) { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (this.tree.isExtensionPage(document.getDocumentReference())) { updateCustomizedFlag(document.getDocumentReferenceWithLocale()); } } else if (event instanceof ApplicationReadyEvent) { addExtensionDocuments(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()); } else if (event instanceof WikiReadyEvent) { addExtensionDocuments((String) source); } else if (event instanceof XarExtensionInstalledEvent) { addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUninstalledEvent) { removeExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } else if (event instanceof XarExtensionUpgradedEvent) { ((Collection<InstalledExtension>) data).stream().forEach( oldInstalledExtension -> removeExtensionDocuments((ExtensionEvent) event, oldInstalledExtension)); addExtensionDocuments((ExtensionEvent) event, (InstalledExtension) source); } } InstalledExtensionDocumentListener(); @SuppressWarnings("unchecked") @Override void onEvent(Event event, Object source, Object data); static final String HINT; }### Answer:
@Test public void onDocumentUpdated() { DocumentReference alice = new DocumentReference("wiki", "Users", "Alice"); DocumentReference aliceFR = new DocumentReference(alice, Locale.FRENCH); XWikiDocument document = mock(XWikiDocument.class); when(document.getDocumentReference()).thenReturn(alice); when(document.getDocumentReferenceWithLocale()).thenReturn(aliceFR); this.listener.onEvent(new DocumentUpdatedEvent(), document, null); verify(this.tree, never()).setCustomizedExtensionPage(eq(alice), any(Boolean.class)); when(this.tree.isExtensionPage(alice)).thenReturn(true); this.listener.onEvent(new DocumentUpdatedEvent(), document, null); verify(this.tree).setCustomizedExtensionPage(aliceFR, false); when(this.customizationDetectorProvider.get().isCustomized(aliceFR)).thenReturn(true); this.listener.onEvent(new DocumentUpdatedEvent(), document, null); verify(this.tree).setCustomizedExtensionPage(aliceFR, true); }
@Test public void onApplicationReady() throws Exception { when(this.wikiDescriptorManagerProvider.get().getCurrentWikiId()).thenReturn("test"); XarInstalledExtension xarInstalledExtension = mock(XarInstalledExtension.class); when(this.xarRepositoryProvider.get().getInstalledExtensions("wiki:test")) .thenReturn(Collections.singleton(xarInstalledExtension)); XarPackage xarPackage = mock(XarPackage.class); when(xarInstalledExtension.getXarPackage()).thenReturn(xarPackage); XarEntry xarEntry = mock(XarEntry.class); when(xarPackage.getEntries()).thenReturn(Collections.singleton(xarEntry)); DocumentReference documentReference = new DocumentReference("test", "Some", "Page"); DocumentReference documentReferenceWithLocale = new DocumentReference(documentReference, Locale.FRENCH); when(this.packagerProvider.get().getDocumentReferences(eq(Collections.singleton(xarEntry)), any(PackageConfiguration.class))).thenReturn(Collections.singletonList(documentReferenceWithLocale)); when(this.customizationDetectorProvider.get().isCustomized(documentReferenceWithLocale)).thenReturn(true); this.listener.onEvent(new ApplicationReadyEvent(), null, null); verify(this.tree).addExtensionPage(documentReference); verify(this.tree).setCustomizedExtensionPage(documentReferenceWithLocale, true); }