<commit_before>package de.frosner.broccoli.signal

import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import sun.misc.{Signal, SignalHandler}

class UnixSignalManagerSpec extends Specification with Mockito {
  "Registering new signal" should {
    "trigger the handler when the signal is raised" in {
      val manager = new UnixSignalManager()
      val signal = new Signal("USR2")
      val handler = mock[SignalHandler]
      manager.register(signal, handler)
      Signal.raise(signal)
      Thread.sleep(1000)
      there was one(handler).handle(signal)
    }

    "fail if the signal is reserved by the JVM" in {
      val manager = new UnixSignalManager()
      manager.register(new Signal("USR1"), mock[SignalHandler]) must throwA(
        new IllegalArgumentException("Signal already used by VM or OS: SIGUSR1"))
    }

    "fail if the signal is already registered" in {
      val manager = new UnixSignalManager()
      val signal = new Signal("USR2")
      val handler = mock[SignalHandler]
      manager.register(signal, handler)
      manager.register(signal, handler) must throwA(
        new IllegalArgumentException(s"Signal $signal is already registered"))

    }
  }

  "Unregistering a signal" should {
    "fail if the signal was not registered" in {
      val manager = new UnixSignalManager()
      val signal = new Signal("USR1")
      manager.unregister(signal) must throwA(new IllegalArgumentException(s"Signal $signal is not registered"))
    }
  }
}
<commit_msg>Explicitly test signal registration with distinct signal objects<commit_after>package de.frosner.broccoli.signal

import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import sun.misc.{Signal, SignalHandler}

class UnixSignalManagerSpec extends Specification with Mockito {
  "Registering new signal" should {
    "trigger the handler when the signal is raised" in {
      val manager = new UnixSignalManager()
      val signal = new Signal("USR2")
      val handler = mock[SignalHandler]
      manager.register(signal, handler)
      Signal.raise(signal)
      Thread.sleep(1000)
      there was one(handler).handle(signal)
    }

    "fail if the signal is reserved by the JVM" in {
      val manager = new UnixSignalManager()
      manager.register(new Signal("USR1"), mock[SignalHandler]) must throwA(
        new IllegalArgumentException("Signal already used by VM or OS: SIGUSR1"))
    }

    "fail if the signal is already registered" in {
      val manager = new UnixSignalManager()
      val handler = mock[SignalHandler]
      manager.register(new Signal("USR2"), handler)
      manager.register(new Signal("USR2"), handler) must throwA(
        new IllegalArgumentException(s"Signal ${new Signal("USR2")} is already registered"))

    }
  }

  "Unregistering a signal" should {
    "fail if the signal was not registered" in {
      val manager = new UnixSignalManager()
      val signal = new Signal("USR1")
      manager.unregister(signal) must throwA(new IllegalArgumentException(s"Signal $signal is not registered"))
    }
  }
}

{'fraction_non_alphanumeric': 0.08954737870400521, 'fraction_numerical': 0.007815043959622273, 'mean_word_length': 3.5309734513274336, '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': '5834244', 'n_tokens_mistral': 871, 'n_tokens_neox': 832, 'n_words': 272}