01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Boris V. Kuznetsov
20: * @version $Revision$
21: */package javax.net;
22:
23: import java.io.IOException;
24: import java.net.InetAddress;
25: import java.net.ServerSocket;
26: import java.net.SocketException;
27: import java.net.UnknownHostException;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * Tests for <code>ServerSocketFactory</code> class constructors and methods.
33: */
34:
35: public class ServerSocketFactoryTest extends TestCase {
36: /*
37: * Class under test for java.net.ServerSocket createServerSocket()
38: */
39: public final void testCreateServerSocket() {
40: ServerSocketFactory sf = new MyServerSocketFactory();
41: try {
42: sf.createServerSocket();
43: fail("No expected SocketException");
44: } catch (SocketException e) {
45: } catch (IOException e) {
46: fail(e.toString());
47: }
48: }
49:
50: /*
51: * Class under test for javax.net.ServerSocketFactory getDefault()
52: */
53: public final void testGetDefault() {
54: ServerSocketFactory sf = ServerSocketFactory.getDefault();
55: ServerSocket s;
56: if (!(sf instanceof DefaultServerSocketFactory)) {
57: fail("Incorrect class instance");
58: }
59: try {
60: s = sf.createServerSocket(0);
61: s.close();
62: } catch (IOException e) {
63: }
64: try {
65: s = sf.createServerSocket(0, 50);
66: s.close();
67: } catch (IOException e) {
68: }
69: try {
70: s = sf
71: .createServerSocket(0, 50, InetAddress
72: .getLocalHost());
73: s.close();
74: } catch (IOException e) {
75: }
76: }
77: }
78:
79: class MyServerSocketFactory extends ServerSocketFactory {
80: public ServerSocket createServerSocket(int port)
81: throws IOException, UnknownHostException {
82: throw new IOException();
83: }
84:
85: public ServerSocket createServerSocket(int port, int backlog)
86: throws IOException, UnknownHostException {
87: throw new IOException();
88: }
89:
90: public ServerSocket createServerSocket(int port, int backlog,
91: InetAddress ifAddress) throws IOException {
92: throw new IOException();
93: }
94: }
|