<commit_before><commit_msg>add unit test for signal implementation<commit_after>package org.westmalle.wayland.core.events;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

@RunWith(MockitoJUnitRunner.class)
public class SignalTest {

    @InjectMocks
    private Signal<Object, Slot<Object>> signal;

    @Test
    public void testEmit() throws Exception {
        //given
        final Object       event = new Object();
        final Slot<Object> slot  = mock(Slot.class);
        this.signal.connect(slot);

        //when
        this.signal.emit(event);

        //then
        verify(slot).handle(event);
    }

    @Test
    public void testEmitUpdateSlot() throws Exception {
        //given
        final Object       event = new Object();
        final Slot<Object> slot  = mock(Slot.class);
        doAnswer(invocation -> {
            this.signal.disconnect(slot);
            return null;
        }).when(slot)
          .handle(event);
        this.signal.connect(slot);

        //when
        this.signal.emit(event);

        //then
        verify(slot).handle(event);

        //and when
        this.signal.emit(event);
        verifyNoMoreInteractions(slot);
    }
}
{'fraction_non_alphanumeric': 0.10882956878850103, 'fraction_numerical': 0.0, 'mean_word_length': 2.4892601431980905, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '6817885', 'n_tokens_mistral': 434, 'n_tokens_neox': 423, 'n_words': 88}