Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for AioChannelFinder implementations

  • Loading branch information...
commit da7bcfa8f69a07e93e2c403b67ac3e17136d0128 1 parent 59cd054
Norman Maurer normanmaurer authored
98 transport/src/test/java/io/netty/channel/socket/aio/AbstractAioChannelFinderTest.java
View
@@ -0,0 +1,98 @@
+package io.netty.channel.socket.aio;
+
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+
+import org.junit.Test;
+
+/*
+ * Copyright 2012 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+public abstract class AbstractAioChannelFinderTest {
+
+ protected abstract AioChannelFinder create();
+
+ @Test
+ public void testNull() throws Exception {
+ AioChannelFinder finder = create();
+ AbstractAioChannel channel = finder.findChannel(new Runnable() {
+
+ @Override
+ public void run() {
+ // Noop
+ }
+ });
+ assertNull(channel);
+ }
+
+ @Test
+ public void testRunnableWrappsAbstractAioChannel() throws Exception {
+ final Object mockChannel = createMock("mockChannel", AbstractAioChannel.class);
+ replay(mockChannel);
+
+ Runnable r = new Runnable() {
+
+ @SuppressWarnings("unused")
+ @Override
+ public void run() {
+ Object channel = mockChannel;
+ // Noop
+ }
+ };
+ AioChannelFinder finder = create();
+ AbstractAioChannel channel = finder.findChannel(r);
+ assertNotNull(channel);
+
+ AbstractAioChannel channel2 = finder.findChannel(r);
+ assertNotNull(channel2);
+ assertSame(channel2, channel);
+ verify(mockChannel);
+ reset(mockChannel);
+ }
+
+ @Test
+ public void testRunnableWrappsRunnable() throws Exception {
+ final Object mockChannel = createMock("mockChannel", AbstractAioChannel.class);
+ replay(mockChannel);
+
+ final Runnable r = new Runnable() {
+
+ @SuppressWarnings("unused")
+ @Override
+ public void run() {
+ Object channel = mockChannel;
+ // Noop
+ }
+ };
+ Runnable r2 = new Runnable() {
+
+ @SuppressWarnings("unused")
+ @Override
+ public void run() {
+ Runnable runnable = r;
+ // Noop
+ }
+ };
+ AioChannelFinder finder = create();
+ AbstractAioChannel channel = finder.findChannel(r2);
+ assertNotNull(channel);
+
+ AbstractAioChannel channel2 = finder.findChannel(r2);
+ assertNotNull(channel2);
+ assertSame(channel2, channel);
+ verify(mockChannel);
+ reset(mockChannel);
+ }
+}
25 transport/src/test/java/io/netty/channel/socket/aio/ReflectiveAioChannelFinderTest.java
View
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2012 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package io.netty.channel.socket.aio;
+
+public class ReflectiveAioChannelFinderTest extends AbstractAioChannelFinderTest {
+
+ @Override
+ protected AioChannelFinder create() {
+ return new ReflectiveAioChannelFinder();
+ }
+
+}
25 transport/src/test/java/io/netty/channel/socket/aio/UnsafeAioChannelFinderTest.java
View
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2012 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package io.netty.channel.socket.aio;
+
+public class UnsafeAioChannelFinderTest extends AbstractAioChannelFinderTest {
+
+ @Override
+ protected AioChannelFinder create() {
+ return new UnsafeAioChannelFinder();
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.