/* * Copyright (c) 2010-2017 Nathan Rajlich * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package org.java_websocket.framing; import org.java_websocket.exceptions.InvalidDataException; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** * JUnit Test for the PingFrame class */ public class PingFrameTest { @Test public void testConstructor() { PingFrame frame = new PingFrame(); assertEquals("Opcode must be equal", Framedata.Opcode.PING , frame.getOpcode()); assertEquals("Fin must be set", true , frame.isFin()); assertEquals("TransferedMask must not be set", false , frame.getTransfereMasked()); assertEquals("Payload must be empty", 0 , frame.getPayloadData().capacity()); assertEquals("RSV1 must be false", false , frame.isRSV1()); assertEquals("RSV2 must be false", false , frame.isRSV2()); assertEquals("RSV3 must be false", false , frame.isRSV3()); try { frame.isValid(); } catch (InvalidDataException e) { fail("InvalidDataException should not be thrown"); } } @Test public void testExtends() { PingFrame frame = new PingFrame(); assertEquals("Frame must extend dataframe", true, frame instanceof ControlFrame); } @Test public void testIsValid() { PingFrame frame = new PingFrame(); try { frame.isValid(); } catch (InvalidDataException e) { fail("InvalidDataException should not be thrown"); } frame.setFin(false); try { frame.isValid(); fail("InvalidDataException should be thrown"); } catch (InvalidDataException e) { //Fine } frame.setFin(true); frame.setRSV1(true); try { frame.isValid(); fail("InvalidDataException should be thrown"); } catch (InvalidDataException e) { //Fine } frame.setRSV1(false); frame.setRSV2(true); try { frame.isValid(); fail("InvalidDataException should be thrown"); } catch (InvalidDataException e) { //Fine } frame.setRSV2(false); frame.setRSV3(true); try { frame.isValid(); fail("InvalidDataException should be thrown"); } catch (InvalidDataException e) { //Fine } } }