<commit_before>package com.celements.navigation.service;

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

import org.junit.Before;
import org.junit.Test;
import org.xwiki.context.Execution;

import com.celements.common.test.AbstractBridgedComponentTestCase;
import com.celements.navigation.cmd.GetMappedMenuItemsForParentCommand;
import com.celements.navigation.cmd.GetNotMappedMenuItemsForParentCommand;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.store.XWikiStoreInterface;

public class TreeNodeCacheTest extends AbstractBridgedComponentTestCase {

  private XWikiContext context;
  private XWiki wiki;
  private XWikiStoreInterface mockStore;
  private TreeNodeCache treeNodeCache;

  @Before
  public void setUp_TreeNodeCacheTest() throws Exception {
    context = getContext();
    wiki = createMock(XWiki.class);
    context.setWiki(wiki);
    mockStore = createMock(XWikiStoreInterface.class);
    expect(wiki.getStore()).andReturn(mockStore).anyTimes();
    treeNodeCache = new TreeNodeCache();
    treeNodeCache.execution = getComponentManager().lookup(Execution.class);
  }

  @Test
  public void testGetMappedMenuItemsForParentCmd() {
    assertFalse(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }
  
  @Test
  public void testGetMappedMenuItemsForParentCmd_injected() {
    GetMappedMenuItemsForParentCommand testGetMenuItemCommand =
      new GetMappedMenuItemsForParentCommand();
    testGetMenuItemCommand.set_isActive(true);
    treeNodeCache.inject_GetMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    assertEquals(testGetMenuItemCommand, treeNodeCache.getMappedMenuItemsForParentCmd());
    assertTrue(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd() {
    assertNotNull(treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd_injected() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      new GetNotMappedMenuItemsForParentCommand();
    treeNodeCache.inject_GetNotMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    assertNotNull(treeNodeCache.getNotMappedMenuItemsForParentCmd());
    assertSame("Expecting injected cmd object", testGetMenuItemCommand,
        treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd_singleton() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      treeNodeCache.getNotMappedMenuItemsForParentCmd();
    assertNotNull(testGetMenuItemCommand);
    assertSame("Expecting injected cmd object", testGetMenuItemCommand,
        treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetMappedMenuItemsForParentCmd_injectedByContext() {
    GetMappedMenuItemsForParentCommand testGetMenuItemCommand = new GetMappedMenuItemsForParentCommand();
    testGetMenuItemCommand.set_isActive(true);
    context.put(GetMappedMenuItemsForParentCommand.CELEMENTS_MAPPED_MENU_ITEMS_KEY, 
        testGetMenuItemCommand);
    assertTrue(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
    
    testGetMenuItemCommand.set_isActive(false);
    context.put(GetMappedMenuItemsForParentCommand.CELEMENTS_MAPPED_MENU_ITEMS_KEY, 
        testGetMenuItemCommand);
    assertFalse(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }

  @Test
  public void testQueryCount() {
    fail("Not yet implemented");
  }

  @Test
  public void testFlushMenuItemCache() {
    fail("Not yet implemented");
  }

}<commit_msg>add missing tests for queryCount and flushMenuItemCache<commit_after>package com.celements.navigation.service;

import static org.easymock.EasyMock.*;

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

import org.junit.Before;
import org.junit.Test;
import org.xwiki.context.Execution;

import com.celements.common.test.AbstractBridgedComponentTestCase;
import com.celements.navigation.cmd.GetMappedMenuItemsForParentCommand;
import com.celements.navigation.cmd.GetNotMappedMenuItemsForParentCommand;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.store.XWikiStoreInterface;

public class TreeNodeCacheTest extends AbstractBridgedComponentTestCase {

  private XWikiContext context;
  private XWiki wiki;
  private XWikiStoreInterface mockStore;
  private TreeNodeCache treeNodeCache;

  @Before
  public void setUp_TreeNodeCacheTest() throws Exception {
    context = getContext();
    wiki = createMock(XWiki.class);
    context.setWiki(wiki);
    mockStore = createMock(XWikiStoreInterface.class);
    expect(wiki.getStore()).andReturn(mockStore).anyTimes();
    treeNodeCache = new TreeNodeCache();
    treeNodeCache.execution = getComponentManager().lookup(Execution.class);
  }

  @Test
  public void testGetMappedMenuItemsForParentCmd() {
    assertFalse(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }
  
  @Test
  public void testGetMappedMenuItemsForParentCmd_injected() {
    GetMappedMenuItemsForParentCommand testGetMenuItemCommand =
      new GetMappedMenuItemsForParentCommand();
    testGetMenuItemCommand.set_isActive(true);
    treeNodeCache.inject_GetMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    assertEquals(testGetMenuItemCommand, treeNodeCache.getMappedMenuItemsForParentCmd());
    assertTrue(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd() {
    assertNotNull(treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd_injected() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      new GetNotMappedMenuItemsForParentCommand();
    treeNodeCache.inject_GetNotMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    assertNotNull(treeNodeCache.getNotMappedMenuItemsForParentCmd());
    assertSame("Expecting injected cmd object", testGetMenuItemCommand,
        treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetNotMappedMenuItemsForParentCmd_singleton() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      treeNodeCache.getNotMappedMenuItemsForParentCmd();
    assertNotNull(testGetMenuItemCommand);
    assertSame("Expecting injected cmd object", testGetMenuItemCommand,
        treeNodeCache.getNotMappedMenuItemsForParentCmd());
  }
  
  @Test
  public void testGetMappedMenuItemsForParentCmd_injectedByContext() {
    GetMappedMenuItemsForParentCommand testGetMenuItemCommand = new GetMappedMenuItemsForParentCommand();
    testGetMenuItemCommand.set_isActive(true);
    context.put(GetMappedMenuItemsForParentCommand.CELEMENTS_MAPPED_MENU_ITEMS_KEY, 
        testGetMenuItemCommand);
    assertTrue(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
    
    testGetMenuItemCommand.set_isActive(false);
    context.put(GetMappedMenuItemsForParentCommand.CELEMENTS_MAPPED_MENU_ITEMS_KEY, 
        testGetMenuItemCommand);
    assertFalse(treeNodeCache.getMappedMenuItemsForParentCmd().is_isActive());
  }

  @Test
  public void testQueryCount() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      createMock(GetNotMappedMenuItemsForParentCommand.class);
    treeNodeCache.inject_GetNotMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    expect(testGetMenuItemCommand.queryCount()).andReturn(15);
    replayAll(testGetMenuItemCommand);
    assertEquals(15, treeNodeCache.queryCount());
    verifyAll(testGetMenuItemCommand);
  }

  @Test
  public void testFlushMenuItemCache() {
    GetNotMappedMenuItemsForParentCommand testGetMenuItemCommand =
      createMock(GetNotMappedMenuItemsForParentCommand.class);
    treeNodeCache.inject_GetNotMappedMenuItemsForParentCmd(testGetMenuItemCommand);
    testGetMenuItemCommand.flushMenuItemCache(same(context));
    expectLastCall().once();
    replayAll(testGetMenuItemCommand);
    treeNodeCache.flushMenuItemCache();
    verifyAll(testGetMenuItemCommand);
  }


  private void replayAll(Object ... mocks) {
    replay(mockStore, wiki);
    replay(mocks);
  }

  private void verifyAll(Object ... mocks) {
    verify(mockStore, wiki);
    verify(mocks);
  }
}
{'fraction_non_alphanumeric': 0.07875809158475186, 'fraction_numerical': 0.0004795013186286262, 'mean_word_length': 6.192241379310345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '17390', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2403, 'n_words': 325}