/*
 * 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.examples.todolist.mode.list;

import com.google.protobuf.StringValue;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;

import static com.google.protobuf.StringValue.getDefaultInstance;
import static io.spine.examples.todolist.mode.list.ListModeTest.StringListMode.EMPTY_VIEW;
import static io.spine.examples.todolist.mode.list.ListModeTest.StringListMode.recentState;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

/**
 * @author Dmytro Grankin
 */
@DisplayName("ListMode should")
class ListModeTest {

    private final ListMode<StringValue> stringListMode = new StringListMode();

    @Test
    @DisplayName("update state")
    void updateState() {
        assertNotEquals(recentState, stringListMode.getState());
        stringListMode.updateState();
        assertEquals(recentState, stringListMode.getState());
    }

    @Test
    @DisplayName("return empty view if state is empty")
    void returnEmptyView() {
        final List<StringValue> emptyState = emptyList();
        stringListMode.setState(emptyState);
        assertEquals(EMPTY_VIEW, stringListMode.getView());
    }

    @Test
    @DisplayName("return non-empty view if state is not empty")
    void returnNonEmptyView() {
        final StringValue item = getDefaultInstance();
        final List<StringValue> nonEmptyState = singletonList(item);
        stringListMode.setState(nonEmptyState);
        assertNotEquals(EMPTY_VIEW, stringListMode.getView());
    }

    static class StringListMode extends ListMode<StringValue> {

        static final String EMPTY_VIEW = "Empty";
        static final List<StringValue> recentState = singletonList(getDefaultInstance());

        @Override
        protected List<StringValue> receiveRecentState() {
            return unmodifiableList(recentState);
        }

        @Override
        protected String getEmptyView() {
            return EMPTY_VIEW;
        }

        @Override
        protected String getItemView(StringValue item) {
            return item.getValue();
        }
    }
}

@@ -1435,27 +1435,79 @@
 istMode.
-recentState
+RECENT_STATE;%0Aimport static io.spine.protobuf.Wrapper.forString
 ;%0Aimport
@@ -1974,22 +1974,30 @@
 ayName(%22
-update
+display recent
  state%22)
@@ -2006,22 +2006,23 @@
    void 
-update
+display
 State() 
@@ -2043,35 +2043,36 @@
 rtNotEquals(
-recentState
+RECENT_STATE
 , stringList
@@ -2116,19 +2116,13 @@
 ode.
-updateState
+start
 ();%0A
@@ -2142,27 +2142,28 @@
 tEquals(
-recentState
+RECENT_STATE
 , string
@@ -2869,32 +2869,40 @@
 lue%3E %7B%0A%0A        
+private 
 static final Str
@@ -2908,29 +2908,44 @@
 ring
- EMPTY_VIEW = %22Empty%22
+Value VALUE = forString(%22list item%22)
 ;%0A  
@@ -2981,27 +2981,28 @@
 gValue%3E 
-recentState
+RECENT_STATE
  = singl
@@ -3014,29 +3014,64 @@
 ist(
-getDefaultInstance())
+VALUE);%0A        static final String EMPTY_VIEW = %22Empty%22
 ;%0A%0A 
@@ -3186,19 +3186,20 @@
 ist(
-recentState
+RECENT_STATE
 );%0A 

Make little changes in `ListModeTest`