Improve test coverage, preparations, fixes

Removed an unnnecessary bit of code from ChatFormatter
This commit is contained in:
Norbi Peti 2020-10-29 20:31:38 +01:00
parent 7646db4487
commit dc6df53c96
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
15 changed files with 45 additions and 75 deletions

View file

@ -7,17 +7,15 @@ before_install: | # Wget BuildTools and run if cached folder not found
# grep so that download counts don't appear in log files # grep so that download counts don't appear in log files
java -jar BuildTools.jar --rev 1.12.2 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$" java -jar BuildTools.jar --rev 1.12.2 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
fi fi
cp ci/settings.xml $HOME/.m2/
language: java language: java
jdk: jdk:
- oraclejdk8 - oraclejdk11
sudo: true sudo: true
dist: trusty # Needed for Java 8, although we might not need Java 8
deploy: deploy:
- provider: releases - provider: releases
api_key: api_key:
secure: "F5YiEuD6LyRENUDMCslcSl0O0dg4IDk+nNeb4X2VLYlmb8dW9beMuIgjH8efTMeaQ3D/ntIkN0Dtf2GKvpOduhwkSbAgw4WM028X60SY9f2hmpEO3LmM4T1tKoDlI1T3BmhYP4KeTKBYn+etV1mSPbT07vUybCm/vGzvr96yMZGNFEoKsWLaEu7dZfBFULj4tXOwrLh/KO6BsdAHvZcGKWNVupPq3YoUVT0dpGcUudf5cpn+aaqMwyd709zgMbyCuqf+c5Udps43q4EKvr9z7TWxFUkGTPVVAcUVygJsi2ytuyA8TLMPq/KhYe9htnkNUnizbqv/j49xww0gVaD7OJXENJ4hAUTV4sdn1DXG45JXW+dir3V7YzbRYn3M+eCuKB2O77SXRZBkxcGtTMtCmghP9/tcRAQlXDXnxu7oAnlUVp17g/+aFApvlzZEZVx2N+fkyEe7JrUFlRCixtHyrmTLWhyV0Px9p0FHJpvSSCL0S0UKVAT/sNHYHhD5gouK7owEomEbG58XCsRDH6Et7RuDksB98ekK8brZp6S7dNIS2CVuVx1vIkXC8PzUGcpJQoztvEYUE20Axahh5s8AkE9n/O9jzs9ajcfYaHhWzYeUZzHdHllOYF9l6VoCUitTk4Sl8eJifSq3GzI+T6wGMBepZHLpe230MvBIrqGZ+Vg=" secure: "F5YiEuD6LyRENUDMCslcSl0O0dg4IDk+nNeb4X2VLYlmb8dW9beMuIgjH8efTMeaQ3D/ntIkN0Dtf2GKvpOduhwkSbAgw4WM028X60SY9f2hmpEO3LmM4T1tKoDlI1T3BmhYP4KeTKBYn+etV1mSPbT07vUybCm/vGzvr96yMZGNFEoKsWLaEu7dZfBFULj4tXOwrLh/KO6BsdAHvZcGKWNVupPq3YoUVT0dpGcUudf5cpn+aaqMwyd709zgMbyCuqf+c5Udps43q4EKvr9z7TWxFUkGTPVVAcUVygJsi2ytuyA8TLMPq/KhYe9htnkNUnizbqv/j49xww0gVaD7OJXENJ4hAUTV4sdn1DXG45JXW+dir3V7YzbRYn3M+eCuKB2O77SXRZBkxcGtTMtCmghP9/tcRAQlXDXnxu7oAnlUVp17g/+aFApvlzZEZVx2N+fkyEe7JrUFlRCixtHyrmTLWhyV0Px9p0FHJpvSSCL0S0UKVAT/sNHYHhD5gouK7owEomEbG58XCsRDH6Et7RuDksB98ekK8brZp6S7dNIS2CVuVx1vIkXC8PzUGcpJQoztvEYUE20Axahh5s8AkE9n/O9jzs9ajcfYaHhWzYeUZzHdHllOYF9l6VoCUitTk4Sl8eJifSq3GzI+T6wGMBepZHLpe230MvBIrqGZ+Vg="
file: 'Chroma-Core/target/Chroma-Core.jar' file: 'target/Chroma-Chat.jar'
on: on:
tags: true tags: true
skip_cleanup: true skip_cleanup: true

