/*
 * Copyright 2021, TeamDev. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.aggregate.given;

import io.spine.base.CommandMessage;
import io.spine.base.EventMessage;
import io.spine.base.Identifier;
import io.spine.client.CommandFactory;
import io.spine.core.Command;
import io.spine.core.Event;
import io.spine.core.TenantId;
import io.spine.server.aggregate.AggregateTest;
import io.spine.test.aggregate.ProjectId;
import io.spine.test.aggregate.command.AggCreateProject;
import io.spine.test.aggregate.command.AggStartProject;
import io.spine.test.aggregate.event.AggProjectPaused;
import io.spine.test.aggregate.event.AggTaskStarted;
import io.spine.test.aggregate.task.AggTaskId;
import io.spine.testing.client.TestActorRequestFactory;
import io.spine.testing.server.TestEventFactory;

import static io.spine.base.Identifier.newUuid;

public class IdempotencyGuardTestEnv {

    private static final TestEventFactory eventFactory =
            TestEventFactory.newInstance(IdempotencyGuardTestEnv.class);
    private static final CommandFactory commandFactory =
            new TestActorRequestFactory(AggregateTest.class).command();


    /** Prevents instantiation of this test environment. */
    private IdempotencyGuardTestEnv() {
    }

    public static TenantId newTenantId() {
        return TenantId.newBuilder()
                       .setValue(newUuid())
                       .build();
    }

    private static AggTaskId newTaskId() {
        return AggTaskId.newBuilder()
                        .setId(Identifier.newUuid())
                        .build();
    }

    public static AggCreateProject createProject(ProjectId projectId) {
        return AggCreateProject.newBuilder()
                               .setProjectId(projectId)
                               .build();
    }

    public static AggStartProject startProject(ProjectId projectId) {
        return AggStartProject.newBuilder()
                              .setProjectId(projectId)
                              .build();
    }

    public static AggTaskStarted taskStarted(ProjectId projectId) {
        return AggTaskStarted.newBuilder()
                             .setTaskId(newTaskId())
                             .setProjectId(projectId)
                             .build();
    }

    public static AggProjectPaused projectPaused(ProjectId projectId) {
        return AggProjectPaused.newBuilder()
                               .setProjectId(projectId)
                               .build();
    }

    public static Command command(CommandMessage commandMessage) {
        return commandFactory.create(commandMessage);
    }

    public static Event event(EventMessage eventMessage) {
        return eventFactory.createEvent(eventMessage);
    }
}

@@ -2031,16 +2031,22 @@
 %0Apublic 
+final 
 class Id
@@ -2069,16 +2069,16 @@
 stEnv %7B%0A
-
 %0A    pri
@@ -2530,31 +2530,24 @@
             
-       
 .setValue(ne
@@ -2547,39 +2547,32 @@
 alue(newUuid())%0A
-       
                 
@@ -2681,32 +2681,24 @@
             
-        
 .setId(Ident
@@ -2710,32 +2710,24 @@
 .newUuid())%0A
-        
             
@@ -2876,39 +2876,24 @@
             
-               
 .setProjectI
@@ -2901,39 +2901,24 @@
 (projectId)%0A
-               
             
@@ -3064,38 +3064,24 @@
             
-              
 .setProjectI
@@ -3089,38 +3089,24 @@
 (projectId)%0A
-              
             
@@ -3249,37 +3249,24 @@
             
-             
 .setTaskId(n
@@ -3289,37 +3289,24 @@
             
-       
-      
 .setProjectI
@@ -3314,37 +3314,24 @@
 (projectId)%0A
-             
             
@@ -3484,31 +3484,16 @@
         
-               
 .setProj
@@ -3509,31 +3509,16 @@
 jectId)%0A
-               
         

Reformat the code.