Skip to content

Commit

Permalink
Polish "Fix potential NPE in GraylogExtendedLogFormatProperties"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 19, 2025
1 parent 9de5172 commit 7c52938
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public record GraylogExtendedLogFormatProperties(String host, Service service) {

static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, Service.NONE);
static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, null);

public GraylogExtendedLogFormatProperties(String host, Service service) {
this.host = host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissing() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.gelf.host", "spring");
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", Service.NONE));
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service(null)));
}

@Test
Expand All @@ -58,6 +58,15 @@ void getBindsFromEnvironmentWhenHostIsPresentAndServiceIsMissingUsesApplicationV
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
}

@Test
void getBindsFromEnvironmentWhenVersionIsPresentAndHostIsMissingUsesApplicationName() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.application.name", "spring");
environment.setProperty("logging.structured.gelf.service.version", "1.2.3");
GraylogExtendedLogFormatProperties properties = GraylogExtendedLogFormatProperties.get(environment);
assertThat(properties).isEqualTo(new GraylogExtendedLogFormatProperties("spring", new Service("1.2.3")));
}

@Test
void getWhenNoServiceNameUsesApplicationName() {
MockEnvironment environment = new MockEnvironment();
Expand Down

0 comments on commit 7c52938

Please sign in to comment.