mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Don't allow null in BillingEvent.setFlags()
It's better that it always takes a non-null ImmutableSet, which may either be empty or contain elements. That way the ugliness of nullness is contained just to the entity class itself, and all other code that interacts with it can always be assured of having a real set to deal with. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132066238
This commit is contained in:
parent
c06133435b
commit
07135f6190
3 changed files with 9 additions and 3 deletions
|
@ -157,7 +157,9 @@ public class DomainCreateFlow extends DomainCreateOrAllocateFlow {
|
||||||
.setBillingTime(now.plus(isAnchorTenant()
|
.setBillingTime(now.plus(isAnchorTenant()
|
||||||
? registry.getAnchorTenantAddGracePeriodLength()
|
? registry.getAnchorTenantAddGracePeriodLength()
|
||||||
: registry.getAddGracePeriodLength()))
|
: registry.getAddGracePeriodLength()))
|
||||||
.setFlags(isAnchorTenant() ? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT) : null)
|
.setFlags(isAnchorTenant()
|
||||||
|
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
|
||||||
|
: ImmutableSet.<BillingEvent.Flag>of())
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
.build();
|
.build();
|
||||||
ofy().save().entity(createEvent);
|
ofy().save().entity(createEvent);
|
||||||
|
|
|
@ -19,9 +19,11 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
|
import static google.registry.util.CollectionUtils.forceEmptyToNull;
|
||||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||||
import static google.registry.util.CollectionUtils.union;
|
import static google.registry.util.CollectionUtils.union;
|
||||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||||
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -44,6 +46,7 @@ import google.registry.model.reporting.HistoryEntry;
|
||||||
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
@ -98,6 +101,7 @@ public abstract class BillingEvent extends ImmutableObject
|
||||||
/** The fully qualified domain name of the domain that the bill is for. */
|
/** The fully qualified domain name of the domain that the bill is for. */
|
||||||
String targetId;
|
String targetId;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
Set<Flag> flags;
|
Set<Flag> flags;
|
||||||
|
|
||||||
public String getClientId() {
|
public String getClientId() {
|
||||||
|
@ -168,7 +172,7 @@ public abstract class BillingEvent extends ImmutableObject
|
||||||
}
|
}
|
||||||
|
|
||||||
public B setFlags(ImmutableSet<Flag> flags) {
|
public B setFlags(ImmutableSet<Flag> flags) {
|
||||||
getInstance().flags = flags;
|
getInstance().flags = forceEmptyToNull(checkArgumentNotNull(flags, "flags"));
|
||||||
return thisCastToDerived();
|
return thisCastToDerived();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
: clock.nowUtc().plus(Registry.get(domainTld).getAddGracePeriodLength());
|
: clock.nowUtc().plus(Registry.get(domainTld).getAddGracePeriodLength());
|
||||||
ImmutableSet<BillingEvent.Flag> billingFlags = isAnchorTenant
|
ImmutableSet<BillingEvent.Flag> billingFlags = isAnchorTenant
|
||||||
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
|
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
|
||||||
: null;
|
: ImmutableSet.<BillingEvent.Flag>of();
|
||||||
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
|
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
|
||||||
assertAboutDomains().that(domain)
|
assertAboutDomains().that(domain)
|
||||||
.hasRegistrationExpirationTime(
|
.hasRegistrationExpirationTime(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue