Skip to content

Commit

Permalink
fix: Make tenant attributes optional
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
  • Loading branch information
ThomasVitale committed Mar 24, 2024
1 parent e004c7a commit c2c6e56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand All @@ -14,15 +16,14 @@ public class Tenant implements TenantDetails {

private final boolean enabled;

private final Map<String, Object> attributes = new HashMap<>();
private final Map<String, Object> attributes;

public Tenant(String identifier, boolean enabled, Map<String, Object> attributes) {
public Tenant(String identifier, boolean enabled, @Nullable Map<String, Object> attributes) {
Assert.hasText(identifier, "identifier cannot be null or empty");
Assert.notNull(attributes, "attributes cannot be null");

this.identifier = identifier;
this.enabled = enabled;
this.attributes = attributes;
this.attributes = Objects.requireNonNullElse(attributes, new HashMap<>());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
Expand All @@ -22,10 +23,10 @@ void whenIdentifierIsEmptyThenThrow() {
}

@Test
void whenAttributesIsNullThenThrow() {
assertThatThrownBy(() -> Tenant.create().identifier("acme").attributes(null).build())
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("attributes cannot be null");
void whenAttributesIsNullThenUseEmptymap() {
var tenant = Tenant.create().identifier("acme").attributes(null).build();
assertThat(tenant.getAttributes()).isNotNull();
assertThat(tenant.getAttributes()).isEmpty();
}

}

0 comments on commit c2c6e56

Please sign in to comment.