@Test public void testUpdateDataUsage() throws PersistenceException { ArgumentCaptor<String> keyArg1 = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> keyArg2 = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> cqlArg = ArgumentCaptor.forClass(String.class); ArgumentCaptor<PersistentItem> itemArg = ArgumentCaptor.forClass(PersistentItem.class); attributesList = new ArrayList<>(); Map<String, Object> attributes = new HashMap<>(); attributes.put(DATA_USAGE_LONG, LONG_1); attributes.put(DATA_LIMIT_LONG, LONG_1); attributesList.add(attributes); when(persistentStore.get(anyString(), anyString())).thenReturn(attributesList); attributesStore.updateUserDataUsage(USER, LONG_5); verify(persistentStore, atLeast(2)).get(keyArg1.capture(), cqlArg.capture()); verify(persistentStore).add(keyArg2.capture(), itemArg.capture()); assertThat(keyArg1.getValue(), is(PersistentStore.USER_ATTRIBUTE_TYPE)); assertThat(keyArg2.getValue(), is(PersistentStore.USER_ATTRIBUTE_TYPE)); assertThat(itemArg.getValue().getLongProperty(AttributesStore.DATA_USAGE_KEY), is(600L)); assertThat(cqlArg.getValue(), is(CQL)); }
@Test public void testUpdateDataUsageSizeLessThanZero() throws PersistenceException { long dataUsage = -1L; attributesStore.updateUserDataUsage(USER, dataUsage); verify(persistentStore, never()).add(anyString(), anyMap()); }
@Test(expected = PersistenceException.class) public void testPersistenceStoreThrowsExceptionOnGet() throws PersistenceException { when(persistentStore.get(anyString(), anyString())).thenThrow(new PersistenceException()); attributesStore.updateUserDataUsage(USER, LONG_5); }
@Test(expected = PersistenceException.class) public void testUpdateDataUsageNullUsername() throws PersistenceException { attributesStore.updateUserDataUsage(null, LONG_5); }