diff options
author | Jason Tedor <jason@tedor.me> | 2017-05-23 08:22:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-23 08:22:18 -0400 |
commit | c179c6a4c9c67543d1c21817be3df769053ee345 (patch) | |
tree | 55eebd6088e18a00b50434df68ebfb9a81d61c47 /core/src/test/java/org/elasticsearch/common | |
parent | 747fa721e48655bc82595b94461d76c99dee3b83 (diff) |
Add assertions enabled helper
Today in the code base we have lots of ugly code blocks like:
boolean assertionsEnabled = false;
assert assertionsEnabled = true;
if (assertionsEnabled) {
// something
}
These are a nuisance. Instead, we can do this in exactly one place and
replace these blocks with
if (Assertions.ENABLED) {
// something
}
The cool thing here is that since this is a static final field, the JIT
can optimize away the check at runtime if assertions are disabled.
Relates #24834
Diffstat (limited to 'core/src/test/java/org/elasticsearch/common')
-rw-r--r-- | core/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/core/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java b/core/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java index 0b23002a89..1d340ad65d 100644 --- a/core/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java +++ b/core/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.common.hppc; import com.carrotsearch.hppc.ObjectHashSet; +import org.elasticsearch.Assertions; import org.elasticsearch.common.collect.HppcMaps; import org.elasticsearch.test.ESTestCase; @@ -29,9 +30,7 @@ import static org.hamcrest.Matchers.equalTo; public class HppcMapsTests extends ESTestCase { public void testIntersection() throws Exception { - boolean enabled = false; - assert enabled = true; - assumeTrue("assertions enabled", enabled); + assumeTrue("assertions enabled", Assertions.ENABLED); ObjectHashSet<String> set1 = ObjectHashSet.from("1", "2", "3"); ObjectHashSet<String> set2 = ObjectHashSet.from("1", "2", "3"); List<String> values = toList(HppcMaps.intersection(set1, set2)); |