示例#1
0
 @Test(expected = AuthorizationException.class)
 public void setNoPermissions() {
   // given
   when(subject.isPermitted(any(OptionPermission.class))).thenReturn(false);
   when(defaultHierarchy.rankName(0)).thenReturn("specific");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, SPECIFIC_RANK, 0, optionKey1);
   // when
   option.set(5, optionKey1);
   // then
 }
示例#2
0
 @Test
 public void set_simplest() {
   // given
   when(subject.isPermitted(any(OptionPermission.class))).thenReturn(true);
   when(defaultHierarchy.rankName(0)).thenReturn("specific");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, SPECIFIC_RANK, 0, optionKey1);
   // when
   option.set(5, optionKey1);
   // then
   verify(optionCache).write(cacheKey, Optional.of(5));
 }
示例#3
0
 @Test(expected = AuthorizationException.class)
 public void delete_no_permissions() {
   // given
   when(subject.isPermitted(any(OptionPermission.class))).thenReturn(false);
   when(defaultHierarchy.rankName(1)).thenReturn("specific");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, SPECIFIC_RANK, 1, optionKey2);
   when(optionCache.delete(cacheKey)).thenAnswer(answerOf(3));
   // when
   Object actual = option.delete(1, optionKey2);
   // then
 }
示例#4
0
 @Test
 public void get_lowest() {
   // given
   when(defaultHierarchy.lowestRankName()).thenReturn("low");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, LOWEST_RANK, optionKey2);
   when(optionCache.get(Optional.of(5), cacheKey)).thenAnswer(answerOf(20));
   // when
   Integer actual = option.getLowestRanked(optionKey2);
   // then
   assertThat(actual).isEqualTo(20);
 }
示例#5
0
 @Test
 public void get_none_found() {
   // given
   when(defaultHierarchy.highestRankName()).thenReturn("high");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, HIGHEST_RANK, optionKey2);
   when(optionCache.get(Optional.of(5), cacheKey)).thenReturn(Optional.empty());
   // when
   Integer actual = option.get(optionKey2);
   // then
   assertThat(actual).isEqualTo(5);
 }
示例#6
0
 @Test(expected = IllegalArgumentException.class)
 public void set_with_all_args_rank_too_low() {
   // given
   when(subject.isPermitted(any(OptionPermission.class))).thenReturn(true);
   when(defaultHierarchy.rankName(2)).thenReturn("specific");
   OptionKey<Integer> optionKey2 =
       new OptionKey<>(999, context, TestLabelKey.key1, TestLabelKey.key1, "q");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, SPECIFIC_RANK, 2, optionKey2);
   // when
   option.set(5, -1, optionKey2);
   // then
 }
示例#7
0
 @Test
 public void delete() {
   // given
   when(subject.isPermitted(any(OptionPermission.class))).thenReturn(true);
   when(defaultHierarchy.rankName(1)).thenReturn("specific");
   OptionCacheKey cacheKey = new OptionCacheKey(defaultHierarchy, SPECIFIC_RANK, 1, optionKey2);
   when(optionCache.delete(cacheKey)).thenAnswer(answerOf(3));
   // when
   Object actual = option.delete(1, optionKey2);
   // then
   assertThat(actual).isEqualTo(Optional.of(3));
   verify(optionCache).delete(cacheKey);
 }