View file

@ -1,36 +0,0 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<!-- <repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository> -->
<repository>
<id>github</id>
<name>GitHub Towny Apache Maven Packages</name>
<url>https://maven.pkg.github.com/TownyAdvanced/Towny</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>NorbiPeti</username>
<password>${env.GHTOKEN}</password>
</server>
</servers>
</settings>

View file

@ -12,12 +12,6 @@
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>

View file

@ -10,7 +10,10 @@ import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
@CommandClass(modOnly = true) @CommandClass(modOnly = true, helpText = {
"Snap",
"Perfectly balanced as all things should be."
})
public class SnapCommand extends ICommand2MC { public class SnapCommand extends ICommand2MC {
@Command2.Subcommand @Command2.Subcommand
public void def(CommandSender sender) { public void def(CommandSender sender) {

View file

@ -4,6 +4,7 @@ import buttondevteam.chat.PluginMain;
import buttondevteam.core.component.channel.Channel; import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ComponentMetadata;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ListConfigData; import buttondevteam.lib.architecture.ListConfigData;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
@ -12,6 +13,7 @@ import org.bukkit.Bukkit;
/** /**
* Displays the configured messages at the set interval when someone is online. * Displays the configured messages at the set interval when someone is online.
*/ */
@ComponentMetadata(enabledByDefault = false)
public class AnnouncerComponent extends Component<PluginMain> implements Runnable { public class AnnouncerComponent extends Component<PluginMain> implements Runnable {
/** /**
* The messages to display to players. * The messages to display to players.

View file

@ -75,7 +75,7 @@ public class ChatProcessing {
.onmatch((match, builder, section) -> { .onmatch((match, builder, section) -> {
String text, link; String text, link;
if (section.Matches.size() < 2 || (text = section.Matches.get(0)).length() == 0 || (link = section.Matches.get(1)).length() == 0) if (section.Matches.size() < 2 || (text = section.Matches.get(0)).length() == 0 || (link = section.Matches.get(1)).length() == 0)
return ""; return "[MISSING LINK]"; //Doesn't actually happen, because of the regex
builder.setOpenlink(link); builder.setOpenlink(link);
return text; return text;
}).build()), }).build()),

View file

@ -166,16 +166,6 @@ public final class ChatFormatter {
i = 0; i = 0;
} }
sortSections(sections); sortSections(sections);
if (i == 0) continue;
for (int j = i - 1; j <= i + 1; j++) {
if (j < sections.size() && sections.get(j).End < sections.get(j).Start) {
DebugCommand.SendDebugMessage("Removing section: " + sections.get(j));
ChatFormatUtils.sendMessageWithPointer(str, sections.get(j).Start, sections.get(j).End);
sections.remove(j);
j--;
i = 0;
}
}
} }
} }

View file

@ -27,7 +27,6 @@ public class FormatSettings {
if (field.getBoolean(settings)) if (field.getBoolean(settings))
field.setBoolean(this, true); //Set to true if either of them are true field.setBoolean(this, true); //Set to true if either of them are true
} else if (field.get(settings) != null) { } else if (field.get(settings) != null) {
//System.out.println("Setting " + field.getType() + " " + field.getName() + " from " + field.get(this) + " to " + field.get(settings));
field.set(this, field.get(settings)); field.set(this, field.get(settings));
} }
} }

View file

@ -12,7 +12,7 @@ public class StringMatchProvider extends MatchProviderBase {
@ToString.Exclude @ToString.Exclude
private final FormatSettings settings; private final FormatSettings settings;
private int nextIndex = 0; private int nextIndex = 0;
private boolean ignoreCase; private final boolean ignoreCase;
/** /**
* Matches the given strings in the order given * Matches the given strings in the order given

View file

@ -14,7 +14,7 @@ public final class TellrawPart implements Serializable {
private boolean underlined; private boolean underlined;
private boolean strikethrough; private boolean strikethrough;
private boolean obfuscated; private boolean obfuscated;
private List<TellrawPart> extra = new ArrayList<>(); private final List<TellrawPart> extra = new ArrayList<>();
private String text; private String text;
private TellrawEvent<TellrawEvent.HoverAction> hoverEvent; private TellrawEvent<TellrawEvent.HoverAction> hoverEvent;
private TellrawEvent<TellrawEvent.ClickAction> clickEvent; private TellrawEvent<TellrawEvent.ClickAction> clickEvent;

View file

@ -8,6 +8,7 @@ import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC; import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -44,5 +45,7 @@ public class PressCommand extends ICommand2MC implements Listener {
command = event.getCommand(); command = event.getCommand();
pressers = new HashSet<>(); pressers = new HashSet<>();
startTicks = event.getRestartTicks(); startTicks = event.getRestartTicks();
if (Bukkit.getOnlinePlayers().size() > 0)
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§b-- Do /press to reset the timer. You may only press once.", command.getComponent().getRestartBroadcast());
} }
} }

View file

@ -51,7 +51,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
public static final Map<String, Color> NationColor = new HashMap<>(); public static final Map<String, Color> NationColor = new HashMap<>();
/** /**
* The amount of town colors allowed. If more than one is used, players can change how many letters to be in a specific color using /u ncolor. * The amount of town colors allowed. If more than one is used (or nation colors are enabled), players can change how many letters to be in a specific color using /u ncolor.
*/ */
public final ConfigData<Byte> colorCount = getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue); public final ConfigData<Byte> colorCount = getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue);

View file

@ -26,6 +26,7 @@ import java.util.stream.Collectors;
/** /**
* This component manages the town and nation chat. It's also needed for the TownColorComponent. * This component manages the town and nation chat. It's also needed for the TownColorComponent.
* It provides the TC and NC channels, and posts Towny messages (global, town, nation) to the correct channels for other platforms like Discord. * It provides the TC and NC channels, and posts Towny messages (global, town, nation) to the correct channels for other platforms like Discord.
* You can disable /tc and /nc in Chroma-Core's config if you only want to use the TownColorComponent.
*/ */
public class TownyComponent extends Component<PluginMain> { public class TownyComponent extends Component<PluginMain> {
public static TownyDataSource dataSource; public static TownyDataSource dataSource;

View file

@ -1,18 +1,14 @@
name: Chroma-Chat name: Chroma-Chat
main: buttondevteam.chat.PluginMain main: buttondevteam.chat.PluginMain
version: '1.0' version: '${noprefix.version}'
commands: commands:
u: u:
description: Auto-flair system. Accept or ignore flair. description: The main command for Chroma-Chat.
ooc:
description: Send message Out-of-Character.
alias: nrp
unlol: unlol:
description: Unlaugh the last laugh. description: Unlaugh the last laugh.
alias: unlaugh alias: unlaugh
mwiki: mwiki:
description: Search the wiki. description: Search the wiki.
dontrunthiscmd: null
tableflip: tableflip:
description: Flip a table. description: Flip a table.
unflip: unflip:
@ -34,9 +30,9 @@ commands:
description: Me command with Chroma support. description: Me command with Chroma support.
author: NorbiPeti author: NorbiPeti
depend: depend:
- Essentials - Essentials
- Vault - Vault
- ChromaCore - Chroma-Core
soft-depend: soft-depend:
- Dynmap-Towny - Dynmap-Towny
- Towny - Towny

View file

@ -10,7 +10,10 @@ import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickActi
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction; import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction;
import buttondevteam.core.TestPrepare; import buttondevteam.core.TestPrepare;
import buttondevteam.core.component.channel.Channel; import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.junit.Assert; import org.junit.Assert;
@ -20,6 +23,7 @@ import org.mockito.Mockito;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function;
@RunWith(ObjectTestRunner.class) @RunWith(ObjectTestRunner.class)
public class ChatFormatIT { public class ChatFormatIT {
@ -29,6 +33,7 @@ public class ChatFormatIT {
final CommandSender sender = Mockito.mock(CommandSender.class); final CommandSender sender = Mockito.mock(CommandSender.class);
DebugCommand.DebugMode = true; DebugCommand.DebugMode = true;
PluginMain.permission = Mockito.mock(Permission.class); PluginMain.permission = Mockito.mock(Permission.class);
TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class, TBMCPlayer::new);
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<>();
@ -88,6 +93,23 @@ public class ChatFormatIT {
list.add(new ChatFormatIT(sender, "***test*** test", new TellrawPart("test").setColor(Color.White) list.add(new ChatFormatIT(sender, "***test*** test", new TellrawPart("test").setColor(Color.White)
.setItalic(true).setBold(true), new TellrawPart(" test").setColor(Color.White))); .setItalic(true).setBold(true), new TellrawPart(" test").setColor(Color.White)));
list.add(new ChatFormatIT(sender, ">test message\nheh", new TellrawPart(">test message\nheh").setColor(Color.Green))); list.add(new ChatFormatIT(sender, ">test message\nheh", new TellrawPart(">test message\nheh").setColor(Color.Green)));
list.add(new ChatFormatIT(sender, "[here's a link]()", new TellrawPart("[here's a link]()").setColor(Color.White)));
list.add(new ChatFormatIT(sender, "[](fakelink)", new TellrawPart("[](fakelink)").setColor(Color.White)));
list.add(new ChatFormatIT(sender, "||this is a spoiler||", new TellrawPart("this is a spoiler").setColor(Color.White)
.setObfuscated(true).setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, "this is a spoiler"))));
Function<String, TellrawPart> whiteBoldItalic = text -> new TellrawPart(text).setColor(Color.White).setBold(true).setItalic(true);
list.add(new ChatFormatIT(sender, "***some complicated ||test message|| with [links](https://chromagaming.figytuna.com) and other __greatness__ by NorbiPeti***",
whiteBoldItalic.apply("some complicated "),
whiteBoldItalic.apply("test message").setObfuscated(true).setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, "test message")),
whiteBoldItalic.apply(" with "),
whiteBoldItalic.apply("links").setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://chromagaming.figytuna.com")).setUnderlined(true)
.setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, new TellrawPart("Click to open").setColor(Color.Blue))),
whiteBoldItalic.apply(" and other "),
whiteBoldItalic.apply("greatness").setUnderlined(true),
whiteBoldItalic.apply(" by "),
whiteBoldItalic.apply("§bNorbiPeti§r").setColor(Color.Aqua))); //§b: flair color
list.add(new ChatFormatIT(sender, "hey @console", new TellrawPart("hey ").setColor(Color.White),
new TellrawPart("@console").setColor(Color.Aqua)));
return list; return list;
} }
@ -97,10 +119,10 @@ public class ChatFormatIT {
private final TellrawPart[] extras; private final TellrawPart[] extras;
private boolean rainbowMode; private boolean rainbowMode;
public ChatFormatIT(CommandSender sender, String message, TellrawPart... expectedextras) { public ChatFormatIT(CommandSender sender, String message, TellrawPart... expectedExtras) {
this.sender = sender; this.sender = sender;
this.message = message; this.message = message;
this.extras = expectedextras; this.extras = expectedExtras;
} }
private ChatFormatIT setRainbowMode() { private ChatFormatIT setRainbowMode() {
@ -110,16 +132,14 @@ public class ChatFormatIT {
@Test @Test
public void testMessage() { public void testMessage() {
System.out.println("Testing: " + message);
ArrayList<MatchProviderBase> cfs = ChatProcessing.addFormatters(p -> true, null); ArrayList<MatchProviderBase> cfs = ChatProcessing.addFormatters(p -> true, null);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN); final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
if (rainbowMode) if (rainbowMode)
ChatProcessing.createRPC(Color.White, cfs); ChatProcessing.createRPC(Color.White, cfs);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN); final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
ChatFormatter.Combine(cfs, message, tp, null, FormatSettings.builder().color(Color.White).build()); ChatFormatter.Combine(cfs, message, tp, null, FormatSettings.builder().color(Color.White).build());
System.out.println("Testing: " + message);
// System.out.println(ChatProcessing.toJson(tp));
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN); final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
// System.out.println("Raw: " + ChatProcessing.toJson(expectedtp));
for (TellrawPart extra : extras) for (TellrawPart extra : extras)
expectedtp.addExtra(extra); expectedtp.addExtra(extra);
Assert.assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp)); Assert.assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));