View Javadoc

1   package com.atlassian.vcache.internal.core;
2   
3   import com.atlassian.vcache.internal.RequestContext;
4   
5   import org.junit.Rule;
6   import org.junit.Test;
7   import org.junit.rules.ExpectedException;
8   
9   import static org.hamcrest.Matchers.is;
10  import static org.junit.Assert.assertThat;
11  
12  public class DefaultRequestContextTest
13  {
14      @Rule
15      public ExpectedException thrown = ExpectedException.none();
16  
17      @Test
18      public void partitionIdentifier() throws Exception
19      {
20          final RequestContext rc = new DefaultRequestContext("tenant");
21  
22          assertThat(rc.partitionIdentifier(), is("tenant"));
23      }
24  
25      @Test
26      public void computeIfAbsent_normal() throws Exception
27      {
28          final RequestContext rc = new DefaultRequestContext("ignored");
29          final String missing = rc.computeIfAbsent("missing", () -> "generated");
30  
31          assertThat(missing, is("generated"));
32  
33          final String exists = rc.computeIfAbsent("missing", () -> "wtf");
34  
35          assertThat(exists, is("generated"));
36      }
37  
38      @Test
39      public void computeIfAbsent_cast_error() throws Exception
40      {
41          final RequestContext rc = new DefaultRequestContext("ignored");
42          rc.computeIfAbsent("key", () -> "value");
43  
44          thrown.expect(ClassCastException.class);
45  
46          final Integer i = rc.computeIfAbsent("key", () -> 42);
47      }
48  }