<commit_before>package com.celements.parents;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.xwiki.model.EntityType;
import org.xwiki.model.reference.DocumentReference;

import com.celements.common.test.AbstractBridgedComponentTestCase;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.web.Utils;

public class DocumentParentsListerTest extends AbstractBridgedComponentTestCase {

  private XWikiContext context;
  private XWiki xwiki;
  private DocumentParentsLister docParentsLister;
  private Map<String, IDocParentProviderRole> docParentProviderMapBackup;

  @Before
  public void setUp_WebUtilsServiceTest() throws Exception {
    context = getContext();
    xwiki = getWikiMock();
    docParentsLister = (DocumentParentsLister) Utils.getComponent(
        IDocumentParentsListerRole.class);
    docParentProviderMapBackup = docParentsLister.docParentProviderMap;
    docParentsLister.docParentProviderMap = new HashMap<String, IDocParentProviderRole>(
        docParentProviderMapBackup);
  }

  public void tearDown_DocumentParentsListerTest() {
    docParentsLister.docParentProviderMap = docParentProviderMapBackup;
  }

  @Test
  public void testGetDocumentParentsList_not_include() throws Exception {
    DocumentReference docRef = new DocumentReference(context.getDatabase(), "mySpace",
        "myDoc");
    DocumentReference parentRef1 = new DocumentReference(context.getDatabase(), "mySpace",
        "parent1");
    DocumentReference parentRef2 = new DocumentReference(context.getDatabase(), "mySpace",
        "parent2");
    XWikiDocument doc = new XWikiDocument(docRef);
    XWikiDocument docP1 = new XWikiDocument(parentRef1);
    XWikiDocument docP2 = new XWikiDocument(parentRef2);
    docP1.setParentReference(parentRef2.extractReference(EntityType.DOCUMENT));
    doc.setParentReference(parentRef1.extractReference(EntityType.DOCUMENT));
    expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(doc).once();
    expect(xwiki.getDocument(eq(parentRef1), same(context))).andReturn(docP1).once();
    expect(xwiki.exists(eq(parentRef1), same(context))).andReturn(true).anyTimes();
    expect(xwiki.getDocument(eq(parentRef2), same(context))).andReturn(docP2).once();
    expect(xwiki.exists(eq(parentRef2), same(context))).andReturn(true).anyTimes();
    List<DocumentReference> docParentsList = Arrays.asList(parentRef1, parentRef2);
    replayDefault();
    assertEquals(docParentsList, docParentsLister.getDocumentParentsList(docRef, false));
    verifyDefault();<commit_msg>add after annotation for tearDown method<commit_after>package com.celements.parents;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xwiki.model.EntityType;
import org.xwiki.model.reference.DocumentReference;

import com.celements.common.test.AbstractBridgedComponentTestCase;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.web.Utils;

public class DocumentParentsListerTest extends AbstractBridgedComponentTestCase {

  private XWikiContext context;
  private XWiki xwiki;
  private DocumentParentsLister docParentsLister;
  private Map<String, IDocParentProviderRole> docParentProviderMapBackup;

  @Before
  public void setUp_WebUtilsServiceTest() throws Exception {
    context = getContext();
    xwiki = getWikiMock();
    docParentsLister = (DocumentParentsLister) Utils.getComponent(
        IDocumentParentsListerRole.class);
    docParentProviderMapBackup = docParentsLister.docParentProviderMap;
    docParentsLister.docParentProviderMap = new HashMap<String, IDocParentProviderRole>(
        docParentProviderMapBackup);
  }

  @After
  public void tearDown_DocumentParentsListerTest() {
    docParentsLister.docParentProviderMap = docParentProviderMapBackup;
  }

  @Test
  public void testGetDocumentParentsList_not_include() throws Exception {
    DocumentReference docRef = new DocumentReference(context.getDatabase(), "mySpace",
        "myDoc");
    DocumentReference parentRef1 = new DocumentReference(context.getDatabase(), "mySpace",
        "parent1");
    DocumentReference parentRef2 = new DocumentReference(context.getDatabase(), "mySpace",
        "parent2");
    XWikiDocument doc = new XWikiDocument(docRef);
    XWikiDocument docP1 = new XWikiDocument(parentRef1);
    XWikiDocument docP2 = new XWikiDocument(parentRef2);
    docP1.setParentReference(parentRef2.extractReference(EntityType.DOCUMENT));
    doc.setParentReference(parentRef1.extractReference(EntityType.DOCUMENT));
    expect(xwiki.getDocument(eq(docRef), same(context))).andReturn(doc).once();
    expect(xwiki.getDocument(eq(parentRef1), same(context))).andReturn(docP1).once();
    expect(xwiki.exists(eq(parentRef1), same(context))).andReturn(true).anyTimes();
    expect(xwiki.getDocument(eq(parentRef2), same(context))).andReturn(docP2).once();
    expect(xwiki.exists(eq(parentRef2), same(context))).andReturn(true).anyTimes();
    List<DocumentReference> docParentsList = Arrays.asList(parentRef1, parentRef2);
    replayDefault();
    assertEquals(docParentsList, docParentsLister.getDocumentParentsList(docRef, false));
    verifyDefault();
{'fraction_non_alphanumeric': 0.10466760961810467, 'fraction_numerical': 0.006718528995756719, 'mean_word_length': 6.027329192546584, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3750883', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1698, 'n_words': 281}