tests: improved testable dialogs with better/colored logs and asserts (part of #13643, #13638);

This commit is contained in:
Oleg Agafonov 2025-06-14 21:10:32 +04:00
parent d43e96eaf2
commit a98f72649a
17 changed files with 123 additions and 83 deletions

View file

@ -11,19 +11,19 @@ public class AmountTestableResult extends BaseTestableResult {
int amount = 0;
public void save(boolean status, List<String> info, int amount) {
this.save(status, info);
public void onFinish(boolean status, List<String> info, int amount) {
this.onFinish(status, info);
this.amount = amount;
}
@Override
public boolean isOk() {
return true;
public Boolean getResAssert() {
return null; // TODO: implement
}
@Override
public void clear() {
super.clear();
public void onClear() {
super.onClear();
this.amount = 0;
}
}

View file

@ -42,7 +42,7 @@ class AnnounceXTestableDialog extends BaseTestableDialog {
List<String> res = new ArrayList<>();
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
((AmountTestableResult) this.getResult()).save(true, res, chooseRes);
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -44,13 +44,13 @@ abstract class BaseTestableDialog implements TestableDialog {
@Override
public void prepare() {
this.result.clear();
this.result.onClear();
}
@Override
final public void showResult(Player player, Game game) {
// show message with result
game.informPlayer(player, String.join("<br>", getResult().getInfo()));
game.informPlayer(player, String.join("<br>", getResult().getResDetails()));
// reset game and gui (in most use cases it must return to player's priority)
game.firePriorityEvent(player.getId());
}

View file

@ -10,41 +10,41 @@ import java.util.List;
*/
public class BaseTestableResult implements TestableResult {
boolean saved = false;
boolean status = false;
List<String> info = new ArrayList<>();
boolean isFinished = false;
boolean resStatus = false;
List<String> resInfo = new ArrayList<>();
@Override
public boolean getStatus() {
return this.status;
public boolean getResStatus() {
return this.resStatus;
}
@Override
public List<String> getInfo() {
return this.info;
public List<String> getResDetails() {
return this.resInfo;
}
@Override
public void save(boolean status, List<String> info) {
this.saved = true;
this.status = status;
this.info = info;
public Boolean getResAssert() {
return null; // TODO: implement
}
@Override
public boolean isOk() {
return true;
public void onFinish(boolean resStatus, List<String> resDetails) {
this.isFinished = true;
this.resStatus = resStatus;
this.resInfo = resDetails;
}
@Override
public boolean isSaved() {
return this.saved;
public boolean isFinished() {
return this.isFinished;
}
@Override
public void clear() {
this.saved = false;
this.status = false;
this.info.clear();
public void onClear() {
this.isFinished = false;
this.resStatus = false;
this.resInfo.clear();
}
}

View file

@ -11,19 +11,19 @@ public class ChoiceTestableResult extends BaseTestableResult {
String choice = null;
public void save(boolean status, List<String> info, String choice) {
this.save(status, info);
public void onFinish(boolean status, List<String> info, String choice) {
this.onFinish(status, info);
this.choice = choice;
}
@Override
public boolean isOk() {
return true;
public Boolean getResAssert() {
return null; // TODO: implement
}
@Override
public void clear() {
super.clear();
public void onClear() {
super.onClear();
this.choice = null;
}
}

View file

@ -54,7 +54,7 @@ class ChooseAmountTestableDialog extends BaseTestableDialog {
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
}
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -70,7 +70,7 @@ class ChooseCardsTestableDialog extends BaseTestableDialog {
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
}
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -52,7 +52,7 @@ class ChooseChoiceTestableDialog extends BaseTestableDialog {
res.add(String.format("* selected value: %s", choice));
}
((ChoiceTestableResult) this.getResult()).save(chooseRes, res, choice);
((ChoiceTestableResult) this.getResult()).onFinish(chooseRes, res, choice);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -56,7 +56,7 @@ class ChoosePileTestableDialog extends BaseTestableDialog {
res.add(getGroup() + " - " + this.getName() + " - " + (chooseRes ? "TRUE" : "FALSE"));
res.add(" * selected pile: " + (chooseRes ? "pile 1" : "pile 2"));
this.getResult().save(chooseRes, res);
this.getResult().onFinish(chooseRes, res);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -74,14 +74,14 @@ class ChooseTargetTestableDialog extends BaseTestableDialog {
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
}
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
}
private ChooseTargetTestableDialog aiMustChoose(boolean status, int count) {
private ChooseTargetTestableDialog aiMustChoose(boolean resStatus, int targetsCount) {
TargetTestableResult res = ((TargetTestableResult) this.getResult());
res.aiAssert = true;
res.aiMustChooseStatus = status;
res.aiMustChooseTargetsCount = count;
res.aiAssertEnabled = true;
res.aiAssertResStatus = resStatus;
res.aiAssertTargetsCount = targetsCount;
return this;
}

View file

@ -60,7 +60,7 @@ class ChooseUseTestableDialog extends BaseTestableDialog {
List<String> res = new ArrayList<>();
res.add(chooseRes ? "TRUE" : "FALSE");
this.getResult().save(chooseRes, res);
this.getResult().onFinish(chooseRes, res);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -44,7 +44,7 @@ class GetAmountTestableDialog extends BaseTestableDialog {
List<String> res = new ArrayList<>();
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
((AmountTestableResult) this.getResult()).save(true, res, chooseRes);
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -82,7 +82,7 @@ class GetMultiAmountTestableDialog extends BaseTestableDialog {
}
res.add("total selected: " + selectedTotal);
((MultiAmountTestableResult) this.getResult()).save(true, res, chooseRes);
((MultiAmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
}
static public void register(TestableDialogsRunner runner) {

View file

@ -12,19 +12,19 @@ public class MultiAmountTestableResult extends BaseTestableResult {
List<Integer> values = new ArrayList<>();
public void save(boolean status, List<String> info, List<Integer> values) {
this.save(status, info);
public void onFinish(boolean status, List<String> info, List<Integer> values) {
this.onFinish(status, info);
this.values = values;
}
@Override
public boolean isOk() {
return true;
public Boolean getResAssert() {
return null; // TODO: implement
}
@Override
public void clear() {
super.clear();
public void onClear() {
super.onClear();
this.values.clear();
}
}

View file

@ -13,33 +13,33 @@ public class TargetTestableResult extends BaseTestableResult {
Target target = null;
boolean aiAssert = false;
boolean aiMustChooseStatus = false;
int aiMustChooseTargetsCount = 0;
boolean aiAssertEnabled = false;
boolean aiAssertResStatus = false;
int aiAssertTargetsCount = 0;
public void save(boolean status, List<String> info, Target target) {
this.save(status, info);
public void onFinish(boolean status, List<String> info, Target target) {
this.onFinish(status, info);
this.target = target;
}
@Override
public boolean isOk() {
if (!this.aiAssert) {
return true;
public Boolean getResAssert() {
if (!this.aiAssertEnabled) {
return null;
}
// not finish
// not finished
if (this.target == null) {
return false;
return null;
}
// wrong choose
if (this.getStatus() != this.aiMustChooseStatus) {
if (this.getResStatus() != this.aiAssertResStatus) {
return false;
}
// wrong targets
if (this.target.getTargets().size() != this.aiMustChooseTargetsCount) {
if (this.target.getTargets().size() != this.aiAssertTargetsCount) {
return false;
}
@ -48,8 +48,8 @@ public class TargetTestableResult extends BaseTestableResult {
}
@Override
public void clear() {
super.clear();
public void onClear() {
super.onClear();
this.target = null;
}
}

View file

@ -9,21 +9,25 @@ import java.util.List;
*/
public interface TestableResult {
boolean getStatus();
/**
* Dialog's result
*/
boolean getResStatus();
List<String> getInfo();
/**
* Dialog's detail result
*/
List<String> getResDetails();
/**
* Save new result after show dialog
*
* @param status result of choice dialog call
* @param info detail result to show in GUI
*/
void save(boolean status, List<String> info);
void onFinish(boolean resStatus, List<String> resDetails);
boolean isSaved();
boolean isFinished();
void clear();
void onClear();
boolean isOk();
Boolean getResAssert();
}