blob: 0b796ff4dde8e5968e0701a42e44d981676a28f0 [file] [log] [blame]
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed 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 com.ericsson.gerrit.plugins.heartbeat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.server.events.EventDispatcher;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
public class HeartbeatDaemonTest {
private EventDispatcher eventDispatcherMock;
private HeartbeatDaemon heartbeatDaemon;
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
eventDispatcherMock = mock(EventDispatcher.class);
DynamicItem<EventDispatcher> dynamicEventDispatcherMock = mock(DynamicItem.class);
when(dynamicEventDispatcherMock.get()).thenReturn(eventDispatcherMock);
HeartbeatConfig heartbeatConfigMock = mock(HeartbeatConfig.class);
when(heartbeatConfigMock.getDelay()).thenReturn(1);
heartbeatDaemon = new HeartbeatDaemon(dynamicEventDispatcherMock, heartbeatConfigMock);
}
@Test
public void thatDaemonSendsHeartbeatEvents() throws Exception {
heartbeatDaemon.start();
TimeUnit.MILLISECONDS.sleep(500);
verify(eventDispatcherMock, atLeastOnce()).postEvent(any(HeartbeatEvent.class));
heartbeatDaemon.stop();
}
}