View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.screen.help;
19  
20  import static org.hamcrest.CoreMatchers.is;
21  import static org.junit.Assert.assertThat;
22  import static org.mockito.Mockito.argThat;
23  import static org.mockito.Mockito.eq;
24  import static org.mockito.Mockito.verify;
25  
26  import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
27  import org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView;
28  import org.apache.hadoop.hbase.testclassification.SmallTests;
29  import org.junit.Before;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  import org.junit.runner.RunWith;
33  import org.mockito.ArgumentMatcher;
34  import org.mockito.Mock;
35  import org.mockito.runners.MockitoJUnitRunner;
36  
37  
38  @Category(SmallTests.class)
39  @RunWith(MockitoJUnitRunner.class)
40  public class TestHelpScreenPresenter {
41  
42    private static final long TEST_REFRESH_DELAY = 5;
43  
44    @Mock
45    private HelpScreenView helpScreenView;
46  
47    @Mock
48    private TopScreenView topScreenView;
49  
50    private HelpScreenPresenter helpScreenPresenter;
51  
52    @Before
53    public void setup() {
54      helpScreenPresenter = new HelpScreenPresenter(helpScreenView, TEST_REFRESH_DELAY,
55        topScreenView);
56    }
57  
58    @Test
59    public void testInit() {
60      helpScreenPresenter.init();
61  
62      verify(helpScreenView).showHelpScreen(eq(TEST_REFRESH_DELAY), argThat(
63        new ArgumentMatcher<CommandDescription[]>() {
64          @Override
65          public boolean matches(Object o) {
66            return ((CommandDescription[]) o).length == 14;
67          }
68        }));
69    }
70  
71    @Test
72    public void testTransitionToTopScreen() {
73      assertThat(helpScreenPresenter.transitionToNextScreen(), is((ScreenView) topScreenView));
74    }
75  }