<commit_before>package azkaban.trigger;

import java.util.HashMap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;

import azkaban.trigger.builtin.NyxTriggerChecker;
import azkaban.utils.NyxUtils;

/**
 * Test class for NyxTriggerChecker
 * 
 * @author gaggarwa
 *
 */
@RunWith(PowerMockRunner.class)
@PrepareForTest({ NyxUtils.class, NyxTriggerChecker.class })
public class NyxTriggerCheckerTest {
  private NyxTriggerChecker checker;
  private String dummySpec = "spec1";
  private long dummyTriggerId = 123L;

  @Before
  public void initObjects() throws Exception {
    PowerMockito.mockStatic(NyxUtils.class);
    PowerMockito.when(NyxUtils.registerNyxTrigger(dummySpec))
        .thenReturn(dummyTriggerId);
    PowerMockito.doNothing().when(NyxUtils.class, "unregisterNyxTrigger",
        dummyTriggerId);
    PowerMockito.when(NyxUtils.isNyxTriggerReady(dummyTriggerId))
        .thenReturn(true);

    checker = new NyxTriggerChecker(dummySpec, "NyxTriggerChecker_1");
  }

  @Test
  public void testDefaultTriggerRegister() throws TriggerManagerException {
    Assert.assertEquals("NyxTriggerChecker_1", checker.getId());
    Assert.assertEquals(123L, checker.getTriggerId());
    PowerMockito.verifyStatic();
    // verify register Trigger was called
    NyxUtils.registerNyxTrigger(dummySpec);
  }

  @Test
  public void testJSONserialization() throws Exception {
    @SuppressWarnings("unchecked")
    ConditionChecker retrievedChecker = NyxTriggerChecker
        .createFromJson((HashMap<String, Object>) checker.toJson());
    Assert.assertEquals(checker, retrievedChecker);
  }

  @Test
  public void testReset() throws TriggerManagerException {
    checker.reset();
    PowerMockito.verifyStatic();
    NyxUtils.unregisterNyxTrigger(dummyTriggerId);

    PowerMockito.verifyStatic(Mockito.times(2));
    NyxUtils.registerNyxTrigger(dummySpec);
  }

  @Test
  public void testStop() throws TriggerManagerException {
    checker.stopChecker();
    PowerMockito.verifyStatic();
    NyxUtils.unregisterNyxTrigger(dummyTriggerId);
  }

  @Test
  public void testType() {
    Assert.assertEquals(NyxTriggerChecker.type, checker.getType());
  }

  @Test
  public void testGetNum() {
    Assert.assertEquals(null, checker.getNum());
  }

  @Test
  public void testGetNextCheckTime() {
    Assert.assertEquals(Long.MAX_VALUE, checker.getNextCheckTime());
  }

  @Test
  public void testEval() {
    Assert.assertEquals(true, checker.eval());
  }
}
<commit_msg>fix unit tests.<commit_after>package azkaban.trigger;

import java.util.HashMap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;

import azkaban.trigger.builtin.NyxTriggerChecker;
import azkaban.utils.NyxUtils;

/**
 * Test class for NyxTriggerChecker
 *
 * @author gaggarwa
 *
 */
@RunWith(PowerMockRunner.class)
@PrepareForTest({ NyxUtils.class, NyxTriggerChecker.class })
public class NyxTriggerCheckerTest {
  private NyxTriggerChecker checker;
  private String dummySpec = "spec1";
  private long dummyTriggerId = 123L;

  @Before
  public void initObjects() throws Exception {
    PowerMockito.mockStatic(NyxUtils.class);
    PowerMockito.when(NyxUtils.registerNyxTrigger(dummySpec)).thenReturn(
        dummyTriggerId);
    PowerMockito.doNothing().when(NyxUtils.class, "unregisterNyxTrigger",
        dummyTriggerId);
    PowerMockito.when(NyxUtils.isNyxTriggerReady(dummyTriggerId)).thenReturn(
        true);

    checker = new NyxTriggerChecker(dummySpec, "NyxTriggerChecker_1");
  }

  @Test
  public void testDefaultTriggerRegister() throws TriggerManagerException {
    Assert.assertEquals("NyxTriggerChecker_1", checker.getId());
    Assert.assertEquals(-1, checker.getTriggerId());
  }

  @Test
  public void testJSONserialization() throws Exception {
    @SuppressWarnings("unchecked")
    ConditionChecker retrievedChecker =
        NyxTriggerChecker.createFromJson((HashMap<String, Object>) checker
            .toJson());
    Assert.assertEquals(checker, retrievedChecker);
  }

  @Test
  public void testReset() throws TriggerManagerException {
    checker.eval();
    checker.reset();
    PowerMockito.verifyStatic();
    NyxUtils.unregisterNyxTrigger(dummyTriggerId);

    PowerMockito.verifyStatic(Mockito.times(2));
    NyxUtils.registerNyxTrigger(dummySpec);
  }

  @Test
  public void testStop() throws TriggerManagerException {
    checker.eval();
    checker.stopChecker();
    PowerMockito.verifyStatic();
    NyxUtils.unregisterNyxTrigger(dummyTriggerId);
  }

  @Test
  public void testType() {
    Assert.assertEquals(NyxTriggerChecker.type, checker.getType());
  }

  @Test
  public void testGetNum() {
    Assert.assertEquals(null, checker.getNum());
  }

  @Test
  public void testGetNextCheckTime() {
    Assert.assertEquals(Long.MAX_VALUE, checker.getNextCheckTime());
  }

  @Test
  public void testEval() {
    Assert.assertEquals(true, checker.eval());
  }
}

{'fraction_non_alphanumeric': 0.106810569408262, 'fraction_numerical': 0.003721622627465575, 'mean_word_length': 4.754817987152034, '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': '1566619', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1661, 'n_words': 281}