-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnleashContext.Builder Convenience (#255)
- made builder populate special properties by name Co-authored-by: ms583h <[email protected]>
- Loading branch information
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package io.getunleash; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.getunleash.util.UnleashConfig; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.data.MapEntry.entry; | ||
|
||
public class UnleashContextTest { | ||
|
||
@Test | ||
|
@@ -39,7 +41,7 @@ public void should_get_context_with_fields_set() { | |
assertThat(context.getRemoteAddress()).hasValue("127.0.0.1"); | ||
assertThat(context.getEnvironment()).hasValue("prod"); | ||
assertThat(context.getAppName()).hasValue("myapp"); | ||
assertThat(context.getProperties().get("test")).isEqualTo("me"); | ||
assertThat(context.getProperties()).containsExactly(entry("test", "me")); | ||
} | ||
|
||
@Test | ||
|
@@ -70,7 +72,7 @@ public void should_apply_context_fields() { | |
} | ||
|
||
@Test | ||
public void should_not_ovveride_static_context_fields() { | ||
public void should_not_override_static_context_fields() { | ||
UnleashContext context = | ||
UnleashContext.builder() | ||
.userId("[email protected]") | ||
|
@@ -96,4 +98,36 @@ public void should_not_ovveride_static_context_fields() { | |
assertThat(enhanced.getEnvironment()).hasValue("env"); | ||
assertThat(enhanced.getAppName()).hasValue("myApp"); | ||
} | ||
|
||
@Nested | ||
class BuilderTest { | ||
|
||
@Test | ||
void should_set_special_properties() { | ||
final UnleashContext context = UnleashContext.builder() | ||
.addProperty("userId", "[email protected]") | ||
.addProperty("sessionId", "123") | ||
.addProperty("remoteAddress", "127.0.0.1") | ||
.addProperty("environment", "env") | ||
.addProperty("appName", "myApp") | ||
.build(); | ||
|
||
assertThat(context.getUserId()).contains("[email protected]"); | ||
assertThat(context.getSessionId()).contains("123"); | ||
assertThat(context.getRemoteAddress()).contains("127.0.0.1"); | ||
assertThat(context.getEnvironment()).contains("env"); | ||
assertThat(context.getAppName()).contains("myApp"); | ||
} | ||
|
||
@Test | ||
void should_set_non_special_properties() { | ||
final UnleashContext context = UnleashContext.builder() | ||
.addProperty("foo", "bar") | ||
.build(); | ||
|
||
assertThat(context.getProperties()).containsExactly(entry("foo", "bar")); | ||
} | ||
|
||
} | ||
|
||
} |