/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * 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.model;

import com.google.protobuf.Empty;
import com.google.protobuf.Timestamp;
import io.spine.server.command.Assign;
import io.spine.server.command.CommandHandler;
import io.spine.server.event.EventBus;
import io.spine.test.Tests;
import org.junit.Test;

/**
 * @author Alexander Yevsyukov
 */
public class ModelTestsShould {

    @Test
    public void have_utility_ctor() {
        Tests.assertHasPrivateParameterlessCtor(ModelTests.class);
    }

    @Test
    public void clear_the_model() {
        final Model model = Model.getInstance();

        // This adds new class to the model.
        model.asCommandHandlerClass(TestCommandHandler.class);

        ModelTests.clearModel();

        // This should pass as we cleared the model.
        model.asCommandHandlerClass(TestCommandHandler.class);
    }

    private static class TestCommandHandler extends CommandHandler {

        private TestCommandHandler(EventBus eventBus) {
            super(eventBus);
        }

        @Assign
        Empty handle(Timestamp cmd) {
            return Empty.getDefaultInstance();
        }
    }
}

@@ -1267,16 +1267,41 @@
 .Tests;%0A
+import org.junit.Before;%0A
 import o
@@ -1384,24 +1384,241 @@
 tsShould %7B%0A%0A
+    private final Model model = Model.getInstance();%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        // The model should not be polluted by the previously executed tests.%0A        model.clear();%0A    %7D%0A%0A
     @Test%0A  
@@ -1777,101 +1777,83 @@
 ) %7B%0A
-        final Model model = Model.getInstance();%0A%0A        // This adds new class to the model
+%0A        // This adds a command handler for %60com.google.protobuf.Timestamp%60
 .%0A  
@@ -1999,16 +1999,108 @@
 he model
+,%0A        // i.e. there is no registered command handler for %60com.google.protobuf.Timestamp%60
 .%0A      
@@ -2121,36 +2121,42 @@
 andHandlerClass(
-Test
+Duplicated
 CommandHandler.c
@@ -2238,17 +2238,16 @@
 ndler %7B%0A
-%0A
         
@@ -2329,24 +2329,428 @@
 ;%0A        %7D%0A
+%0A        @Assign%0A        Empty handle(Timestamp cmd) %7B%0A            return Empty.getDefaultInstance();%0A        %7D%0A    %7D%0A%0A    private static class DuplicatedCommandHandler extends CommandHandler %7B%0A        private DuplicatedCommandHandler(EventBus eventBus) %7B%0A            super(eventBus);%0A        %7D%0A%0A        /**%0A         * Handles the same command as %7B@link TestCommandHandler#handle(Timestamp)%7D.%0A         */
 %0A        @As

Fix tests and set up for `ModelTestsShould`