Fix confusing "now" parameters on persist deleted helper methods

They were taking a DateTime "now", which would seem like it would be the time of
when the resource was deleted, but it was actually the time by which the
resource was deleted, with the actual deletion time being hardcoded to a day
prior.  The confusion was evident because a fair number of tests were passing
the wrong thing.  I renamed the parameter "deletionTime" to make it exactly
clear what it's doing and fixed up some callsites where necessary.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134818032
This commit is contained in:
mcilwain 2016-09-30 13:10:08 -07:00 committed by Ben McIlwain
parent 35d5307706
commit c517c98d17
23 changed files with 63 additions and 53 deletions

View file

@ -249,12 +249,10 @@ public class DatastoreHelper {
return persistResource(newContactResource(contactId));
}
public static ContactResource persistDeletedContact(String contactId, DateTime now) {
/** Persists a contact resource with the given contact id deleted at the specified time. */
public static ContactResource persistDeletedContact(String contactId, DateTime deletionTime) {
return persistResource(
newContactResource(contactId)
.asBuilder()
.setDeletionTime(now.minusDays(1))
.build());
newContactResource(contactId).asBuilder().setDeletionTime(deletionTime).build());
}
public static HostResource persistActiveHost(String hostName) {
@ -271,9 +269,10 @@ public class DatastoreHelper {
.build());
}
public static HostResource persistDeletedHost(String hostName, DateTime now) {
/** Persists a host resource with the given hostname deleted at the specified time. */
public static HostResource persistDeletedHost(String hostName, DateTime deletionTime) {
return persistResource(
newHostResource(hostName).asBuilder().setDeletionTime(now.minusDays(1)).build());
newHostResource(hostName).asBuilder().setDeletionTime(deletionTime).build());
}
public static DomainResource persistActiveDomain(String domainName) {
@ -289,17 +288,28 @@ public class DatastoreHelper {
return persistResource(newDomainApplication(domainName, contact, phase));
}
public static DomainApplication persistDeletedDomainApplication(String domainName, DateTime now) {
return persistResource(newDomainApplication(domainName).asBuilder()
.setDeletionTime(now.minusDays(1)).build());
/**
* Persists a domain application resource with the given domain name deleted at the specified
* time.
*/
public static DomainApplication persistDeletedDomainApplication(
String domainName, DateTime deletionTime) {
return persistResource(
newDomainApplication(domainName).asBuilder().setDeletionTime(deletionTime).build());
}
public static DomainResource persistDeletedDomain(String domainName, DateTime now) {
return persistDomainAsDeleted(newDomainResource(domainName), now);
/** Persists a domain resource with the given domain name deleted at the specified time. */
public static DomainResource persistDeletedDomain(String domainName, DateTime deletionTime) {
return persistDomainAsDeleted(newDomainResource(domainName), deletionTime);
}
public static DomainResource persistDomainAsDeleted(DomainResource domain, DateTime now) {
return persistResource(domain.asBuilder().setDeletionTime(now.minusDays(1)).build());
/**
* Returns a persisted domain that is the passed-in domain modified to be deleted at the specified
* time.
*/
public static DomainResource persistDomainAsDeleted(
DomainResource domain, DateTime deletionTime) {
return persistResource(domain.asBuilder().setDeletionTime(deletionTime).build());
}
/** Persists a domain and enqueues a LORDN task of the appropriate type for it. */