From a0478a7832e003ac3748ae5b574504b12e64dc1a Mon Sep 17 00:00:00 2001 From: ramkumarvenkat Date: Tue, 31 Mar 2020 12:09:13 +0530 Subject: [PATCH] Fix code after article changes --- .../com/baeldung/guava/entity/Profile.java | 20 ++++++++ .../com/baeldung/guava/entity/Session.java | 13 ++++++ .../java/com/baeldung/guava/entity/User.java | 20 ++++++++ .../guava/mapmaker/GuavaMapMakerUnitTest.java | 46 +++++++++++++------ 4 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java new file mode 100644 index 0000000000..17a6502f39 --- /dev/null +++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java @@ -0,0 +1,20 @@ +package com.baeldung.guava.entity; + +public class Profile { + private long id; + private String type; + + public Profile(long id, String type) { + this.id = id; + this.type = type; + } + + public long getId() { + return id; + } + + public String getName() { + return type; + } + +} diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java new file mode 100644 index 0000000000..b834c23df1 --- /dev/null +++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java @@ -0,0 +1,13 @@ +package com.baeldung.guava.entity; + +public class Session { + private long id; + + public Session(long id) { + this.id = id; + } + + public long getId() { + return id; + } +} diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java new file mode 100644 index 0000000000..613045ec23 --- /dev/null +++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java @@ -0,0 +1,20 @@ +package com.baeldung.guava.entity; + +public class User { + private long id; + private String name; + + public User(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + +} diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java index 8da459f22e..e2bc1349c6 100644 --- a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java +++ b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java @@ -1,40 +1,56 @@ package com.baeldung.guava.mapmaker; +import com.baeldung.guava.entity.Profile; +import com.baeldung.guava.entity.Session; +import com.baeldung.guava.entity.User; import com.google.common.collect.MapMaker; +import org.junit.Assert; import org.junit.Test; import java.util.concurrent.ConcurrentMap; +import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; public class GuavaMapMakerUnitTest { @Test - public void whenMakeMap_thenCreated() { - ConcurrentMap concurrentMap = new MapMaker().makeMap(); - assertNotNull(concurrentMap); + public void whenCreateCaches_thenCreated() { + ConcurrentMap sessionCache = new MapMaker().makeMap(); + assertNotNull(sessionCache); + + ConcurrentMap profileCache = new MapMaker().makeMap(); + assertNotNull(profileCache); + + User userA = new User(1, "UserA"); + + sessionCache.put(userA, new Session(100)); + Assert.assertThat(sessionCache.size(), equalTo(1)); + + profileCache.put(userA, new Profile(1000, "Personal")); + Assert.assertThat(profileCache.size(), equalTo(1)); } @Test - public void whenMakeMapWithWeakKeys_thenCreated() { - ConcurrentMap concurrentMap = new MapMaker().weakKeys().makeMap(); - assertNotNull(concurrentMap); + public void whenCreateCacheWithInitialCapacity_thenCreated() { + ConcurrentMap profileCache = new MapMaker().initialCapacity(100).makeMap(); + assertNotNull(profileCache); } @Test - public void whenMakeMapWithWeakValues_thenCreated() { - ConcurrentMap concurrentMap = new MapMaker().weakValues().makeMap(); - assertNotNull(concurrentMap); + public void whenCreateCacheWithConcurrencyLevel_thenCreated() { + ConcurrentMap sessionCache = new MapMaker().concurrencyLevel(10).makeMap(); + assertNotNull(sessionCache); } @Test - public void whenMakeMapWithInitialCapacity_thenCreated() { - ConcurrentMap concurrentMap = new MapMaker().initialCapacity(10).makeMap(); - assertNotNull(concurrentMap); + public void whenCreateCacheWithWeakKeys_thenCreated() { + ConcurrentMap sessionCache = new MapMaker().weakKeys().makeMap(); + assertNotNull(sessionCache); } @Test - public void whenMakeMapWithConcurrencyLevel_thenCreated() { - ConcurrentMap concurrentMap = new MapMaker().concurrencyLevel(10).makeMap(); - assertNotNull(concurrentMap); + public void whenCreateCacheWithWeakValues_thenCreated() { + ConcurrentMap profileCache = new MapMaker().weakValues().makeMap(); + assertNotNull(profileCache); } }