/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.kafka.streams.processor.internals;

import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.processor.ProcessorContext;
import org.apache.kafka.streams.processor.TaskId;
import org.apache.kafka.streams.processor.internals.Task.TaskType;
import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl;
import org.apache.kafka.streams.state.internals.ThreadCache;
import org.junit.Before;
import org.junit.Test;

import java.time.Duration;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

public class ProcessorContextTest {
    private ProcessorContext context;

    @Before
    public void prepare() {
        final StreamsConfig streamsConfig = mock(StreamsConfig.class);
        expect(streamsConfig.getString(StreamsConfig.APPLICATION_ID_CONFIG)).andReturn("add-id");
        expect(streamsConfig.defaultValueSerde()).andReturn(Serdes.ByteArray());
        expect(streamsConfig.defaultKeySerde()).andReturn(Serdes.ByteArray());

        final ProcessorStateManager stateManager = mock(ProcessorStateManager.class);
        expect(stateManager.taskType()).andStubReturn(TaskType.ACTIVE);

        replay(streamsConfig, stateManager);

        context = new ProcessorContextImpl(
            mock(TaskId.class),
            streamsConfig,
            stateManager,
            mock(StreamsMetricsImpl.class),
            mock(ThreadCache.class)
        );
        ((InternalProcessorContext) context).transitionToActive(mock(StreamTask.class), null, null);
    }

    @Test
    public void shouldNotAllowToScheduleZeroMillisecondPunctuation() {
        try {
            context.schedule(Duration.ofMillis(0L), null, null);
            fail("Should have thrown IllegalArgumentException");
        } catch (final IllegalArgumentException expected) {
            assertThat(expected.getMessage(), equalTo("The minimum supported scheduling interval is 1 millisecond."));
        }
    }

    @Test
    public void shouldNotAllowToScheduleSubMillisecondPunctuation() {
        try {
            context.schedule(Duration.ofNanos(999_999L), null, null);
            fail("Should have thrown IllegalArgumentException");
        } catch (final IllegalArgumentException expected) {
            assertThat(expected.getMessage(), equalTo("The minimum supported scheduling interval is 1 millisecond."));
        }
    }
}

@@ -1346,138 +1346,8 @@
 n;%0A%0A
-import static org.easymock.EasyMock.expect;%0Aimport static org.easymock.EasyMock.mock;%0Aimport static org.easymock.EasyMock.replay;%0A
 impo
@@ -1476,16 +1476,100 @@
 rt.fail;
+%0Aimport static org.mockito.Mockito.doReturn;%0Aimport static org.mockito.Mockito.mock;
 %0A%0Apublic
@@ -1748,38 +1748,55 @@
 class);%0A        
-expect
+doReturn(%22add-id%22).when
 (streamsConfig.g
@@ -1793,16 +1793,17 @@
 msConfig
+)
 .getStri
@@ -1845,45 +1845,51 @@
 FIG)
-).andReturn(%22add-id%22);%0A        expect
+;%0A        doReturn(Serdes.ByteArray()).when
 (str
@@ -1890,32 +1890,33 @@
 en(streamsConfig
+)
 .defaultValueSer
@@ -1915,29 +1915,36 @@
 ValueSerde()
-).and
+;%0A        do
 Return(Serde
@@ -1957,32 +1957,21 @@
 Array())
-;%0A        expect
+.when
 (streams
@@ -1976,16 +1976,17 @@
 msConfig
+)
 .default
@@ -1999,39 +1999,8 @@
 de()
-).andReturn(Serdes.ByteArray())
 ;%0A%0A 
@@ -2096,103 +2096,39 @@
     
-expect(stateManager.taskType()).andStubReturn(TaskType.ACTIVE);%0A%0A        replay(streamsConfig, 
+doReturn(TaskType.ACTIVE).when(
 stat
@@ -2136,16 +2136,27 @@
 Manager)
+.taskType()
 ;%0A%0A     

Replace EasyMock with Mockito for ProcessorContextTest (#11045)