|
19 | 19 | import static org.junit.Assert.assertEquals; |
20 | 20 | import static org.junit.Assert.assertFalse; |
21 | 21 | import static org.junit.Assert.assertTrue; |
| 22 | +import static org.junit.Assert.fail; |
22 | 23 |
|
| 24 | +import java.net.ProtocolException; |
23 | 25 | import java.util.ArrayList; |
24 | 26 | import java.util.List; |
25 | 27 | import java.util.concurrent.TimeUnit; |
|
34 | 36 | import org.fusesource.mqtt.codec.MQTTFrame; |
35 | 37 | import org.fusesource.mqtt.codec.PUBLISH; |
36 | 38 | import org.fusesource.mqtt.codec.SUBSCRIBE; |
| 39 | +import org.fusesource.mqtt.codec.UNSUBSCRIBE; |
37 | 40 | import org.junit.Before; |
38 | 41 | import org.junit.Test; |
39 | 42 | import org.slf4j.Logger; |
@@ -254,6 +257,28 @@ public void testMessageDecoding() throws Exception { |
254 | 257 | assertEquals(MESSAGE_SIZE, publish.payload().length()); |
255 | 258 | } |
256 | 259 |
|
| 260 | + @Test |
| 261 | + public void testMessageDecodingCorrupted() throws Exception { |
| 262 | + UNSUBSCRIBE unsubscribe = new UNSUBSCRIBE(); |
| 263 | + |
| 264 | + MQTTFrame frame = unsubscribe.encode(); |
| 265 | + |
| 266 | + DataByteArrayOutputStream str = new DataByteArrayOutputStream(5); |
| 267 | + str.write(new byte[] {0,0,0,0,0}); |
| 268 | + |
| 269 | + frame.buffers[0] = str.toBuffer(); |
| 270 | + |
| 271 | + boolean decodingFailed = false; |
| 272 | + try { |
| 273 | + unsubscribe.decode(frame); |
| 274 | + } catch (ProtocolException pe) { |
| 275 | + decodingFailed = true; |
| 276 | + } |
| 277 | + if (!decodingFailed) { |
| 278 | + fail("Should have failed decoding the frame"); |
| 279 | + } |
| 280 | + } |
| 281 | + |
257 | 282 | @Test |
258 | 283 | public void testMessageDecodingPerformance() throws Exception { |
259 | 284 |
|
|
0 commit comments