@Test public void putIfAbsent() { User stewieGriffon = newUser("stewieGriffon"); assertThat(users.containsValue(stewieGriffon)).isFalse(); assertThat(usersTemplate.putIfAbsent(getKey(stewieGriffon), stewieGriffon)).isNull(); assertThat(users.containsValue(stewieGriffon)).isTrue(); assertThat(usersTemplate.putIfAbsent(getKey(stewieGriffon), newUser("megGriffon"))) .isEqualTo(stewieGriffon); assertThat(users.get(getKey(stewieGriffon))).isEqualTo(stewieGriffon); }
@Test public void replaceOldValueWithNewValue() { User jackHandy = getUser("jackHandy"); User imaPigg = getUser("imaPigg"); assertThat(users.containsValue(jackHandy)).isTrue(); assertThat(usersTemplate.replace(getKey(jackHandy), null, imaPigg)).isFalse(); assertThat(users.containsValue(jackHandy)).isTrue(); assertThat(users.get(getKey(jackHandy))).isEqualTo(jackHandy); assertThat(usersTemplate.replace(getKey(jackHandy), jackHandy, imaPigg)).isTrue(); assertThat(users.containsValue(jackHandy)).isFalse(); assertThat(users.get(getKey(jackHandy))).isEqualTo(imaPigg); }
@Test public void replace() { User randyHandy = users.get(getKey(getUser("randyHandy"))); User lukeFluke = newUser("lukeFluke"); User chrisGriffon = newUser("chrisGriffon"); assertThat(randyHandy).isNotNull(); assertThat(usersTemplate.replace(getKey(randyHandy), lukeFluke)).isEqualTo(randyHandy); assertThat(users.get(getKey(randyHandy))).isEqualTo(lukeFluke); assertThat(users.containsValue(randyHandy)).isFalse(); assertThat(users.containsValue(chrisGriffon)).isFalse(); assertThat(usersTemplate.replace(getKey(chrisGriffon), chrisGriffon)).isNull(); assertThat(users.containsValue(chrisGriffon)).isFalse(); }
protected void assertRegionContents(Region<?, ?> region, Object... values) { assertThat(region.size(), is(equalTo(values.length))); for (Object value : values) { assertThat(region.containsValue(value), is(true)); } }
@Test public void create() { User bartSimpson = newUser("bartSimpson"); usersTemplate.create(getKey(bartSimpson), bartSimpson); assertThat(users.containsKey(getKey(bartSimpson))).isTrue(); assertThat(users.containsValueForKey(getKey(bartSimpson))).isTrue(); assertThat(users.containsValue(bartSimpson)).isTrue(); assertThat(users.get(getKey(bartSimpson))).isEqualTo(bartSimpson); }
@Test public void remove() { User mandyHandy = users.get(getKey(getUser("mandyHandy"))); assertThat(mandyHandy).isNotNull(); assertThat(usersTemplate.remove(getKey(mandyHandy))).isEqualTo(mandyHandy); assertThat(users.containsKey(getKey(mandyHandy))).isFalse(); assertThat(users.containsValue(mandyHandy)).isFalse(); assertThat(users.containsKey("loisGriffon")).isFalse(); assertThat(usersTemplate.remove("loisGriffon")).isNull(); assertThat(users.containsKey("loisGriffon")).isFalse(); }