Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate zoneOffset based on zoneId in TestActorRequestFactory #915

Merged
merged 4 commits into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import io.spine.time.ZoneOffset;
import io.spine.time.ZoneOffsets;

import java.time.ZonedDateTime;

import static io.spine.testing.core.given.GivenUserId.of;

/**
Expand All @@ -45,11 +47,11 @@
@VisibleForTesting
public class TestActorRequestFactory extends ActorRequestFactory {

protected TestActorRequestFactory(UserId actor, ZoneOffset zoneOffset, ZoneId zoneId) {
protected TestActorRequestFactory(UserId actor, ZoneId zoneId) {
super(ActorRequestFactory
.newBuilder()
.setActor(actor)
.setZoneOffset(zoneOffset)
.setZoneOffset(idToZoneOffset(zoneId))
.setZoneId(zoneId)
);
}
Expand All @@ -68,21 +70,21 @@ protected TestActorRequestFactory(TenantId tenantId,
}

public static
TestActorRequestFactory newInstance(String actor, ZoneOffset zoneOffset, ZoneId zoneId) {
return newInstance(of(actor), zoneOffset, zoneId);
TestActorRequestFactory newInstance(String actor, ZoneId zoneId) {
return newInstance(of(actor), zoneId);
}

public static
TestActorRequestFactory newInstance(UserId actor, ZoneOffset zoneOffset, ZoneId zoneId) {
return new TestActorRequestFactory(actor, zoneOffset, zoneId);
TestActorRequestFactory newInstance(UserId actor, ZoneId zoneId) {
return new TestActorRequestFactory(actor, zoneId);
}

public static TestActorRequestFactory newInstance(Class<?> testClass) {
return newInstance(testClass.getName(), ZoneOffsets.getDefault(), ZoneIds.systemDefault());
return newInstance(testClass.getName(), ZoneIds.systemDefault());
}

public static TestActorRequestFactory newInstance(UserId actor) {
return newInstance(actor, ZoneOffsets.getDefault(), ZoneIds.systemDefault());
return newInstance(actor, ZoneIds.systemDefault());
}

public static TestActorRequestFactory newInstance(UserId actor, TenantId tenantId) {
Expand All @@ -98,6 +100,18 @@ public static TestActorRequestFactory newInstance(Class<?> testClass, TenantId t
ZoneIds.systemDefault());
}

private static ZoneOffset idToZoneOffset(ZoneId zoneId) {
java.time.ZoneId javaZoneId = java.time.ZoneId.of(zoneId.getValue());
int offsetInSeconds = ZonedDateTime.now(javaZoneId)
.getOffset()
.getTotalSeconds();
ZoneOffset offset = ZoneOffset
.newBuilder()
.setAmountSeconds(offsetInSeconds)
.build();
return offset;
}

/** Creates new command with the passed timestamp. */
public Command createCommand(CommandMessage message, Timestamp timestamp) {
Command command = command().create(message);
Expand Down