|
| 1 | +package io.sentry |
| 2 | +import org.junit.Assert.assertThrows |
| 3 | +import java.util.NoSuchElementException |
| 4 | +import kotlin.test.Test |
| 5 | +import kotlin.test.assertEquals |
| 6 | +import kotlin.test.assertFalse |
| 7 | +import kotlin.test.assertNull |
| 8 | + |
| 9 | +class DisabledQueueTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + fun `size starts empty`() { |
| 13 | + val queue = DisabledQueue<Int>() |
| 14 | + assertEquals(0, queue.size, "Size should always be zero.") |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + fun `add does not add elements`() { |
| 19 | + val queue = DisabledQueue<Int>() |
| 20 | + assertFalse(queue.add(1), "add should always return false.") |
| 21 | + assertEquals(0, queue.size, "Size should still be zero after attempting to add an element.") |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + fun `isEmpty returns false when created`() { |
| 26 | + val queue = DisabledQueue<Int>() |
| 27 | + assertFalse(queue.isEmpty(), "isEmpty should always return false.") |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + fun `isEmpty always returns false if add function was called`() { |
| 32 | + val queue = DisabledQueue<Int>() |
| 33 | + queue.add(1) |
| 34 | + |
| 35 | + assertFalse(queue.isEmpty(), "isEmpty should always return false.") |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + fun `offer does not add elements`() { |
| 40 | + val queue = DisabledQueue<Int>() |
| 41 | + assertFalse(queue.offer(1), "offer should always return false.") |
| 42 | + assertEquals(0, queue.size, "Size should still be zero after attempting to offer an element.") |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + fun `poll returns null`() { |
| 47 | + val queue = DisabledQueue<Int>() |
| 48 | + queue.add(1) |
| 49 | + assertNull(queue.poll(), "poll should always return null.") |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun `peek returns null`() { |
| 54 | + val queue = DisabledQueue<Int>() |
| 55 | + queue.add(1) |
| 56 | + |
| 57 | + assertNull(queue.peek(), "peek should always return null.") |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + fun `element returns null`() { |
| 62 | + val queue = DisabledQueue<Int>() |
| 63 | + assertNull(queue.element(), "element should always return null.") |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + fun `remove throws NoSuchElementException`() { |
| 68 | + val queue = DisabledQueue<Int>() |
| 69 | + assertThrows(NoSuchElementException::class.java) { queue.remove() } |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + fun `clear does nothing`() { |
| 74 | + val queue = DisabledQueue<Int>() |
| 75 | + queue.clear() // Should not throw an exception |
| 76 | + assertEquals(0, queue.size, "Size should remain zero after clear.") |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + fun `iterator has no elements`() { |
| 81 | + val queue = DisabledQueue<Int>() |
| 82 | + val iterator = queue.iterator() |
| 83 | + assertFalse(iterator.hasNext(), "Iterator should have no elements.") |
| 84 | + assertThrows(NoSuchElementException::class.java) { iterator.next() } |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + fun `iterator remove throws IllegalStateException`() { |
| 89 | + val queue = DisabledQueue<Int>() |
| 90 | + val iterator = queue.iterator() |
| 91 | + assertThrows(IllegalStateException::class.java) { iterator.remove() } |
| 92 | + } |
| 93 | +} |
0 commit comments