2008-08-25 13:27:30 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2008-08-25 13:27:30 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* 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:
|
2008-08-25 13:27:30 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-08-25 13:27:30 +02:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 09:15:49 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-25 13:27:30 +02:00
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.channel;
|
2008-08-25 13:27:30 +02:00
|
|
|
|
2013-03-05 21:41:19 +01:00
|
|
|
import org.junit.Test;
|
2017-01-09 22:04:18 +01:00
|
|
|
import org.mockito.Mockito;
|
2008-08-25 13:27:30 +02:00
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2013-03-05 21:41:19 +01:00
|
|
|
import static org.junit.Assert.*;
|
2008-08-25 13:27:30 +02:00
|
|
|
|
|
|
|
public class CompleteChannelFutureTest {
|
|
|
|
|
|
|
|
@Test(expected = NullPointerException.class)
|
|
|
|
public void shouldDisallowNullChannel() {
|
|
|
|
new CompleteChannelFutureImpl(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldNotDoAnythingOnRemove() throws Exception {
|
2017-01-09 22:04:18 +01:00
|
|
|
Channel channel = Mockito.mock(Channel.class);
|
|
|
|
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
|
|
|
|
ChannelFutureListener l = Mockito.mock(ChannelFutureListener.class);
|
2008-08-25 13:27:30 +02:00
|
|
|
future.removeListener(l);
|
2017-01-09 22:04:18 +01:00
|
|
|
Mockito.verifyNoMoreInteractions(l);
|
|
|
|
Mockito.verifyZeroInteractions(channel);
|
2008-08-25 13:27:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testConstantProperties() throws InterruptedException {
|
2017-01-09 22:04:18 +01:00
|
|
|
Channel channel = Mockito.mock(Channel.class);
|
|
|
|
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
assertSame(channel, future.channel());
|
2008-08-25 13:27:30 +02:00
|
|
|
assertTrue(future.isDone());
|
|
|
|
assertSame(future, future.await());
|
|
|
|
assertTrue(future.await(1));
|
|
|
|
assertTrue(future.await(1, TimeUnit.NANOSECONDS));
|
|
|
|
assertSame(future, future.awaitUninterruptibly());
|
|
|
|
assertTrue(future.awaitUninterruptibly(1));
|
|
|
|
assertTrue(future.awaitUninterruptibly(1, TimeUnit.NANOSECONDS));
|
2017-01-09 22:04:18 +01:00
|
|
|
Mockito.verifyZeroInteractions(channel);
|
2008-08-25 13:27:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class CompleteChannelFutureImpl extends CompleteChannelFuture {
|
|
|
|
|
|
|
|
CompleteChannelFutureImpl(Channel channel) {
|
2013-03-05 21:41:19 +01:00
|
|
|
super(channel, null);
|
2008-08-25 13:27:30 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public Throwable cause() {
|
2008-08-25 13:27:30 +02:00
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2008-08-25 13:27:30 +02:00
|
|
|
public boolean isSuccess() {
|
|
|
|
throw new Error();
|
|
|
|
}
|
2012-05-14 16:57:23 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture sync() throws InterruptedException {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:33:37 +01:00
|
|
|
@Override
|
2012-05-14 16:57:23 +02:00
|
|
|
public ChannelFuture syncUninterruptibly() {
|
2012-01-19 05:33:37 +01:00
|
|
|
throw new Error();
|
|
|
|
}
|
2008-08-25 13:27:30 +02:00
|
|
|
}
|
|
|
|
}
|