<commit_before>package de.gurkenlabs.litiengine.environment;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Test;

import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.entities.IEntity;
import de.gurkenlabs.litiengine.entities.Trigger;
import de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation;
import junit.framework.Assert;

public class TriggerTests {
  @Test
  public void testInteractTrigger() {
    Trigger trigger = new Trigger(TriggerActivation.INTERACT, "testrigger", "testmessage");
    IEntity entity = mock(IEntity.class);
    when(entity.getMapId()).thenReturn(123);

    IEntity target = mock(IEntity.class);
    when(target.getMapId()).thenReturn(456);
    when(target.sendMessage(any(Object.class), any(String.class))).thenReturn("answer");
    trigger.addTarget(456);

    IEnvironment env = mock(IEnvironment.class);
    Game.loadEnvironment(env);
    when(env.get(456)).thenReturn(target);

    Assert.assertFalse(trigger.isActivated());

    trigger.sendMessage(entity, Trigger.INTERACT_MESSAGE);<commit_msg>Since triggers now depend on the game loop we need to initialize the game for the related unittests.<commit_after>package de.gurkenlabs.litiengine.environment;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Test;

import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.entities.IEntity;
import de.gurkenlabs.litiengine.entities.Trigger;
import de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation;
import junit.framework.Assert;

public class TriggerTests {
  @Test
  public void testInteractTrigger() {
    Trigger trigger = new Trigger(TriggerActivation.INTERACT, "testrigger", "testmessage");
    IEntity entity = mock(IEntity.class);
    when(entity.getMapId()).thenReturn(123);

    IEntity target = mock(IEntity.class);
    when(target.getMapId()).thenReturn(456);
    when(target.sendMessage(any(Object.class), any(String.class))).thenReturn("answer");
    trigger.addTarget(456);

    IEnvironment env = mock(IEnvironment.class);
    Game.loadEnvironment(env);
    Game.init();
    when(env.get(456)).thenReturn(target);

    Assert.assertFalse(trigger.isActivated());

    trigger.sendMessage(entity, Trigger.INTERACT_MESSAGE);
{'fraction_non_alphanumeric': 0.1183087664856478, 'fraction_numerical': 0.009309542280837859, 'mean_word_length': 5.56234096692112, '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': '4625564', 'n_tokens_mistral': 833, 'n_tokens_neox': 809, 'n_words': 139}