From: Robert Varga Date: Tue, 22 Dec 2015 11:04:10 +0000 (+0100) Subject: BUG-4803: invalidate cache before each test X-Git-Tag: release/beryllium~58 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=f1091bd54afc0a9342bd468887efd22b41fffcc5 BUG-4803: invalidate cache before each test Running tests will pollute the cache, so we need to clear it before each test. Change-Id: I0cc171c22409d81092d82d5570a3c0068bbfc889 Signed-off-by: Robert Varga --- diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java index e99a4f8a06..b9776e3421 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java @@ -7,6 +7,7 @@ */ package org.opendaylight.yangtools.util; +import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -42,6 +43,11 @@ final class OffsetMapCache { return (Map) CACHE.getUnchecked(args); } + @VisibleForTesting + static void invalidateCache() { + CACHE.invalidateAll(); + } + static Map orderedOffsets(final Collection args) { if (args.size() == 1) { return unorderedOffsets(args); diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java index 4c4f6bbf18..17a6f2e1ed 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Set; +import org.junit.Before; import org.junit.Test; public class OffsetMapTest { @@ -39,6 +40,11 @@ public class OffsetMapTest { return (ImmutableOffsetMap) ImmutableOffsetMap.copyOf(twoEntryMap); } + @Before + public void setup() { + OffsetMapCache.invalidateCache(); + } + @Test(expected=IllegalArgumentException.class) public void testWrongImmutableConstruction() { new ImmutableOffsetMap.Ordered(Collections.emptyMap(), new String[1]);