• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.apache.harmony.nio.tests.java.nio.channels;
18 
19 import java.io.IOException;
20 import java.nio.channels.ClosedChannelException;
21 import java.nio.channels.SelectableChannel;
22 import java.nio.channels.SelectionKey;
23 import java.nio.channels.Selector;
24 import java.nio.channels.spi.SelectorProvider;
25 import junit.framework.TestCase;
26 
27 /*
28  * Tests for SelectableChannel
29  */
30 public class SelectableChannelTest extends TestCase {
31 
32     /**
33      * @tests SelectableChannel#register(Selector, int)
34      */
test_register_LSelectorI()35     public void test_register_LSelectorI() throws IOException {
36         MockSelectableChannel msc = new MockSelectableChannel();
37         // Verify that calling register(Selector, int) leads to the method
38         // register(Selector, int, Object) being called with a null value
39         // for the third argument.
40         msc.register(Selector.open(), SelectionKey.OP_ACCEPT);
41         assertTrue(msc.isCalled);
42     }
43 
44     private class MockSelectableChannel extends SelectableChannel {
45 
46         private boolean isCalled = false;
47 
blockingLock()48         public Object blockingLock() {
49             return null;
50         }
51 
configureBlocking(boolean block)52         public SelectableChannel configureBlocking(boolean block)
53                 throws IOException {
54             return null;
55         }
56 
isBlocking()57         public boolean isBlocking() {
58             return false;
59         }
60 
isRegistered()61         public boolean isRegistered() {
62             return false;
63         }
64 
keyFor(Selector sel)65         public SelectionKey keyFor(Selector sel) {
66             return null;
67         }
68 
provider()69         public SelectorProvider provider() {
70             return null;
71         }
72 
register(Selector sel, int ops, Object att)73         public SelectionKey register(Selector sel, int ops, Object att)
74                 throws ClosedChannelException {
75             if (null == att) {
76                 isCalled = true;
77             }
78             return null;
79         }
80 
validOps()81         public int validOps() {
82             return 0;
83         }
84 
implCloseChannel()85         protected void implCloseChannel() throws IOException {
86             // empty
87         }
88     }
89 }
90