harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r416713 - /incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java
Date Fri, 23 Jun 2006 13:13:12 GMT
Author: gharley
Date: Fri Jun 23 06:13:11 2006
New Revision: 416713

URL: http://svn.apache.org/viewvc?rev=416713&view=rev
Log:
HARMONY 645 : java.nio.spi.AbstractSelector needs more tests

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java?rev=416713&r1=416712&r2=416713&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/spi/AbstractSelectorTest.java
Fri Jun 23 06:13:11 2006
@@ -16,11 +16,17 @@
 package org.apache.harmony.tests.java.nio.channels.spi;
 
 import java.io.IOException;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.spi.SelectorProvider;
 
 import junit.framework.TestCase;
 
+/**
+ * Tests for AbstractSelector and register of its default implementation
+ */ 
 public class AbstractSelectorTest extends TestCase {
 
     /**
@@ -89,4 +95,65 @@
             mockSelector.superEnd();
         }
     }
+    
+    /**
+     * @tests AbstractSelector#isOpen()
+     */
+    public void test_isOpen() throws Exception {
+        Selector acceptSelector = SelectorProvider.provider().openSelector();
+        assertTrue(acceptSelector.isOpen());
+        acceptSelector.close();
+        assertFalse(acceptSelector.isOpen());
+    }
+    
+    /**
+     * @tests AbstractSelector#register(Selector,int)
+     */
+    public void test_register_LSelectorI() throws Exception {
+        Selector acceptSelector = SelectorProvider.provider().openSelector();
+        ServerSocketChannel ssc = ServerSocketChannel.open();
+        ssc.configureBlocking(false);
+
+        assertFalse(ssc.isRegistered());
+        SelectionKey acceptKey = ssc.register(acceptSelector,
+                SelectionKey.OP_ACCEPT);
+        assertTrue(ssc.isRegistered());
+        assertNotNull(acceptKey);
+        assertTrue(acceptSelector.keys().contains(acceptKey));
+    }
+
+    /**
+     * @tests AbstractSelector#register(Selector,int)
+     */
+    public void test_register_LSelectorI_error() throws IOException {
+        Selector acceptSelector = SelectorProvider.provider().openSelector();
+        ServerSocketChannel ssc = ServerSocketChannel.open();
+        ssc.configureBlocking(false);
+        acceptSelector.close();
+
+        assertFalse(acceptSelector.isOpen());
+        try {
+            ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        assertFalse(ssc.isRegistered());
+
+        acceptSelector = Selector.open();
+        ssc.configureBlocking(true);
+        try {
+            ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
+            fail("should throw IllegalBlockingModeException");
+        } catch (IllegalBlockingModeException e) {
+            // expected
+        }
+        assertFalse(ssc.isRegistered());
+        ssc.configureBlocking(false);
+        SelectionKey acceptKey = ssc.register(acceptSelector,
+                SelectionKey.OP_ACCEPT);
+        assertNotNull(acceptKey);
+        assertTrue(acceptSelector.keys().contains(acceptKey));
+        assertTrue(ssc.isRegistered());
+    }    
 }



Mime
View raw message