aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/logging/CircularArrayAccessLogKeeperTest.java
blob: 01bbe0d009c83742dae7be332c5e9aeff36a77e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.logging;

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsIterableContaining.hasItem;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.MatcherAssert.assertThat;

public class CircularArrayAccessLogKeeperTest {
    private CircularArrayAccessLogKeeper circularArrayAccessLogKeeper = new CircularArrayAccessLogKeeper();

    @Test
    void testSizeIsCroppedCorrectly() {
        for (int i = 0; i < CircularArrayAccessLogKeeper.SIZE - 1; i++) {
            circularArrayAccessLogKeeper.addUri(String.valueOf(i));
        }
        assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE - 1));
        circularArrayAccessLogKeeper.addUri("foo");
        assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE));
        circularArrayAccessLogKeeper.addUri("bar");
        assertThat(circularArrayAccessLogKeeper.getUris().size(), is(CircularArrayAccessLogKeeper.SIZE));
        assertThat(circularArrayAccessLogKeeper.getUris(), hasItems("1", "2", "3", "foo", "bar"));
        assertThat(circularArrayAccessLogKeeper.getUris(), not(hasItem("0")));
    }

    @Test
    void testEmpty() {
        assertThat(circularArrayAccessLogKeeper.getUris().size(), is(0));
    }

    @Test
    void testSomeItems() {
        circularArrayAccessLogKeeper.addUri("a");
        circularArrayAccessLogKeeper.addUri("b");
        circularArrayAccessLogKeeper.addUri("b");
        assertThat(circularArrayAccessLogKeeper.getUris(), contains("a", "b", "b"));
    }
}