<commit_before>package green.bunny

class QueueDeclareSpec extends IntegrationSpec {
  def "declaring a server-named queue with all defaults"() {
    when: "the queue is declared"
    def q = ch.queue()

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureServerNamed(q)
    !q.isAutoDelete
    !q.isDurable
    !q.isExclusive

    cleanup:
    q.delete()
  }

  def "declaring a server-named queue"(boolean durable, boolean exclusive, boolean autoDelete) {
    when: "the queue is declared"
    def q = ch.queue("", exclusive: exclusive, durable: durable, autoDelete: autoDelete)

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureServerNamed(q)
    q.isAutoDelete == autoDelete
    q.isDurable == durable
    q.isExclusive == exclusive

    cleanup:
    q.delete()

    where:
    durable | exclusive | autoDelete
    false   | false     | false
    true    | false     | false
    true    | true      | false
    true    | true      | true
    false   | false     | true
    false   | true      | true
    false   | true      | false
    true    | false     | true
  }

  def "declaring a client-named queue"(boolean durable, boolean exclusive, boolean autoDelete) {
    given: "a client-specified name"
    def s = UUID.randomUUID().toString()

    when: "the queue is declared"
    def q = ch.queue(s, exclusive: exclusive, durable: durable, autoDelete: autoDelete)

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureClientNamed(q)
    q.isAutoDelete == autoDelete
    q.isDurable == durable
    q.isExclusive == exclusive

    cleanup:
    q.delete()

    where:
    durable | exclusive | autoDelete
    false   | false     | false
    true    | false     | false
    true    | true      | false
    true    | true      | true
    false   | false     | true
    false   | true      | true
    false   | true      | false
    true    | false     | true
  }

  //
  // Matchers
  //

  void ensureServerNamed(Queue q) {
    assert q.name =~ /^amq\./
    assert q.isServerNamed
  }

  void ensureClientNamed(Queue q) {
    assert !(q.name =~ /^amq\./)
    assert !q.isServerNamed
  }

  void ensureDeclared(Channel ch, Queue q) {
    assert q.channel == ch
    assert ch.queueDeclarePassive(q.name)
  }
}<commit_msg>Cover Channel#queueDeclare<commit_after>package green.bunny

class QueueDeclareSpec extends IntegrationSpec {

  //
  // High-level API
  //

  def "declaring a server-named queue with all defaults"() {
    when: "the queue is declared"
    def q = ch.queue()

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureServerNamed(q)
    !q.isAutoDelete
    !q.isDurable
    !q.isExclusive

    cleanup:
    q.delete()
  }

  def "declaring a server-named queue"(boolean durable, boolean exclusive, boolean autoDelete) {
    when: "the queue is declared"
    def q = ch.queue("", exclusive: exclusive, durable: durable, autoDelete: autoDelete)

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureServerNamed(q)
    q.isAutoDelete == autoDelete
    q.isDurable == durable
    q.isExclusive == exclusive

    cleanup:
    q.delete()

    where:
    durable | exclusive | autoDelete
    false   | false     | false
    true    | false     | false
    true    | true      | false
    true    | true      | true
    false   | false     | true
    false   | true      | true
    false   | true      | false
    true    | false     | true
  }

  def "declaring a client-named queue"(boolean durable, boolean exclusive, boolean autoDelete) {
    given: "a client-specified name"
    def s = UUID.randomUUID().toString()

    when: "the queue is declared"
    def q = ch.queue(s, exclusive: exclusive, durable: durable, autoDelete: autoDelete)

    then: "the queue is declared and retains its attributes"
    ensureDeclared(ch, q)
    ensureClientNamed(q)
    q.isAutoDelete == autoDelete
    q.isDurable == durable
    q.isExclusive == exclusive

    cleanup:
    q.delete()

    where:
    durable | exclusive | autoDelete
    false   | false     | false
    true    | false     | false
    true    | true      | false
    true    | true      | true
    false   | false     | true
    false   | true      | true
    false   | true      | false
    true    | false     | true
  }


  //
  // Lower-level API
  //

  def "declaring a server-named queue with all defaults using lower-level API"() {
    when: "the queue is declared"
    def q = ch.queueDeclare()

    then: "the queue is declared and retains its attributes"
    ensureDeclared(q)
    ensureServerNamed(q)

    cleanup:
    ch.queueDelete(q)
  }

  //
  // Matchers
  //

  void ensureServerNamed(Queue q) {
    assert q.name =~ /^amq\./
    assert q.isServerNamed
  }

  void ensureServerNamed(String q) {
    assert q =~ /^amq\./
  }

  void ensureClientNamed(Queue q) {
    assert !(q.name =~ /^amq\./)
    assert !q.isServerNamed
  }

  void ensureDeclared(Channel ch, Queue q) {
    assert q.channel == ch
    assert ch.queueDeclarePassive(q.name)
  }

    void ensureDeclared(String q) {
    assert ch.queueDeclarePassive(q)
  }
}
{'fraction_non_alphanumeric': 0.09644766997708175, 'fraction_numerical': 0.0, 'mean_word_length': 2.299936988027725, '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': '4327415', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1604, 'n_words': 482}