1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.net.telnet;
18
19 import static org.junit.jupiter.api.Assertions.assertFalse;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import org.junit.jupiter.api.Test;
23
24 /**
25 * The TelnetOptionHandlerTest is the abstract class for testing TelnetOptionHandler. It can be used to derive the actual test classes for TelnetOptionHadler
26 * derived classes, by adding creation of three new option handlers and testing of the specific subnegotiation behavior.
27 */
28 public abstract class AbstractTelnetOptionHandlerTest {
29 TelnetOptionHandler opthand1;
30 TelnetOptionHandler opthand2;
31 TelnetOptionHandler opthand3;
32
33 /**
34 * test of the constructors. The derived class may add test of the option code.
35 */
36 void testConstructors() {
37 // add test of the option code
38 assertFalse(opthand1.getInitLocal());
39 assertFalse(opthand1.getInitRemote());
40 assertFalse(opthand1.getAcceptLocal());
41 assertFalse(opthand1.getAcceptRemote());
42
43 assertTrue(opthand2.getInitLocal());
44 assertTrue(opthand2.getInitRemote());
45 assertTrue(opthand2.getAcceptLocal());
46 assertTrue(opthand2.getAcceptRemote());
47
48 assertFalse(opthand3.getInitLocal());
49 assertFalse(opthand3.getInitRemote());
50 assertFalse(opthand3.getAcceptLocal());
51 assertFalse(opthand3.getAcceptRemote());
52 }
53
54 /**
55 * test of setDo/getDo
56 */
57 @Test
58 void testDo() {
59 opthand2.setDo(true);
60 opthand3.setDo(false);
61
62 assertFalse(opthand1.getDo());
63 assertTrue(opthand2.getDo());
64 assertFalse(opthand3.getDo());
65 }
66
67 /**
68 * test of setWill/getWill
69 */
70 @Test
71 void testWill() {
72 opthand2.setWill(true);
73 opthand3.setWill(false);
74
75 assertFalse(opthand1.getWill());
76 assertTrue(opthand2.getWill());
77 assertFalse(opthand3.getWill());
78 }
79 }