001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop.screen.help;
019
020import static org.hamcrest.CoreMatchers.is;
021import static org.hamcrest.MatcherAssert.assertThat;
022import static org.mockito.ArgumentMatchers.argThat;
023import static org.mockito.ArgumentMatchers.eq;
024import static org.mockito.Mockito.verify;
025
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.junit.Before;
030import org.junit.ClassRule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033import org.junit.runner.RunWith;
034import org.mockito.Mock;
035import org.mockito.junit.MockitoJUnitRunner;
036
037@Category(SmallTests.class)
038@RunWith(MockitoJUnitRunner.class)
039public class TestHelpScreenPresenter {
040
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043    HBaseClassTestRule.forClass(TestHelpScreenPresenter.class);
044
045  private static final long TEST_REFRESH_DELAY = 5;
046
047  @Mock
048  private HelpScreenView helpScreenView;
049
050  @Mock
051  private TopScreenView topScreenView;
052
053  private HelpScreenPresenter helpScreenPresenter;
054
055  @Before
056  public void setup() {
057    helpScreenPresenter =
058      new HelpScreenPresenter(helpScreenView, TEST_REFRESH_DELAY, topScreenView);
059  }
060
061  @Test
062  public void testInit() {
063    helpScreenPresenter.init();
064    verify(helpScreenView).showHelpScreen(eq(TEST_REFRESH_DELAY), argThat(cds -> cds.length == 14));
065  }
066
067  @Test
068  public void testTransitionToTopScreen() {
069    assertThat(helpScreenPresenter.transitionToNextScreen(), is(topScreenView));
070  }
071}