<commit_before>package org.pentaho.ui.xul.test;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.XulLoader;
import org.pentaho.ui.xul.components.XulTextbox;
import org.pentaho.ui.xul.impl.XulEventHandler;
import org.pentaho.ui.xul.swing.SwingXulLoader;
import org.pentaho.ui.xul.test.samples.SampleEventHandler;
import org.pentaho.ui.xul.test.samples.TreeHandler;

import static org.junit.Assert.*;

public class XulDomContainerTest {
  
  @Test
  public void testOnLoad() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    XulTextbox testComponent = (XulTextbox) container.getDocumentRoot().getElementById("textbox1");
    assertEquals("initial value", testComponent.getValue());
    container.initialize();
    assertEquals("new value", testComponent.getValue());
  }
  
  @Test
  public void testGetHandlers() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    Map<String, XulEventHandler> handlers  = container.getEventHandlers();
    assertTrue(handlers.size() == 3);
    assertNotNull(handlers.get("handler1"));
    assertNotNull(handlers.get("handler2"));
    assertNotNull(handlers.get("handler5"));
  }
  
  @Test
  public void testGetHandler() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    assertNotNull(container.getEventHandler("handler1"));
    assertNotNull(container.getEventHandler("handler2"));
  }
  
  @Test
  public void testEventHandlerParams() throws Exception{
    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    container.initialize();
    SampleEventHandler handler = (SampleEventHandler) container.getEventHandler("handler2");
    assertEquals(5, handler.testNumber);
    assertEquals(5.2, handler.testDouble, .01);
    assertEquals("hello", handler.testString);
    assertTrue(handler.testBool);
  }
  
  @Test
  public void testMergeContainers() throws Exception{
    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    XulDomContainer container2 = container.loadFragment("resource/documents/testEventHandlers2.xul");
    container.mergeContainer(container2);
    assertNotNull(container.getEventHandler("handler3"));
    
  }
  
  @Test
  public void testIsRegistered() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    assertTrue(container.isRegistered("BUTTON"));
    assertFalse(container.isRegistered("BOGUSjhjhh"));
  }
  
  @Test
  public void testRegisterHandler() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    TreeHandler handler = new TreeHandler();
    handler.setName("handler1");
    container.addEventHandler(handler);
    TreeHandler outHandler = (TreeHandler) container.getEventHandler("handler1");
    assertNotNull(outHandler);
    assertSame(handler, outHandler);
  }

  @Test
  public void testBindings() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    //container.createBinding(source, sourceAttr, targetId, targetAttr)
  }

}

  <commit_msg>Unit tests and minor refactorings<commit_after>package org.pentaho.ui.xul.test;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.XulLoader;
import org.pentaho.ui.xul.components.XulTextbox;
import org.pentaho.ui.xul.impl.XulEventHandler;
import org.pentaho.ui.xul.swing.SwingXulLoader;
import org.pentaho.ui.xul.test.samples.SampleEventHandler;
import org.pentaho.ui.xul.test.samples.TreeHandler;

import static org.junit.Assert.*;

public class XulDomContainerTest {
  
  @Test
  public void testOnLoad() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    XulTextbox testComponent = (XulTextbox) container.getDocumentRoot().getElementById("textbox1");
    assertEquals("initial value", testComponent.getValue());
    container.initialize();
    assertEquals("new value", testComponent.getValue());
  }
  
  @Test
  public void testGetHandlers() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    Map<String, XulEventHandler> handlers  = container.getEventHandlers();
    assertTrue(handlers.size() == 3);
    assertNotNull(handlers.get("handler1"));
    assertNotNull(handlers.get("handler2"));
    assertNotNull(handlers.get("handler5"));
  }
  
  @Test
  public void testGetHandler() throws Exception{

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    assertNotNull(container.getEventHandler("handler1"));
    assertNotNull(container.getEventHandler("handler2"));
  }
  
  @Test
  public void testEventHandlerParams() throws Exception{
    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    container.initialize();
    SampleEventHandler handler = (SampleEventHandler) container.getEventHandler("handler2");
    assertEquals(5, handler.testNumber);
    assertEquals(5.2, handler.testDouble, .01);
    assertEquals("hello", handler.testString);
    assertTrue(handler.testBool);
  }
  
  @Test
  public void testMergeContainers() throws Exception{
    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    XulDomContainer container2 = container.loadFragment("resource/documents/testEventHandlers2.xul");
    container.mergeContainer(container2);
    assertNotNull(container.getEventHandler("handler3"));
    
  }
  
  @Test
  public void testIsRegistered() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    assertTrue(container.isRegistered("BUTTON"));
  }
  
  @Test
  public void testRegisterHandler() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    TreeHandler handler = new TreeHandler();
    handler.setName("handler1");
    container.addEventHandler(handler);
    TreeHandler outHandler = (TreeHandler) container.getEventHandler("handler1");
    assertNotNull(outHandler);
    assertSame(handler, outHandler);
  }

  @Test
  public void testBindings() throws Exception {

    XulLoader loader = new SwingXulLoader();
    XulDomContainer container = loader.loadXul("resource/documents/testEventHandlers.xul");
    //container.createBinding(source, sourceAttr, targetId, targetAttr)
  }

}

  
{'fraction_non_alphanumeric': 0.10936310581070795, 'fraction_numerical': 0.00482111139304745, 'mean_word_length': 4.3552989130434785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5040142', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2274, 'n_words': 401}