-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test for item trace (#735)
* tests: add test for item trace Item Trace has some interesting behaviour: cancelling a previous trace doesn't take effect until the audience is garbage collected. I left this as there's no "unregisterListener" function already. * chore: spotless * refactor: simplify request logger testing * fix: unregister listeners immediately * chore: spotless * refactor: change ptrace the same way * tests: cover invalid item
- Loading branch information
Showing
11 changed files
with
208 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package internal.helpers; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import net.sourceforge.kolmafia.RequestLogger; | ||
|
||
public class RequestLoggerOutput { | ||
|
||
private static ByteArrayOutputStream baos; | ||
|
||
public static void startStream() { | ||
baos = new ByteArrayOutputStream(); | ||
RequestLogger.openCustom(new PrintStream(baos)); | ||
} | ||
|
||
public static String stopStream() { | ||
RequestLogger.closeCustom(); | ||
return baos.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/net/sourceforge/kolmafia/textui/command/ItemTraceCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.sourceforge.kolmafia.textui.command; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.core.StringContains.containsString; | ||
|
||
import internal.helpers.Cleanups; | ||
import internal.helpers.Player; | ||
import internal.helpers.RequestLoggerOutput; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ItemTraceCommandTest extends AbstractCommandTestBase { | ||
|
||
public ItemTraceCommandTest() { | ||
this.command = "itrace"; | ||
} | ||
|
||
@Test | ||
public void doesNotTraceFakeItems() { | ||
execute("beefy nigiri"); | ||
|
||
RequestLoggerOutput.startStream(); | ||
Cleanups cleanups = Player.addItem("beefy nigiri"); | ||
try (cleanups) { | ||
var text = RequestLoggerOutput.stopStream(); | ||
assertThat(text, not(containsString("itrace"))); | ||
} | ||
|
||
String output = execute(""); | ||
assertThat(output, containsString("Previously watched items have been cleared")); | ||
} | ||
|
||
@Test | ||
public void tracesItemsAddedToInventory() { | ||
execute("hair spray"); | ||
|
||
RequestLoggerOutput.startStream(); | ||
Cleanups cleanups = Player.addItem("hair spray"); | ||
try (cleanups) { | ||
var text = RequestLoggerOutput.stopStream(); | ||
assertThat(text, containsString("itrace: hair spray = 1")); | ||
} | ||
} | ||
|
||
@Test | ||
public void clearsPreviousItems() { | ||
execute("hair spray"); | ||
String output = execute(""); | ||
|
||
assertThat(output, containsString("Previously watched items have been cleared")); | ||
|
||
RequestLoggerOutput.startStream(); | ||
Cleanups cleanups = Player.addItem("hair spray"); | ||
try (cleanups) { | ||
var text = RequestLoggerOutput.stopStream(); | ||
assertThat(text, not(containsString("itrace"))); | ||
} | ||
} | ||
} |
Oops, something went wrong.