UdpNetworkManager implements NetworkManager { @Override public ChannelFuture bindDatagramChannel(String address, int port, ChannelHandler handler) throws IllegalStateException { if (this.active.get()) { Bootstrap bootstrap = new Bootstrap().group(this.eventGroup).channel(NioDatagramChannel.class).handler(handler); return bootstrap.bind(address, port); } else { throw new IllegalStateException("Network manager is not active."); } } UdpNetworkManager(); @Override ChannelFuture bindDatagramChannel(String address, int port, ChannelHandler handler); @Override void activate(); @Override void deactivate(); @Override boolean isActive(); static final int N_THREADS; static final long SHUTDOWN_TIME; }
@Test(expected=IllegalStateException.class) public void testBindWhileInactive() { final String address = "127.0.0.1"; final int port = 60000; final ChannelHandler handler = mock(ChannelHandler.class); final NetworkManager manager = new UdpNetworkManager(); manager.bindDatagramChannel(address, port, handler); }