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  
26  import java.util.concurrent.Executor;
27  
28  import org.junit.Assert;
29  import org.junit.Before;
30  import org.junit.Test;
31  import org.mockito.ArgumentCaptor;
32  
33  /**
34   * Unit test for {@link UnorderHandlerExecutor}
35   * 
36   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
37   */
38  public class UnorderHandlerExecutorTest {
39      private UnorderHandlerExecutor handlerExecutor;
40  
41      private Executor executor;
42  
43      @Before
44      public void setup() {
45          executor = mock(Executor.class);
46          handlerExecutor = new UnorderHandlerExecutor(executor);
47      }
48  
49      @Test
50      public void null_param() {
51          try {
52              new UnorderHandlerExecutor(null);
53              Assert.fail();
54          } catch (IllegalArgumentException ex) {
55              // happy
56          }
57      }
58  
59      @Test
60      public void enqueu_event() {
61          // prepare
62          Event e = mock(Event.class);
63  
64          // run
65          handlerExecutor.execute(e);
66  
67          // verify
68          ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
69          verify(executor).execute(captor.capture());
70  
71          captor.getValue().run();
72          verify(e).visit(any(EventVisitor.class));
73  
74      }
75  }