|
1 | 1 | /* |
2 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 | 3 | * |
4 | | - * Copyright (c) 2009-2015 Oracle and/or its affiliates. All rights reserved. |
| 4 | + * Copyright (c) 2009-2016 Oracle and/or its affiliates. All rights reserved. |
5 | 5 | * |
6 | 6 | * The contents of this file are subject to the terms of either the GNU |
7 | 7 | * General Public License Version 2 only ("GPL") or the Common Development |
|
40 | 40 |
|
41 | 41 | package com.sun.mail.util; |
42 | 42 |
|
| 43 | +import java.lang.reflect.*; |
| 44 | + |
43 | 45 | import java.io.IOException; |
44 | 46 | import java.io.InterruptedIOException; |
45 | 47 | import java.util.Properties; |
46 | 48 | import java.util.List; |
47 | 49 | import java.util.ArrayList; |
| 50 | +import java.util.Set; |
| 51 | +import java.util.HashSet; |
48 | 52 |
|
49 | 53 | import javax.mail.*; |
50 | 54 | import javax.mail.internet.MimeMessage; |
@@ -142,6 +146,40 @@ public void testSSLSocketFactory() throws Exception { |
142 | 146 | assertTrue(sf.getSocketWrapped() || sf.getSocketCreated()); |
143 | 147 | } |
144 | 148 |
|
| 149 | + /** |
| 150 | + * Test that WriteTimeoutSocket overrides all methods from Socket. |
| 151 | + * XXX - this is kind of hacky since it depends on Method.toString |
| 152 | + */ |
| 153 | + @Test |
| 154 | + public void testOverrides() throws Exception { |
| 155 | + Set<String> socketMethods = new HashSet<String>(); |
| 156 | + Method[] m = java.net.Socket.class.getDeclaredMethods(); |
| 157 | + String className = java.net.Socket.class.getName() + "."; |
| 158 | + for (int i = 0; i < m.length; i++) { |
| 159 | + if (Modifier.isPublic(m[i].getModifiers()) && |
| 160 | + !Modifier.isStatic(m[i].getModifiers())) { |
| 161 | + String name = m[i].toString(). |
| 162 | + replace("synchronized ", ""). |
| 163 | + replace(className, ""); |
| 164 | + socketMethods.add(name); |
| 165 | + } |
| 166 | + } |
| 167 | + Set<String> wtsocketMethods = new HashSet<String>(); |
| 168 | + m = WriteTimeoutSocket.class.getDeclaredMethods(); |
| 169 | + className = WriteTimeoutSocket.class.getName() + "."; |
| 170 | + for (int i = 0; i < m.length; i++) { |
| 171 | + if (Modifier.isPublic(m[i].getModifiers())) { |
| 172 | + String name = m[i].toString(). |
| 173 | + replace("synchronized ", ""). |
| 174 | + replace(className, ""); |
| 175 | + socketMethods.remove(name); |
| 176 | + } |
| 177 | + } |
| 178 | + for (String s : socketMethods) |
| 179 | + System.out.println("WriteTimeoutSocket did not override: " + s); |
| 180 | + assertTrue(socketMethods.isEmpty()); |
| 181 | + } |
| 182 | + |
145 | 183 | private static String[] getAnonCipherSuitesArray() { |
146 | 184 | SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault(); |
147 | 185 | List<String> anon = new ArrayList<String>(); |
|
0 commit comments