Crossfire JXClient, Trunk
PacketWatcherTest.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.scripts;
24 
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import org.jetbrains.annotations.NotNull;
31 import org.junit.Assert;
32 import org.junit.Test;
33 
38 public class PacketWatcherTest {
39 
43  @Test
44  public void test1() {
45  final Collection<ReceivedPacketListener> listeners = new ArrayList<>();
47 
48  @Override
49  @SuppressWarnings("MethodDoesntCallSuperMethod")
50  public void addPacketWatcherListener(@NotNull final ReceivedPacketListener listener) {
51  listeners.add(listener);
52  }
53 
54  @Override
55  @SuppressWarnings("MethodDoesntCallSuperMethod")
56  public void removePacketWatcherListener(@NotNull final ReceivedPacketListener listener) {
57  listeners.remove(listener);
58  }
59 
60  };
62  final PacketWatcher packetWatcher = new PacketWatcher(connection, scriptProcess);
63 
64  for (ReceivedPacketListener listener : listeners) {
65  listener.process("command", () -> "");
66  }
67  Assert.assertEquals("", scriptProcess.getAndClearEvents());
68 
69  packetWatcher.addCommand("command");
70 
71  for (ReceivedPacketListener listener : listeners) {
72  //noinspection SpellCheckingInspection
73  listener.process("comman", () -> "");
74  listener.process("command", () -> "");
75  //noinspection SpellCheckingInspection
76  listener.process("commandx", () -> "");
77  }
78  //noinspection SpellCheckingInspection
79  Assert.assertEquals("writeToScript: watch command\n"+"writeToScript: watch commandx\n", scriptProcess.getAndClearEvents());
80  }
81 
82 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.scripts.TestScriptProcess.newTestScriptProcess
static TestScriptProcess newTestScriptProcess(@NotNull final String scriptCommands)
Definition: TestScriptProcess.java:103
com.realtime.crossfire.jxclient.scripts.PacketWatcher
Definition: PacketWatcher.java:38
com.realtime.crossfire.jxclient.scripts.TestScriptProcess
Definition: TestScriptProcess.java:65
com.realtime.crossfire.jxclient.scripts.PacketWatcher.addCommand
void addCommand(@NotNull final String command)
Definition: PacketWatcher.java:137
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.server.server.ReceivedPacketListener
Definition: ReceivedPacketListener.java:33
com.realtime.crossfire.jxclient.server.crossfire.TestCrossfireServerConnection
Definition: TestCrossfireServerConnection.java:39
com.realtime.crossfire.jxclient.server.server
Definition: DefaultServerConnection.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.scripts.PacketWatcherTest.test1
void test1()
Definition: PacketWatcherTest.java:44
com.realtime
com
com.realtime.crossfire.jxclient.scripts.TestScriptProcess.getAndClearEvents
String getAndClearEvents()
Definition: TestScriptProcess.java:223
com.realtime.crossfire.jxclient.scripts.PacketWatcherTest
Definition: PacketWatcherTest.java:38