/*
 * 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 org.spine3.server.entity;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.spine3.server.entity.Predicates.isEntityVisible;
import static org.spine3.server.entity.Predicates.isRecordVisible;
import static org.spine3.test.Tests.assertHasPrivateParameterlessCtor;

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

    @Test
    public void have_private_default_ctor() {
        assertHasPrivateParameterlessCtor(Predicates.class);
    }

    @Test
    public void consider_archived_entity_invisible() {
        final Visibility status =
                Visibility.newBuilder()
                            .setArchived(true)
                            .build();
        assertFalse(isEntityVisible().apply(status));
    }

    @Test
    public void consider_deleted_entity_invisible() {
        final Visibility status =
                Visibility.newBuilder()
                            .setDeleted(true)
                            .build();
        assertFalse(isEntityVisible().apply(status));
    }

    @Test
    public void consider_archived_record_invisible() {
        final EntityRecord record =
                EntityRecord
                        .newBuilder()
                        .setVisibility(Visibility.newBuilder()
                                                     .setArchived(true))
                        .build();
        assertFalse(isRecordVisible().apply(record));
    }

    @Test
    public void consider_deleted_record_invisible() {
        final EntityRecord record =
                EntityRecord
                        .newBuilder()
                        .setVisibility(Visibility.newBuilder()
                                                     .setDeleted(true))
                        .build();
        assertFalse(isRecordVisible().apply(record));
    }
}

@@ -1113,16 +1113,59 @@
 tFalse;%0A
+import static org.junit.Assert.assertTrue;%0A
 import s
@@ -2920,11 +2920,281 @@
 );%0A    %7D
+%0A%0A    /**%0A     * We are not likely to encounter %7B@code null%7D records,%0A     * but making such records %E2%80%9Cvisible%E2%80%9D would help identify possible bugs.%0A     */%0A    @Test%0A    public void consider_null_records_visible() %7B%0A        assertTrue(isEntityVisible().apply(null));%0A    %7D
 %0A%7D%0A

Test visibility of `null` records