package org.atlasapi.messaging;

import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Futures;
import com.metabroadcast.common.time.Timestamp;
import org.atlasapi.content.Brand;
import org.atlasapi.content.EquivalentContentStore;
import org.atlasapi.content.Item;
import org.atlasapi.entity.Id;
import org.atlasapi.media.entity.Publisher;
import org.atlasapi.schedule.EquivalentScheduleWriter;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.UUID;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class EquivalentScheduleStoreContentUpdateWorkerTest {


    @Mock
    private EquivalentContentStore contentStore;

    @Mock
    private EquivalentScheduleWriter scheduleWriter;
    @InjectMocks

    private EquivalentScheduleStoreContentUpdateWorker objectUnderTest;


    @Test
    public void testProcess() throws Exception {
        Long equivalentSetId = 1L;
        Item item1 = new Item(Id.valueOf(1L), Publisher.METABROADCAST);
        Item item2 = new Item(Id.valueOf(2L), Publisher.METABROADCAST);

        when(contentStore.resolveEquivalentSet(equivalentSetId))
                .thenReturn(
                        Futures.immediateFuture(
                                ImmutableSet.of(item1, item2)
                        )
                );
        objectUnderTest.process(
                new EquivalentContentUpdatedMessage(
                        UUID.randomUUID().toString(),
                        Timestamp.of(DateTime.now()),
                        equivalentSetId
                )
        );

        verify(scheduleWriter).updateContent(ImmutableSet.of(item1, item2));

    }


    @Test
    public void testFiltersOutNonItems() throws Exception {
        Long equivalentSetId = 1L;
        Item item1 = new Item(Id.valueOf(1L), Publisher.METABROADCAST);
        Item item2 = new Item(Id.valueOf(2L), Publisher.METABROADCAST);
        Brand brand = new Brand(Id.valueOf(3L), Publisher.METABROADCAST);

        when(contentStore.resolveEquivalentSet(equivalentSetId))
                .thenReturn(
                        Futures.immediateFuture(
                                ImmutableSet.of(item1, item2, brand)
                        )
                );
        objectUnderTest.process(
                new EquivalentContentUpdatedMessage(
                        UUID.randomUUID().toString(),
                        Timestamp.of(DateTime.now()),
                        equivalentSetId
                )
        );

        verify(scheduleWriter).updateContent(ImmutableSet.of(item1, item2));
    }
}
@@ -26,16 +26,95 @@
 aging;%0A%0A
+import com.codahale.metrics.MetricRegistry;%0Aimport com.codahale.metrics.Timer;%0A
 import c
@@ -532,16 +532,41 @@
 teTime;%0A
+import org.junit.Before;%0A
 import o
@@ -742,16 +742,56 @@
 .UUID;%0A%0A
+import static org.mockito.Mockito.mock;%0A
 import s
@@ -1091,97 +1091,579 @@
 er;%0A
+%0A
     @
-InjectMocks%0A%0A    private EquivalentScheduleStoreContentUpdateWorker objectUnderTest;
+Mock%0A    private MetricRegistry metrics;%0A%0A    @Mock%0A    private Timer timer;%0A%0A    private EquivalentScheduleStoreContentUpdateWorker objectUnderTest;%0A%0A    @Before%0A    public void setUp() %7B%0A        when(metrics.timer(%22EquivalentScheduleStoreContentUpdateWorker%22)).thenReturn(timer);%0A        objectUnderTest = new EquivalentScheduleStoreContentUpdateWorker(%0A                contentStore,%0A                scheduleWriter,%0A                metrics%0A        );%0A        Timer.Context context = mock(Timer.Context.class);%0A        when(timer.time()).thenReturn(context);%0A    %7D
 %0A%0A%0A 

Fix broken test.