Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
* @see ContextKey
*/
public interface Context {
/**
* Returns the empty context.
*
* @return the context containing no values at all.
*/
static Context empty() {
return EmptyContext.INSTANCE;
}

/**
* Returns the root context.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.context;

import static datadog.context.Context.empty;
import static datadog.context.Context.root;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -21,6 +22,17 @@ class ContextTest {
static final ContextKey<Float> FLOAT_KEY = ContextKey.named("float-key");
static final ContextKey<Long> LONG_KEY = ContextKey.named("long-key");

@Test
void testEmpty() {
// Test empty is always the same
Context empty = empty();
assertEquals(empty, empty(), "Empty context should be consistent");
// Test empty is not mutated
String stringValue = "value";
empty.with(STRING_KEY, stringValue);
assertEquals(empty, empty(), "Empty context should be immutable");
}

@Test
void testRoot() {
// Test root is always the same
Expand Down
Loading