001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Boris V. Kuznetsov
020: * @version $Revision$
021: */package javax.net;
022:
023: import java.io.IOException;
024: import java.net.InetAddress;
025: import java.net.Socket;
026: import java.net.SocketException;
027: import java.net.UnknownHostException;
028:
029: import junit.framework.TestCase;
030:
031: /**
032: * Tests for <code>SocketFactory</code> class methods.
033: */
034: public class SocketFactoryTest extends TestCase {
035:
036: /*
037: * Class under test for java.net.Socket createSocket()
038: */
039: public final void testCreateSocket() {
040: SocketFactory sf = new MySocketFactory();
041: try {
042: sf.createSocket();
043: fail("No expected SocketException");
044: } catch (SocketException e) {
045: } catch (IOException e) {
046: fail(e.toString());
047: }
048: }
049:
050: /*
051: * Class under test for javax.net.SocketFactory getDefault()
052: */
053: public final void testGetDefault() {
054: SocketFactory sf = SocketFactory.getDefault();
055: Socket s;
056: if (!(sf instanceof DefaultSocketFactory)) {
057: fail("Incorrect class instance");
058: }
059: try {
060: s = sf.createSocket("localhost", 8082);
061: s.close();
062: } catch (IOException e) {
063: }
064: try {
065: s = sf.createSocket("localhost", 8081, InetAddress
066: .getLocalHost(), 8082);
067: s.close();
068: } catch (IOException e) {
069: }
070: try {
071: s = sf.createSocket(InetAddress.getLocalHost(), 8081);
072: s.close();
073: } catch (IOException e) {
074: }
075: try {
076: s = sf.createSocket(InetAddress.getLocalHost(), 8081,
077: InetAddress.getLocalHost(), 8082);
078: s.close();
079: } catch (IOException e) {
080: }
081: }
082: }
083:
084: class MySocketFactory extends SocketFactory {
085: public Socket createSocket(String host, int port)
086: throws IOException, UnknownHostException {
087: throw new IOException();
088: }
089:
090: public Socket createSocket(String host, int port,
091: InetAddress localHost, int localPort) throws IOException,
092: UnknownHostException {
093: throw new IOException();
094: }
095:
096: public Socket createSocket(InetAddress host, int port)
097: throws IOException {
098: throw new IOException();
099: }
100:
101: public Socket createSocket(InetAddress address, int port,
102: InetAddress localAddress, int localPort) throws IOException {
103: throw new IOException();
104: }
105:
106: }
|