package com.nytimes.android.external.store3.base.impl;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

public class MemoryPolicyBuilderTest {

    @Test
    public void testBuildExpireAfterWriteMemoryPolicy() {
        MemoryPolicy policy = MemoryPolicy.builder()
                .setExpireAfterWrite(4L)
                .build();

        assertThat(policy.getExpireAfterWrite()).isEqualTo(4L);
        assertThat(policy.getExpireAfterTimeUnit()).isEqualTo(TimeUnit.SECONDS);
        assertThat(policy.isDefaultWritePolicy()).isFalse();
        assertThat(policy.getExpireAfterAccess()).isEqualTo(MemoryPolicy.DEFAULT_POLICY);
    }

    @Test
    public void testBuildExpireAfterAccessMemoryPolicy() {
        MemoryPolicy policy = MemoryPolicy.builder()
                .setExpireAfterAccess(4L)
                .build();

        assertThat(policy.getExpireAfterAccess()).isEqualTo(4L);
        assertThat(policy.getExpireAfterTimeUnit()).isEqualTo(TimeUnit.SECONDS);
        assertThat(policy.isDefaultWritePolicy()).isTrue();
        assertThat(policy.getExpireAfterWrite()).isEqualTo(MemoryPolicy.DEFAULT_POLICY);
    }

    @Test(expected = IllegalStateException.class)
    public void testCannotSetBothExpirationPolicies() {
        MemoryPolicy.builder()
                .setExpireAfterAccess(4L)
                .setExpireAfterWrite(4L)
                .build();
    }

    @Test
    public void testBuilderSetsExpireAfterTimeUnit() {
        MemoryPolicy policy = MemoryPolicy.builder()
                .setExpireAfterTimeUnit(TimeUnit.MINUTES)
                .build();

        assertThat(policy.getExpireAfterTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    }

    @Test
    public void testBuilderSetsMemorySize() {
        MemoryPolicy policy = MemoryPolicy.builder()
                .setMemorySize(10L)
                .build();

        assertThat(policy.getMaxSize()).isEqualTo(10L);
    }
}

@@ -1973,11 +1973,209 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDefaultMemorySizeIfNotSet() %7B%0A        MemoryPolicy policy = MemoryPolicy.builder()%0A            .build();%0A%0A        assertThat(policy.getMaxSize()).isEqualTo(1L);%0A    %7D
 %0A%7D%0A

Add test for MemoryPolicy default size