<commit_before>/*
 * Copyright 2018, TeamDev. 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.entity;

import com.google.protobuf.Empty;
import com.google.protobuf.Timestamp;
import io.spine.base.Time;
import io.spine.core.Event;
import io.spine.core.EventClass;
import io.spine.testing.server.TestEventFactory;
import io.spine.time.LocalDate;
import io.spine.time.LocalDates;
import io.spine.time.ZonedDateTimes;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author <NAME>
 */
@DisplayName("WhiteListEventFilter should")
class WhiteListEventFilterTest {

    private static final Set<EventClass> WHITE_LIST = EventClass.setOf(
            Timestamp.class,
            LocalDate.class
    );

    private static final TestEventFactory eventFactory =
            TestEventFactory.newInstance(WhiteListEventFilterTest.class);

    @Test
    @DisplayName("allow eventFactory of white list type")
    void acceptAllowed() {
        WhiteListFilter filter = WhiteListFilter.allowEvents(WHITE_LIST);
        Event event = eventFactory.createEvent(Timestamp.getDefaultInstance());
        Optional<Event> result = filter.filter(event);
        assertTrue(result.isPresent());
        assertEquals(event, result.get());
    }

    @Test
    @DisplayName("allow bulk eventFactory of white list types")
    void acceptAllowedBulk() {
        WhiteListFilter filter = WhiteListFilter.allowEvents(WHITE_LIST);
        List<Event> events = Stream.of(Time.getCurrentTime(),
                                       LocalDates.now())
                                   .map(eventFactory::createEvent)
                                   .collect(toList());
        Collection<Event> filtered = filter.filter(events);
        assertEquals(events.size(), filtered.size());
        assertTrue(events.containsAll(filtered));
    }

    @Test
    @DisplayName("filter out non-allowed events")
    void filterOut() {
        WhiteListFilter filter = WhiteListFilter.allowEvents(WHITE_LIST);
        List<Event> events = Stream.of(Time.getCurrentTime(),
                                       ZonedDateTimes.now())
                                   .map(eventFactory::createEvent)
                                   .collect(toList());
        Collection<Event> filtered = filter.filter(events);
        assertEquals(1, filtered.size());
        assertTrue(events.contains(events.get(0)));
    }

    @Test
    @DisplayName("not allow events out from the white list")
    void denyEvents() {
        WhiteListFilter filter = WhiteListFilter.allowEvents(WHITE_LIST);
        Event event = eventFactory.createEvent(Empty.getDefaultInstance());
        Optional<Event> result = filter.filter(event);
        assertFalse(result.isPresent());
    }
}<commit_msg>Delete a redundant test.<commit_after>/*
 * Copyright 2018, TeamDev. 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.entity;

import io.spine.core.Event;
import io.spine.core.EventClass;
import io.spine.test.entity.event.EntProjectCreated;
import io.spine.test.entity.event.EntProjectStarted;
import io.spine.test.entity.event.EntTaskAdded;
import io.spine.testing.server.TestEventFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author <NAME>
 */
@DisplayName("WhiteListFilter should")
class WhiteListEventFilterTest {

    private static final Set<EventClass> WHITE_LIST = EventClass.setOf(
            EntProjectCreated.class,
            EntProjectStarted.class
    );

    private static final TestEventFactory eventFactory =
            TestEventFactory.newInstance(WhiteListEventFilterTest.class);

    private WhiteListFilter whiteList;

    @BeforeEach
    void setUp() {
        whiteList = WhiteListFilter.allowEvents(WHITE_LIST);
    }

    @Test
    @DisplayName("allow eventFactory of white list type")
    void acceptAllowed() {
        Event event = eventFactory.createEvent(EntProjectCreated.getDefaultInstance());
        Optional<Event> result = whiteList.filter(event);
        assertTrue(result.isPresent());
        assertEquals(event, result.get());
    }

    @Test
    @DisplayName("filter out non-allowed events")
    void filterOut() {
        List<Event> events = Stream.of(EntProjectStarted.getDefaultInstance(),
                                       EntTaskAdded.getDefaultInstance())
                                   .map(eventFactory::createEvent)
                                   .collect(toList());
        Collection<Event> filtered = whiteList.filter(events);
        assertEquals(1, filtered.size());
        assertTrue(events.contains(events.get(0)));
    }

    @Test
    @DisplayName("not allow events out from the white list")
    void denyEvents() {
        Event event = eventFactory.createEvent(EntTaskAdded.getDefaultInstance());
        Optional<Event> result = whiteList.filter(event);
        assertFalse(result.isPresent());
    }
}
{'fraction_non_alphanumeric': 0.09220231822971549, 'fraction_numerical': 0.0015806111696522655, 'mean_word_length': 3.3562822719449223, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443506', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1967, 'n_words': 573}