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,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.service.executor;
21  
22  import static org.mockito.Matchers.any;
23  import static org.mockito.Mockito.mock;
24  import static org.mockito.Mockito.verify;
25  import static org.mockito.Mockito.verifyNoMoreInteractions;
26  import static org.mockito.Mockito.when;
27  
28  import org.apache.mina.api.IoSession;
29  import org.junit.Test;
30  
31  /**
32   * Unit test for {@link OrderedHandlerExecutor}.
33   * 
34   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
35   */
36  public class OrderedHandlerExecutorTest {
37      private OrderedHandlerExecutor executor;
38  
39      @Test
40      public void execute_open_events() throws InterruptedException {
41          // prepare
42          executor = new OrderedHandlerExecutor(1, 1);
43          IoSession session = mock(IoSession.class);
44          when(session.getId()).thenReturn(12345L);
45  
46          Event evt = mock(Event.class);
47          when(evt.getSession()).thenReturn(session);
48  
49          // run
50  
51          executor.execute(evt);
52  
53          // verify
54          verify(session).getId();
55          verify(evt).getSession();
56          Thread.sleep(200);
57          verify(evt).visit(any(EventVisitor.class));
58          verifyNoMoreInteractions(evt, session);
59      }
60  }