View Javadoc

1   package com.atlassian.vcache.internal.memcached;
2   
3   import org.junit.Test;
4   
5   import static com.atlassian.vcache.internal.memcached.MemcachedUtils.expiryTime;
6   import static org.hamcrest.Matchers.greaterThan;
7   import static org.hamcrest.Matchers.is;
8   import static org.hamcrest.Matchers.lessThanOrEqualTo;
9   import static org.junit.Assert.assertThat;
10  
11  public class MemcachedUtilsTest {
12  
13      @Test
14      public void expiryTime_under() throws Exception {
15          assertThat(expiryTime(6), is(6));
16      }
17  
18      @Test
19      public void expiryTime_over() throws Exception {
20          final int ttl = 30 * 24 * 60 * 60;
21          final int expiry = expiryTime(ttl);
22          final int nowSecs = (int) (System.currentTimeMillis() / 1_000);
23  
24          assertThat(expiry, greaterThan(ttl));
25          assertThat(expiry, greaterThan(nowSecs));
26          assertThat(expiry, lessThanOrEqualTo(nowSecs + ttl));
27      }
28  }