refactor: Address .editorconfig violations

This commit is contained in:
NotMyFault
2021-10-18 23:09:21 +02:00
parent 9a33789e41
commit bd9476a175
53 changed files with 1415 additions and 1127 deletions

View File

@ -2,8 +2,6 @@ package com.fastasyncworldedit.core;
/**
* An internal FAWE class not meant for public use.
*
* @hidden
**/
public class FaweVersion {

View File

@ -3,7 +3,6 @@ package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.command.tool.ResettableTool;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;

View File

@ -331,7 +331,7 @@ public class Config {
/**
* Get the field for a specific config node and instance.
*
* <p>
* As expiry can have multiple blocks there will be multiple instances
*
* @param split the node (split by period)

View File

@ -228,6 +228,7 @@ public class Settings extends Config {
" - \"extended[true:false]\""
})
public List<String> REMAP_PROPERTIES = new ArrayList<>();
}
public static class HISTORY {

View File

@ -154,7 +154,7 @@ public class DisallowedBlocksExtent extends AbstractDelegateExtent implements IB
}
}
if (remaps == null || remaps.isEmpty()) {
blocks[i] = block;
blocks[i] = block;
continue;
}
for (PropertyRemap<?> remap : remaps) {

View File

@ -5,7 +5,6 @@ import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.util.MemUtil;
import com.fastasyncworldedit.core.util.Permission;
import com.fastasyncworldedit.core.util.WEManager;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;

View File

@ -12,6 +12,7 @@ public abstract class SimpleClipboard implements Clipboard {
private final int volume;
private BlockVector3 offset;
private BlockVector3 origin;
SimpleClipboard(BlockVector3 dimensions, BlockVector3 offset) {
this.size = dimensions;
this.offset = offset;

View File

@ -2,7 +2,6 @@ package com.fastasyncworldedit.core.history.changeset;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.history.change.BlockChange;

View File

@ -6,7 +6,6 @@ import java.lang.reflect.Field;
/**
* This is an internal class not meant to be used outside the FAWE internals.
* @hidden
*/
public class UnsafeUtility {

View File

@ -45,12 +45,12 @@ import com.fastasyncworldedit.core.function.pattern.ExistingPattern;
import com.fastasyncworldedit.core.function.visitor.DirectionalVisitor;
import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet;
import com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
import com.fastasyncworldedit.core.math.MutableBlockVector2;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.math.MutableVector3;
import com.fastasyncworldedit.core.math.random.SimplexNoise;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.queue.implementation.preloader.Preloader;
import com.fastasyncworldedit.core.regions.RegionWrapper;
import com.fastasyncworldedit.core.util.ExtentTraverser;

View File

@ -52,9 +52,9 @@ import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
import com.fastasyncworldedit.core.function.mask.IdMask;
import com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.math.heightmap.ScalableHeightMap;
import com.fastasyncworldedit.core.math.heightmap.ScalableHeightMap.Shape;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.StringMan;

View File

@ -39,7 +39,6 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;

View File

@ -36,7 +36,6 @@ import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;

View File

@ -513,15 +513,20 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
if (actor != null) {
if (!actor.hasPermission("worldedit.anyblock")
&& worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId().toLowerCase(Locale.ROOT))) {
throw new DisallowedUsageException(Caption.of("worldedit.error.disallowed-block", TextComponent.of(blockType.getId())));
throw new DisallowedUsageException(Caption.of(
"worldedit.error.disallowed-block",
TextComponent.of(blockType.getId())
));
}
FaweLimit limit = actor.getLimit();
if (!limit.isUnlimited()) {
// No need to account for blocked states/properties as it will simply return false in the equality check
// during contains.
if (limit.DISALLOWED_BLOCKS.contains(blockType.getId().toLowerCase(Locale.ROOT))) {
throw new DisallowedUsageException(Caption.of("fawe.error.limit.disallowed-block",
TextComponent.of(blockType.getId())));
throw new DisallowedUsageException(Caption.of(
"fawe.error.limit.disallowed-block",
TextComponent.of(blockType.getId())
));
}
}
}

View File

@ -159,9 +159,9 @@ public class CraftScriptContext extends CraftScriptEnvironment {
/**
* Immediately terminate execution of the script, but without a failure message.
*
* <p>
* This exits by throwing an exception, which if caught will prevent
* the script from exiting
* the script from exiting
*/
public void exit() {
throw new ReturnException(null);

View File

@ -344,7 +344,10 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
//FAWE end
BlockType type = this.getBlockType();
// Lazily initialize the map
Map<? extends Property<?>, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property<?>, Object>) this::getState);
Map<? extends Property<?>, Object> map = Maps.asMap(
type.getPropertiesSet(),
(Function<Property<?>, Object>) this::getState
);
//noinspection RedundantCast - This is required for compilation, etc.
return Collections.unmodifiableMap((Map<Property<?>, Object>) map);
//FAWE end

View File

@ -166,8 +166,8 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*
* @param compoundTag The NBT Data to apply
* @return The BaseBlock
* This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
* This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "toBaseBlock",

View File

@ -20,16 +20,13 @@
package com.sk89q.worldedit.world.chunk;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* A 16 by 16 block chunk.
@ -46,6 +43,7 @@ public interface Chunk {
BaseBlock getBlock(BlockVector3 position) throws DataException;
//FAWE start - biome and entity restore
/**
* Get a biome.
*
@ -59,6 +57,7 @@ public interface Chunk {
/**
* Get the stored entities.
*
* @return list of stored entities
*/
default List<BaseEntity> getEntities() throws DataException {

View File

@ -149,8 +149,10 @@ public final class LegacyMapper {
// if it's still null, both fixer and default failed
if (state == null) {
LOGGER.error("Unknown block: {}. Neither the DataFixer nor defaulting worked to recognize this block.",
value);
LOGGER.error(
"Unknown block: {}. Neither the DataFixer nor defaulting worked to recognize this block.",
value
);
} else {
// it's not null so one of them succeeded, now use it
blockToStringMap.put(state, id);

View File

@ -28,8 +28,6 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.world.DataException;

View File

@ -87,6 +87,7 @@ public abstract class ChunkStore implements Closeable {
public abstract CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException;
//FAWE start - biome and entity restore
/**
* Get the tag for the entities stored in a chunk from the entities folder. 1.17+ use only.
* If an error occurs, returns null.

File diff suppressed because it is too large Load Diff

View File

@ -147,7 +147,7 @@ public class CommandContextTest {
public void testSlice() {
try {
CommandContext context = new CommandContext("foo bar baz");
assertArrayEquals(new String[] { "foo", "bar", "baz" }, context.getSlice(0));
assertArrayEquals(new String[]{"foo", "bar", "baz"}, context.getSlice(0));
} catch (CommandException e) {
LOGGER.warn("Error", e);
@ -165,4 +165,5 @@ public class CommandContextTest {
fail("Error creating CommandContext");
}
}
}

View File

@ -37,22 +37,23 @@ class CommandArgParserTest {
@Test
void testArgumentParsing() {
assertEquals(ImmutableList.of(
Substring.wrap("", 0, 0)
Substring.wrap("", 0, 0)
), argParse(""));
assertEquals(ImmutableList.of(
Substring.wrap("ab", 0, 2)
Substring.wrap("ab", 0, 2)
), argParse("ab"));
assertEquals(ImmutableList.of(
Substring.wrap("", 0, 0),
Substring.wrap("", 1, 1)
Substring.wrap("", 0, 0),
Substring.wrap("", 1, 1)
), argParse(" "));
assertEquals(ImmutableList.of(
Substring.wrap("a", 0, 1),
Substring.wrap("", 2, 2)
Substring.wrap("a", 0, 1),
Substring.wrap("", 2, 2)
), argParse("a "));
assertEquals(ImmutableList.of(
Substring.wrap("a", 0, 1),
Substring.wrap("b", 2, 3)
Substring.wrap("a", 0, 1),
Substring.wrap("b", 2, 3)
), argParse("a b"));
}
}

View File

@ -122,4 +122,5 @@ class BaseExpressionTest {
expression.optimize();
return expression;
}
}

View File

@ -42,39 +42,39 @@ class ExpressionTest extends BaseExpressionTest {
@TestFactory
public Stream<DynamicNode> testEvaluate() throws ExpressionException {
List<ExpressionTestCase> testCases = ImmutableList.of(
// basic arithmetic
testCase("1 - 2 + 3", 2),
// unary ops
testCase("2 + +4", 6),
testCase("2 - -4", 6),
testCase("2 * -4", -8),
// check functions
testCase("sin(5)", sin(5)),
testCase("atan2(3, 4)", atan2(3, 4)),
testCase("min(1, 2)", 1),
testCase("max(1, 2)", 2),
testCase("max(1, 2, 3, 4, 5)", 5),
// check conditionals
testCase("0 || 5", 5),
testCase("2 || 5", 2),
testCase("2 && 5", 5),
testCase("5 && 0", 0),
// check ternaries
testCase("false ? 1 : 2", 2),
testCase("true ? 1 : 2", 1),
// - ternary binds inside
testCase("true ? true ? 1 : 2 : 3", 1),
testCase("true ? false ? 1 : 2 : 3", 2),
testCase("false ? true ? 1 : 2 : 3", 3),
testCase("false ? false ? 1 : 2 : 3", 3),
// check return
testCase("return 1; 0", 1)
// basic arithmetic
testCase("1 - 2 + 3", 2),
// unary ops
testCase("2 + +4", 6),
testCase("2 - -4", 6),
testCase("2 * -4", -8),
// check functions
testCase("sin(5)", sin(5)),
testCase("atan2(3, 4)", atan2(3, 4)),
testCase("min(1, 2)", 1),
testCase("max(1, 2)", 2),
testCase("max(1, 2, 3, 4, 5)", 5),
// check conditionals
testCase("0 || 5", 5),
testCase("2 || 5", 2),
testCase("2 && 5", 5),
testCase("5 && 0", 0),
// check ternaries
testCase("false ? 1 : 2", 2),
testCase("true ? 1 : 2", 1),
// - ternary binds inside
testCase("true ? true ? 1 : 2 : 3", 1),
testCase("true ? false ? 1 : 2 : 3", 2),
testCase("false ? true ? 1 : 2 : 3", 3),
testCase("false ? false ? 1 : 2 : 3", 3),
// check return
testCase("return 1; 0", 1)
);
return testCases.stream()
.map(testCase -> dynamicTest(
testCase.getExpression(),
() -> checkTestCase(testCase)
));
.map(testCase -> dynamicTest(
testCase.getExpression(),
() -> checkTestCase(testCase)
));
}
@Test
@ -82,8 +82,10 @@ class ExpressionTest extends BaseExpressionTest {
assertEquals(8, compile("foo+bar", "foo", "bar").evaluate(5D, 3D), 0);
// variables need to be assigned first
EvaluationException ex = assertThrows(EvaluationException.class,
() -> simpleEval("a*=5"));
EvaluationException ex = assertThrows(
EvaluationException.class,
() -> simpleEval("a*=5")
);
assertTrue(ex.getMessage().contains("not initialized yet"));
// can't modify e, pi, true, false
@ -93,11 +95,11 @@ class ExpressionTest extends BaseExpressionTest {
@TestFactory
Stream<DynamicNode> testModifyConstants() {
return Stream.of("e", "pi", "true", "false").map(constant ->
dynamicTest(constant, () -> {
EvaluationException ex = assertThrows(EvaluationException.class, () ->
simpleEval(constant + "++"));
assertTrue(ex.getMessage().endsWith("'" + constant + "' is not a variable"));
}));
dynamicTest(constant, () -> {
EvaluationException ex = assertThrows(EvaluationException.class, () ->
simpleEval(constant + "++"));
assertTrue(ex.getMessage().endsWith("'" + constant + "' is not a variable"));
}));
}
@Test
@ -214,45 +216,63 @@ class ExpressionTest extends BaseExpressionTest {
public void testErrors() {
// test lexer errors
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("#"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("#")
);
assertEquals(0, e.getPosition(), "Error position");
}
// test parser errors
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("x"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("x")
);
assertEquals(0, e.getPosition(), "Error position");
}
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("x()"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("x()")
);
assertEquals(0, e.getPosition(), "Error position");
}
{
// verify that you must return a value
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("return"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("return")
);
assertEquals(6, e.getPosition(), "Error position");
}
assertThrows(ExpressionException.class,
() -> compile("("));
assertThrows(ExpressionException.class,
() -> compile("x("));
assertThrows(
ExpressionException.class,
() -> compile("(")
);
assertThrows(
ExpressionException.class,
() -> compile("x(")
);
// test overloader errors
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("atan2(1)"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("atan2(1)")
);
assertEquals(0, e.getPosition(), "Error position");
}
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("atan2(1, 2, 3)"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("atan2(1, 2, 3)")
);
assertEquals(0, e.getPosition(), "Error position");
}
{
ExpressionException e = assertThrows(ExpressionException.class,
() -> compile("rotate(1, 2, 3)"));
ExpressionException e = assertThrows(
ExpressionException.class,
() -> compile("rotate(1, 2, 3)")
);
assertEquals(7, e.getPosition(), "Error position");
}
@ -289,41 +309,41 @@ class ExpressionTest extends BaseExpressionTest {
checkTestCase("c=5; a=0; while (c > 0) { ++a; --c; } a", 5);
checkTestCase("c=5; a=0; do { ++a; --c; } while (c > 0); a", 5);
checkTestCase("" +
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" --c;" +
" if (c == 1) break;" +
"}" +
"a", 4);
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" --c;" +
" if (c == 1) break;" +
"}" +
"a", 4);
checkTestCase("" +
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" if (a < 5) continue;" +
" --c;" +
"}" +
"a", 9);
"c=5;" +
"a=0;" +
"while (c > 0) {" +
" ++a;" +
" if (a < 5) continue;" +
" --c;" +
"}" +
"a", 9);
checkTestCase("" +
"c=5;" +
"a=0;" +
"do {" +
" ++a;" +
" --c;" +
" if (c == 1) break;" +
"} while (c > 0);" +
"a", 4);
"c=5;" +
"a=0;" +
"do {" +
" ++a;" +
" --c;" +
" if (c == 1) break;" +
"} while (c > 0);" +
"a", 4);
checkTestCase("" +
"c=5;" +
"a=0;" +
"do {" +
" ++a;" +
" if (a < 5) continue;" +
" --c;" +
"} while (c > 0);" +
"a", 9);
"c=5;" +
"a=0;" +
"do {" +
" ++a;" +
" if (a < 5) continue;" +
" --c;" +
"} while (c > 0);" +
"a", 9);
}
@Test
@ -331,33 +351,33 @@ class ExpressionTest extends BaseExpressionTest {
checkTestCase("a=0; for (i=0; i<5; ++i) { ++a; } a", 5);
checkTestCase("y=0; for (i=1,5) { y *= 10; y += i; } y", 12345);
checkTestCase("" +
"a=0;" +
"for (c = 5; c > 0; c--) {" +
" ++a;" +
" if (c == 2) break;" +
"}" +
"a", 4);
"a=0;" +
"for (c = 5; c > 0; c--) {" +
" ++a;" +
" if (c == 2) break;" +
"}" +
"a", 4);
checkTestCase("" +
"a=0;" +
"for (c = 5; c > 0; c--) {" +
" if (a > 1) continue;" +
" ++a;" +
"}" +
"a", 2);
"a=0;" +
"for (c = 5; c > 0; c--) {" +
" if (a > 1) continue;" +
" ++a;" +
"}" +
"a", 2);
checkTestCase("" +
"a=0;" +
"for (c = 1,5) {" +
" ++a;" +
" if (c == 4) break;" +
"}" +
"a", 4);
"a=0;" +
"for (c = 1,5) {" +
" ++a;" +
" if (c == 4) break;" +
"}" +
"a", 4);
checkTestCase("" +
"a=0;" +
"for (c = 1,5) {" +
" if (a > 1) continue;" +
" ++a;" +
"}" +
"a", 2);
"a=0;" +
"for (c = 1,5) {" +
" if (a > 1) continue;" +
" ++a;" +
"}" +
"a", 2);
}
@Test
@ -375,33 +395,33 @@ class ExpressionTest extends BaseExpressionTest {
// try to continue in a switch :P
{
EvaluationException ex = assertThrows(EvaluationException.class, () -> simpleEval("" +
"switch(1) {" +
" case 1: continue;" +
"}"));
"switch(1) {" +
" case 1: continue;" +
"}"));
assertTrue(ex.getMessage().contains("continue in a switch"));
}
{
EvaluationException ex = assertThrows(EvaluationException.class, () -> simpleEval("" +
"switch(1) {" +
" default: continue;" +
"}"));
"switch(1) {" +
" default: continue;" +
"}"));
assertTrue(ex.getMessage().contains("continue in a switch"));
}
// duplicate case checks
{
EvaluationException ex = assertThrows(EvaluationException.class, () -> simpleEval("" +
"switch(1) {" +
" case 1: 1;" +
" case 1: 1;" +
"}"));
"switch(1) {" +
" case 1: 1;" +
" case 1: 1;" +
"}"));
assertTrue(ex.getMessage().contains("Duplicate cases"));
}
{
EvaluationException ex = assertThrows(EvaluationException.class, () -> simpleEval("" +
"switch(1) {" +
" default: 1;" +
" default: 1;" +
"}"));
"switch(1) {" +
" default: 1;" +
" default: 1;" +
"}"));
assertTrue(ex.getMessage().contains("Duplicate default cases"));
}
}
@ -420,9 +440,11 @@ class ExpressionTest extends BaseExpressionTest {
@Test
public void testTimeout() {
ExpressionTimeoutException e = assertTimeoutPreemptively(Duration.ofSeconds(10), () ->
assertThrows(ExpressionTimeoutException.class,
() -> simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"),
"Loop was not stopped.")
assertThrows(
ExpressionTimeoutException.class,
() -> simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"),
"Loop was not stopped."
)
);
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
}

View File

@ -45,4 +45,5 @@ public class ExpressionTestCase {
public String toString() {
return expression + " -> " + result;
}
}

View File

@ -49,7 +49,8 @@ class RealExpressionTest extends BaseExpressionTest {
postChecks.accept(expr);
double data = readSlot(expr, "data");
assertEquals(expectedData, (int) data,
"Test case " + this + " failed (data)");
"Test case " + this + " failed (data)"
);
});
}
@ -57,6 +58,7 @@ class RealExpressionTest extends BaseExpressionTest {
public String toString() {
return loc + " -> " + result;
}
}
private static TestCase testCase(Vector3 loc, double result) {
@ -73,44 +75,51 @@ class RealExpressionTest extends BaseExpressionTest {
for (TestCase aCase : cases) {
Vector3 loc = aCase.loc;
assertEquals(aCase.result, compiled.evaluate(loc.getX(), loc.getY(), loc.getZ()), 0,
"Test case " + aCase + " failed (result)");
"Test case " + aCase + " failed (result)"
);
aCase.postChecks.accept(compiled);
}
}
@Test
void torus() {
checkExpression("(0.75-sqrt(x^2+y^2))^2+z^2 < 0.25^2",
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0.5), 0),
testCase(Vector3.at(1, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0), 1),
testCase(Vector3.at(0.75, 0.5, 0), 1),
testCase(Vector3.at(0.75, 0, 0), 1));
checkExpression(
"(0.75-sqrt(x^2+y^2))^2+z^2 < 0.25^2",
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0.5), 0),
testCase(Vector3.at(1, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0), 1),
testCase(Vector3.at(0.75, 0.5, 0), 1),
testCase(Vector3.at(0.75, 0, 0), 1)
);
}
@Test
void gnarledOakTree() {
checkExpression("(0.5+sin(atan2(x,z)*8)*0.2)*(sqrt(x*x+z*z)/0.5)^(-2)-1.2 < y",
testCase(Vector3.at(-1, -1, -1), 1),
testCase(Vector3.at(-1, 0, 1), 1),
testCase(Vector3.at(1, 1, 1), 1),
testCase(Vector3.at(0, 0, -1), 1),
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0, 1, 0), 0),
testCase(Vector3.at(0, 0, 0.32274), 0),
testCase(Vector3.at(0, 0, 0.32275), 1));
checkExpression(
"(0.5+sin(atan2(x,z)*8)*0.2)*(sqrt(x*x+z*z)/0.5)^(-2)-1.2 < y",
testCase(Vector3.at(-1, -1, -1), 1),
testCase(Vector3.at(-1, 0, 1), 1),
testCase(Vector3.at(1, 1, 1), 1),
testCase(Vector3.at(0, 0, -1), 1),
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0, 1, 0), 0),
testCase(Vector3.at(0, 0, 0.32274), 0),
testCase(Vector3.at(0, 0, 0.32275), 1)
);
}
@Test
void rainbowTorus() {
checkExpression("data=(32+15/2/pi*atan2(x,y))%16; (0.75-sqrt(x^2+y^2))^2+z^2 < 0.25^2",
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0.5), 0),
testCase(Vector3.at(1, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0), 1).withData(1),
testCase(Vector3.at(0.75, 0.5, 0), 1).withData(2),
testCase(Vector3.at(0.75, 0, 0), 1).withData(3));
checkExpression(
"data=(32+15/2/pi*atan2(x,y))%16; (0.75-sqrt(x^2+y^2))^2+z^2 < 0.25^2",
testCase(Vector3.at(0, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0.5), 0),
testCase(Vector3.at(1, 0, 0), 0),
testCase(Vector3.at(0.5, 0.5, 0), 1).withData(1),
testCase(Vector3.at(0.75, 0.5, 0), 1).withData(2),
testCase(Vector3.at(0.75, 0, 0), 1).withData(3)
);
}
@Test
@ -118,53 +127,64 @@ class RealExpressionTest extends BaseExpressionTest {
TestCase[] testCases = new TestCase[15];
for (int i = 0; i < testCases.length; i++) {
testCases[i] = testCase(Vector3.at(0, i / 16.0 - 0.5, 0), 1)
.withData((i + 9) % 16);
.withData((i + 9) % 16);
}
testCases = Stream.concat(Stream.of(testCases), Stream.of(
testCase(Vector3.at(0, 1, 0), 0)
testCase(Vector3.at(0, 1, 0), 0)
)).toArray(TestCase[]::new);
checkExpression("data=(32+y*16+1)%16; y^2/9+x^2/6*(1/(1-0.4*y))+z^2/6*(1/(1-0.4*y))<0.08",
testCases);
checkExpression(
"data=(32+y*16+1)%16; y^2/9+x^2/6*(1/(1-0.4*y))+z^2/6*(1/(1-0.4*y))<0.08",
testCases
);
}
@Test
void heart() {
checkExpression("(z/2)^2+x^2+(5*y/4-sqrt(abs(x)))^2<0.6",
testCase(Vector3.at(0, 0, -1), 1),
testCase(Vector3.at(0, 1, -1), 0),
testCase(Vector3.at(-0.5, 1, 0), 1));
checkExpression(
"(z/2)^2+x^2+(5*y/4-sqrt(abs(x)))^2<0.6",
testCase(Vector3.at(0, 0, -1), 1),
testCase(Vector3.at(0, 1, -1), 0),
testCase(Vector3.at(-0.5, 1, 0), 1)
);
}
@Test
void sineWave() {
checkExpression("sin(x*5)/2<y",
testCase(Vector3.at(1, -0.47947, 0), 0),
testCase(Vector3.at(1, -0.47946, 0), 1),
testCase(Vector3.at(2, -0.27202, 0), 0),
testCase(Vector3.at(2, -0.27201, 0), 1),
testCase(Vector3.at(3, 0.32513, 0), 0),
testCase(Vector3.at(3, 0.32515, 0), 1));
checkExpression(
"sin(x*5)/2<y",
testCase(Vector3.at(1, -0.47947, 0), 0),
testCase(Vector3.at(1, -0.47946, 0), 1),
testCase(Vector3.at(2, -0.27202, 0), 0),
testCase(Vector3.at(2, -0.27201, 0), 1),
testCase(Vector3.at(3, 0.32513, 0), 0),
testCase(Vector3.at(3, 0.32515, 0), 1)
);
}
@Test
void radialCosine() {
checkExpression("cos(sqrt(x^2+z^2)*5)/2<y",
testCase(Vector3.at(0, 0.5, 0), 0),
testCase(Vector3.at(0, 0.51, 0), 1),
testCase(Vector3.at(Math.PI / 5, -0.5, 0), 0),
testCase(Vector3.at(Math.PI / 5, -0.49, 0), 1),
testCase(Vector3.at(Math.PI / 10, 0, 0), 0),
testCase(Vector3.at(Math.PI / 10, 0.1, 0), 1));
checkExpression(
"cos(sqrt(x^2+z^2)*5)/2<y",
testCase(Vector3.at(0, 0.5, 0), 0),
testCase(Vector3.at(0, 0.51, 0), 1),
testCase(Vector3.at(Math.PI / 5, -0.5, 0), 0),
testCase(Vector3.at(Math.PI / 5, -0.49, 0), 1),
testCase(Vector3.at(Math.PI / 10, 0, 0), 0),
testCase(Vector3.at(Math.PI / 10, 0.1, 0), 1)
);
}
@Test
void circularHyperboloid() {
checkExpression("-(z^2/12)+(y^2/4)-(x^2/12)>-0.03",
testCase(Vector3.at(0, 0, 0), 1),
testCase(Vector3.at(0, 1, 0), 1),
testCase(Vector3.at(0, 1, 1), 1),
testCase(Vector3.at(1, 1, 1), 1),
testCase(Vector3.at(0, 0, 1), 0),
testCase(Vector3.at(1, 0, 1), 0));
checkExpression(
"-(z^2/12)+(y^2/4)-(x^2/12)>-0.03",
testCase(Vector3.at(0, 0, 0), 1),
testCase(Vector3.at(0, 1, 0), 1),
testCase(Vector3.at(0, 1, 1), 1),
testCase(Vector3.at(1, 1, 1), 1),
testCase(Vector3.at(0, 0, 1), 0),
testCase(Vector3.at(1, 0, 1), 0)
);
}
}

View File

@ -28,37 +28,44 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class DeprecationUtilTest {
public interface ModifiedApi {
@Deprecated
default boolean oldApi() {
return newApi();
}
@NonAbstractForCompatibility(
delegateName = "oldApi",
delegateParams = {}
delegateName = "oldApi",
delegateParams = {}
)
default boolean newApi() {
DeprecationUtil.checkDelegatingOverride(getClass());
return oldApi();
}
}
public static class OldImpl implements ModifiedApi {
@SuppressWarnings("deprecation")
@Override
public boolean oldApi() {
return false;
}
}
public static class NewImpl implements ModifiedApi {
@Override
public boolean newApi() {
return true;
}
}
public static class NewBadImpl implements ModifiedApi {
}
@Test

View File

@ -39,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* Verifies that {@link RegionOptimizedVectorSorter} sorts properly.
*/
public class RegionOptimizedVectorSorterTest {
/**
* Find factors, smallest to biggest.
*
@ -64,10 +65,10 @@ public class RegionOptimizedVectorSorterTest {
}
@ParameterizedTest(
name = "size={0}"
name = "size={0}"
)
@ValueSource(ints = {
0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000
0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000
})
void checkSorted(int size) {
Random rng = new Random(size);
@ -84,7 +85,7 @@ public class RegionOptimizedVectorSorterTest {
int minZ = z / 2;
int maxZ = minZ + z % 2;
toSort = Lists.newArrayList(new CuboidRegion(
BlockVector3.at(-minX, 0, -minZ), BlockVector3.at(maxX - 1, 0, maxZ - 1)
BlockVector3.at(-minX, 0, -minZ), BlockVector3.at(maxX - 1, 0, maxZ - 1)
));
}
assertEquals(size, toSort.size());
@ -104,23 +105,23 @@ public class RegionOptimizedVectorSorterTest {
String spaceship = "(" + curr + " <=> " + next + ")";
if (currRegionX > nextRegionX) {
fail(spaceship + " "
+ currRegionX + " region x should be less than or equal to " + nextRegionX);
+ currRegionX + " region x should be less than or equal to " + nextRegionX);
} else if (currRegionX == nextRegionX) {
if (currRegionZ > nextRegionZ) {
fail(spaceship + " "
+ currRegionZ + " region z should be less than or equal to " + nextRegionZ);
+ currRegionZ + " region z should be less than or equal to " + nextRegionZ);
} else if (currRegionZ == nextRegionZ) {
if (currChunkX > nextChunkX) {
fail(spaceship + " "
+ currChunkX + " chunk x should be less than or equal to " + nextChunkX);
+ currChunkX + " chunk x should be less than or equal to " + nextChunkX);
} else if (currChunkX == nextChunkX) {
if (currChunkZ > nextChunkZ) {
fail(spaceship + " "
+ currChunkZ + " chunk z should be less than or equal to " + nextChunkZ);
+ currChunkZ + " chunk z should be less than or equal to " + nextChunkZ);
} else if (currChunkZ == nextChunkZ) {
if (curr.getY() < next.getY()) {
fail(spaceship + " "
+ curr + " y should be greater than or equal to " + next);
+ curr + " y should be greater than or equal to " + next);
}
}
}
@ -128,4 +129,5 @@ public class RegionOptimizedVectorSorterTest {
}
}
}
}

View File

@ -150,7 +150,7 @@ public class LocationTest {
World world = mock(World.class);
long start = System.currentTimeMillis();
BlockVector3 location1 = BlockVector3.ZERO;
location1.add(10,10,10);
location1.add(10, 10, 10);
System.out.println(System.currentTimeMillis() - start + " ms");
}

View File

@ -29,17 +29,21 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
abstract class PositionListTest {
static class Long extends PositionListTest {
@Override
protected PositionList createPositionList() {
return new LongPositionList();
}
}
static class Vector extends PositionListTest {
@Override
protected PositionList createPositionList() {
return new VectorPositionList();
}
}
private final VariedVectorGenerator generator = new VariedVectorGenerator(true);
@ -116,4 +120,5 @@ abstract class PositionListTest {
assertEquals(0, positionList.size());
});
}
}

View File

@ -69,4 +69,5 @@ public class EventBusTest {
eventBus.post(e2);
assertEquals(singletonList(e1), subscriber.events);
}
}

View File

@ -38,32 +38,33 @@ class MorePathsTest {
@Test
void testRelative() {
assertEquals(
paths("a", "a/b", "a/b/c"),
MorePaths.iterPaths(Paths.get("a/b/c")).collect(toList())
paths("a", "a/b", "a/b/c"),
MorePaths.iterPaths(Paths.get("a/b/c")).collect(toList())
);
}
@Test
void testAbsolute() {
assertEquals(
paths("/", "/a", "/a/b", "/a/b/c"),
MorePaths.iterPaths(Paths.get("/a/b/c")).collect(toList())
paths("/", "/a", "/a/b", "/a/b/c"),
MorePaths.iterPaths(Paths.get("/a/b/c")).collect(toList())
);
}
@Test
void testEmpty() {
assertEquals(
paths(""),
MorePaths.iterPaths(Paths.get("")).collect(toList())
paths(""),
MorePaths.iterPaths(Paths.get("")).collect(toList())
);
}
@Test
void testJustFile() {
assertEquals(
paths("a"),
MorePaths.iterPaths(Paths.get("a")).collect(toList())
paths("a"),
MorePaths.iterPaths(Paths.get("a")).collect(toList())
);
}
}

View File

@ -20,8 +20,10 @@
package com.sk89q.worldedit.util.test;
public class ResourceLockKeys {
public static final String WORLDEDIT_PLATFORM = "WORLDEDIT_PLATFORM";
private ResourceLockKeys() {
}
}

View File

@ -63,7 +63,8 @@ public class VariedVectorGenerator {
BlockVector3.at(-maxXZ, -maxY - 1, -maxXZ),
BlockVector3.at(maxXZ, -maxY - 1, maxXZ),
BlockVector3.at(-maxXZ, maxY, -maxXZ),
BlockVector3.at(maxXZ, maxY, maxXZ));
BlockVector3.at(maxXZ, maxY, maxXZ)
);
}
public Stream<BlockVector3> makeVectorsStream() {
@ -108,4 +109,5 @@ public class VariedVectorGenerator {
}
};
}
}

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.util.test;
import com.sk89q.worldedit.math.BlockVector3;
public class VariedVectorPair {
public final BlockVector3 first;
public final BlockVector3 second;
@ -29,4 +30,5 @@ public class VariedVectorPair {
this.first = first;
this.second = second;
}
}

View File

@ -36,6 +36,7 @@ import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnaps
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.REGION_DATA;
interface EntryMaker<T> {
EntryMaker<ZonedDateTime> TIMESTAMPED_DIR = (directory, time) -> {
Path timestampedDir = directory.resolve(time.format(FORMATTER));
Files.createDirectories(timestampedDir);
@ -44,8 +45,8 @@ interface EntryMaker<T> {
EntryMaker<ZonedDateTime> TIMESTAMPED_ARCHIVE = (directory, time) -> {
Path zipFile = directory.resolve(time.format(FORMATTER) + ".zip");
try (FileSystem zipFs = FileSystems.newFileSystem(
URI.create("jar:" + zipFile.toUri() + "!/"),
ImmutableMap.of("create", "true")
URI.create("jar:" + zipFile.toUri() + "!/"),
ImmutableMap.of("create", "true")
)) {
TIMESTAMPED_DIR.createEntry(zipFs.getPath("/"), time);
}
@ -63,6 +64,7 @@ interface EntryMaker<T> {
};
class DimInfo {
final String worldName;
final int dim;
@ -70,6 +72,7 @@ interface EntryMaker<T> {
this.worldName = worldName;
this.dim = dim;
}
}
EntryMaker<DimInfo> WORLD_DIM_DIR = (directory, dimInfo) -> {
@ -95,12 +98,12 @@ interface EntryMaker<T> {
Files.createDirectories(worldDir);
Files.createFile(worldDir.resolve("level.dat"));
Path chunkFile = worldDir.resolve(LegacyChunkStore.getFilename(
CHUNK_POS.toBlockVector2(), "/"
CHUNK_POS.toBlockVector2(), "/"
));
Files.createDirectories(chunkFile.getParent());
Files.write(chunkFile, CHUNK_DATA);
chunkFile = worldDir.resolve(LegacyChunkStore.getFilename(
CHUNK_POS.add(32, 0, 32).toBlockVector2(), "/"
CHUNK_POS.add(32, 0, 32).toBlockVector2(), "/"
));
Files.createDirectories(chunkFile.getParent());
Files.write(chunkFile, CHUNK_DATA);
@ -112,8 +115,8 @@ interface EntryMaker<T> {
try {
Files.deleteIfExists(temp);
try (FileSystem zipFs = FileSystems.newFileSystem(
URI.create("jar:" + temp.toUri() + "!/"),
ImmutableMap.of("create", "true")
URI.create("jar:" + temp.toUri() + "!/"),
ImmutableMap.of("create", "true")
)) {
WORLD_DIR.createEntry(zipFs.getPath("/"), worldName);
}

View File

@ -24,13 +24,13 @@ import com.sk89q.worldedit.util.io.file.ArchiveDir;
import com.sk89q.worldedit.util.io.file.ArchiveNioSupport;
import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.stream.Collectors.toList;
@ -75,8 +75,10 @@ class FSSDContext {
snapshots = snapshotStream.collect(toList());
}
try {
assertTrue(snapshots.size() <= 1,
"Too many snapshots matched for " + worldName);
assertTrue(
snapshots.size() <= 1,
"Too many snapshots matched for " + worldName
);
return requireSnapshot(name, snapshots.stream().findAny().orElse(null));
} catch (Throwable t) {
Closer closer = Closer.create();
@ -99,6 +101,7 @@ class FSSDContext {
ArchiveDir getRootOfArchive(Path archive) throws IOException {
return archiveNioSupport.tryOpenAsDir(archive)
.orElseThrow(() -> new AssertionError("No archive opener for " + archive));
.orElseThrow(() -> new AssertionError("No archive opener for " + archive));
}
}

View File

@ -54,10 +54,14 @@ enum FSSDTestType {
@Override
List<DynamicTest> getTests(FSSDContext context) {
return ImmutableList.of(
dynamicTest("return an empty stream from getSnapshots(worldName)",
() -> context.db.getSnapshots(WORLD_ALPHA)),
dynamicTest("return an empty optional from getSnapshot(name)",
() -> context.db.getSnapshot(context.nameUri(WORLD_ALPHA)))
dynamicTest(
"return an empty stream from getSnapshots(worldName)",
() -> context.db.getSnapshots(WORLD_ALPHA)
),
dynamicTest(
"return an empty optional from getSnapshot(name)",
() -> context.db.getSnapshot(context.nameUri(WORLD_ALPHA))
)
);
}
},
@ -74,7 +78,7 @@ enum FSSDTestType {
List<DynamicTest> getTests(FSSDContext context) throws IOException {
int dim = ThreadLocalRandom.current().nextInt();
Path worldFolder = EntryMaker.WORLD_DIM_DIR
.createEntry(context.db.getRoot(), new EntryMaker.DimInfo(WORLD_ALPHA, dim));
.createEntry(context.db.getRoot(), new EntryMaker.DimInfo(WORLD_ALPHA, dim));
Files.setLastModifiedTime(worldFolder, FileTime.from(TIME_ONE.toInstant()));
return singleSnapTest(context, WORLD_ALPHA, TIME_ONE);
}
@ -83,7 +87,7 @@ enum FSSDTestType {
@Override
List<DynamicTest> getTests(FSSDContext context) throws IOException {
Path worldFolder = EntryMaker.WORLD_NO_REGION_DIR
.createEntry(context.db.getRoot(), WORLD_ALPHA);
.createEntry(context.db.getRoot(), WORLD_ALPHA);
Files.setLastModifiedTime(worldFolder, FileTime.from(TIME_ONE.toInstant()));
return singleSnapTest(context, WORLD_ALPHA, TIME_ONE);
}
@ -92,7 +96,7 @@ enum FSSDTestType {
@Override
List<DynamicTest> getTests(FSSDContext context) throws IOException {
Path worldFolder = EntryMaker.WORLD_LEGACY_DIR
.createEntry(context.db.getRoot(), WORLD_ALPHA);
.createEntry(context.db.getRoot(), WORLD_ALPHA);
Files.setLastModifiedTime(worldFolder, FileTime.from(TIME_ONE.toInstant()));
return singleSnapTest(context, WORLD_ALPHA, TIME_ONE);
}
@ -101,11 +105,11 @@ enum FSSDTestType {
@Override
List<DynamicTest> getTests(FSSDContext context) throws IOException {
Path worldArchive = EntryMaker.WORLD_ARCHIVE
.createEntry(context.db.getRoot(), WORLD_ALPHA);
.createEntry(context.db.getRoot(), WORLD_ALPHA);
try (ArchiveDir rootOfArchive = context.getRootOfArchive(worldArchive)) {
Files.setLastModifiedTime(
rootOfArchive.getPath(),
FileTime.from(TIME_ONE.toInstant())
rootOfArchive.getPath(),
FileTime.from(TIME_ONE.toInstant())
);
}
return singleSnapTest(context, WORLD_ALPHA + ".zip", TIME_ONE);
@ -116,20 +120,26 @@ enum FSSDTestType {
List<? extends DynamicNode> getTests(FSSDContext context) throws IOException {
Path root = context.db.getRoot();
Path timestampedDir = EntryMaker.TIMESTAMPED_DIR
.createEntry(root, TIME_ONE);
.createEntry(root, TIME_ONE);
EntryMaker.WORLD_DIR.createEntry(timestampedDir, WORLD_ALPHA);
EntryMaker.WORLD_ARCHIVE.createEntry(timestampedDir, WORLD_BETA);
return ImmutableList.of(
dynamicContainer("world dir",
singleSnapTest(context,
root.relativize(timestampedDir) + File.separator + WORLD_ALPHA,
TIME_ONE)
),
dynamicContainer("world archive",
singleSnapTest(context,
root.relativize(timestampedDir) + File.separator + WORLD_BETA + ".zip",
TIME_ONE)
)
dynamicContainer(
"world dir",
singleSnapTest(
context,
root.relativize(timestampedDir) + File.separator + WORLD_ALPHA,
TIME_ONE
)
),
dynamicContainer(
"world archive",
singleSnapTest(
context,
root.relativize(timestampedDir) + File.separator + WORLD_BETA + ".zip",
TIME_ONE
)
)
);
}
},
@ -138,17 +148,20 @@ enum FSSDTestType {
List<? extends DynamicNode> getTests(FSSDContext context) throws IOException {
Path root = context.db.getRoot();
Path timestampedArchive = EntryMaker.TIMESTAMPED_ARCHIVE
.createEntry(root, TIME_ONE);
.createEntry(root, TIME_ONE);
try (ArchiveDir timestampedDir = context.getRootOfArchive(timestampedArchive)) {
EntryMaker.WORLD_DIR.createEntry(timestampedDir.getPath(), WORLD_ALPHA);
EntryMaker.WORLD_ARCHIVE.createEntry(timestampedDir.getPath(), WORLD_BETA);
}
return ImmutableList.of(
dynamicContainer("world dir",
singleSnapTest(context,
root.relativize(timestampedArchive) + File.separator + WORLD_ALPHA,
TIME_ONE)
)
dynamicContainer(
"world dir",
singleSnapTest(
context,
root.relativize(timestampedArchive) + File.separator + WORLD_ALPHA,
TIME_ONE
)
)
);
}
},
@ -157,22 +170,28 @@ enum FSSDTestType {
List<? extends DynamicNode> getTests(FSSDContext context) throws IOException {
Path root = context.db.getRoot();
Path timestampedDirA = EntryMaker.TIMESTAMPED_DIR
.createEntry(root.resolve(WORLD_ALPHA), TIME_ONE);
.createEntry(root.resolve(WORLD_ALPHA), TIME_ONE);
Path timestampedDirB = EntryMaker.TIMESTAMPED_DIR
.createEntry(root.resolve(WORLD_BETA), TIME_ONE);
.createEntry(root.resolve(WORLD_BETA), TIME_ONE);
EntryMaker.WORLD_DIR.createEntry(timestampedDirA, WORLD_ALPHA);
EntryMaker.WORLD_ARCHIVE.createEntry(timestampedDirB, WORLD_BETA);
return ImmutableList.of(
dynamicContainer("world dir",
singleSnapTest(context,
root.relativize(timestampedDirA) + File.separator + WORLD_ALPHA,
TIME_ONE)
),
dynamicContainer("world archive",
singleSnapTest(context,
root.relativize(timestampedDirB) + File.separator + WORLD_BETA + ".zip",
TIME_ONE)
)
dynamicContainer(
"world dir",
singleSnapTest(
context,
root.relativize(timestampedDirA) + File.separator + WORLD_ALPHA,
TIME_ONE
)
),
dynamicContainer(
"world archive",
singleSnapTest(
context,
root.relativize(timestampedDirB) + File.separator + WORLD_BETA + ".zip",
TIME_ONE
)
)
);
}
},
@ -181,57 +200,57 @@ enum FSSDTestType {
List<DynamicTest> getTests(FSSDContext context) throws IOException {
Path root = context.db.getRoot();
Path timestampedDirA = EntryMaker.TIMESTAMPED_DIR
.createEntry(root, TIME_ONE);
.createEntry(root, TIME_ONE);
EntryMaker.WORLD_DIR.createEntry(timestampedDirA, WORLD_ALPHA);
Path timestampedDirB = EntryMaker.TIMESTAMPED_DIR
.createEntry(root, TIME_TWO);
.createEntry(root, TIME_TWO);
EntryMaker.WORLD_DIR.createEntry(timestampedDirB, WORLD_ALPHA);
return ImmutableList.of(
dynamicTest("list both snapshots in order (newest first)", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsNewestFirst(WORLD_ALPHA).collect(toList());
assertEquals(2, snapshots.size());
assertValidSnapshot(TIME_ONE, snapshots.get(0));
assertValidSnapshot(TIME_TWO, snapshots.get(1));
}),
dynamicTest("list both snapshots in order (oldest first)", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsOldestFirst(WORLD_ALPHA).collect(toList());
assertEquals(2, snapshots.size());
assertValidSnapshot(TIME_TWO, snapshots.get(0));
assertValidSnapshot(TIME_ONE, snapshots.get(1));
}),
dynamicTest("list only 1 if getting AFTER 2", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsAfter(WORLD_ALPHA, TIME_TWO).collect(toList());
assertEquals(1, snapshots.size());
assertValidSnapshot(TIME_ONE, snapshots.get(0));
}),
dynamicTest("list only 2 if getting BEFORE 1", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsBefore(WORLD_ALPHA, TIME_ONE).collect(toList());
assertEquals(1, snapshots.size());
assertValidSnapshot(TIME_TWO, snapshots.get(0));
}),
dynamicTest("list both if AFTER time before 2", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsAfter(WORLD_ALPHA, TIME_TWO.minusSeconds(1))
.collect(toList());
assertEquals(2, snapshots.size());
// sorted newest first
assertValidSnapshot(TIME_ONE, snapshots.get(0));
assertValidSnapshot(TIME_TWO, snapshots.get(1));
}),
dynamicTest("list both if BEFORE time after 1", () -> {
dynamicTest("list both snapshots in order (newest first)", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsBefore(WORLD_ALPHA, TIME_ONE.plusSeconds(1))
.collect(toList());
.getSnapshotsNewestFirst(WORLD_ALPHA).collect(toList());
assertEquals(2, snapshots.size());
assertValidSnapshot(TIME_ONE, snapshots.get(0));
assertValidSnapshot(TIME_TWO, snapshots.get(1));
}),
dynamicTest("list both snapshots in order (oldest first)", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsOldestFirst(WORLD_ALPHA).collect(toList());
assertEquals(2, snapshots.size());
// sorted oldest first
assertValidSnapshot(TIME_TWO, snapshots.get(0));
assertValidSnapshot(TIME_ONE, snapshots.get(1));
}
)
}),
dynamicTest("list only 1 if getting AFTER 2", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsAfter(WORLD_ALPHA, TIME_TWO).collect(toList());
assertEquals(1, snapshots.size());
assertValidSnapshot(TIME_ONE, snapshots.get(0));
}),
dynamicTest("list only 2 if getting BEFORE 1", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsBefore(WORLD_ALPHA, TIME_ONE).collect(toList());
assertEquals(1, snapshots.size());
assertValidSnapshot(TIME_TWO, snapshots.get(0));
}),
dynamicTest("list both if AFTER time before 2", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsAfter(WORLD_ALPHA, TIME_TWO.minusSeconds(1))
.collect(toList());
assertEquals(2, snapshots.size());
// sorted newest first
assertValidSnapshot(TIME_ONE, snapshots.get(0));
assertValidSnapshot(TIME_TWO, snapshots.get(1));
}),
dynamicTest("list both if BEFORE time after 1", () -> {
List<Snapshot> snapshots = context.db
.getSnapshotsBefore(WORLD_ALPHA, TIME_ONE.plusSeconds(1))
.collect(toList());
assertEquals(2, snapshots.size());
// sorted oldest first
assertValidSnapshot(TIME_TWO, snapshots.get(0));
assertValidSnapshot(TIME_ONE, snapshots.get(1));
}
)
);
}
},
@ -239,36 +258,40 @@ enum FSSDTestType {
@Override
List<? extends DynamicNode> getTests(FSSDContext context) throws IOException {
Path worldFolderA = EntryMaker.WORLD_DIR
.createEntry(context.db.getRoot(), WORLD_ALPHA);
.createEntry(context.db.getRoot(), WORLD_ALPHA);
Files.setLastModifiedTime(worldFolderA, FileTime.from(TIME_ONE.toInstant()));
Path worldFolderB = EntryMaker.WORLD_DIR
.createEntry(context.db.getRoot(), WORLD_BETA);
.createEntry(context.db.getRoot(), WORLD_BETA);
Files.setLastModifiedTime(worldFolderB, FileTime.from(TIME_TWO.toInstant()));
return Stream.of(
singleSnapTest(context, WORLD_ALPHA, TIME_ONE),
singleSnapTest(context, WORLD_BETA, TIME_TWO)
singleSnapTest(context, WORLD_ALPHA, TIME_ONE),
singleSnapTest(context, WORLD_BETA, TIME_TWO)
).flatMap(List::stream).collect(toList());
}
};
List<DynamicTest> singleSnapTest(FSSDContext context, String name,
ZonedDateTime time) {
List<DynamicTest> singleSnapTest(
FSSDContext context, String name,
ZonedDateTime time
) {
return ImmutableList.of(
dynamicTest("return a valid snapshot for " + name, () -> {
try (Snapshot snapshot = context.requireSnapshot(name)) {
assertValidSnapshot(time, snapshot);
}
}),
dynamicTest("list a valid snapshot for " + name, () -> {
try (Snapshot snapshot = context.requireListsSnapshot(name)) {
assertValidSnapshot(time, snapshot);
}
})
dynamicTest("return a valid snapshot for " + name, () -> {
try (Snapshot snapshot = context.requireSnapshot(name)) {
assertValidSnapshot(time, snapshot);
}
}),
dynamicTest("list a valid snapshot for " + name, () -> {
try (Snapshot snapshot = context.requireListsSnapshot(name)) {
assertValidSnapshot(time, snapshot);
}
})
);
}
private static void assertValidSnapshot(ZonedDateTime time,
Snapshot snapshot) throws IOException, DataException {
private static void assertValidSnapshot(
ZonedDateTime time,
Snapshot snapshot
) throws IOException, DataException {
assertEquals(time, snapshot.getInfo().getDateTime());
// MCA file
assertEquals(CHUNK_TAG.toString(), snapshot.getChunkTag(CHUNK_POS).toString());
@ -281,10 +304,10 @@ enum FSSDTestType {
Stream<DynamicNode> getNamedTests(FSSDContext context) throws IOException {
return Stream.of(dynamicContainer(
name(),
URI.create("method:" + getClass().getName() +
"#getTests(" + FSSDContext.class.getName() + ")"),
getTests(context).stream()
name(),
URI.create("method:" + getClass().getName() +
"#getTests(" + FSSDContext.class.getName() + ")"),
getTests(context).stream()
));
}

View File

@ -71,9 +71,9 @@ class FileSystemSnapshotDatabaseTest {
static final String WORLD_BETA = "World Beta";
static final DateTimeFormatter FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH_mm_ss");
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH_mm_ss");
static final ZonedDateTime TIME_ONE = Instant.parse("2018-01-01T12:00:00.00Z")
.atZone(ZoneId.systemDefault());
.atZone(ZoneId.systemDefault());
static final ZonedDateTime TIME_TWO = TIME_ONE.minusDays(1);
private static Path TEMP_DIR;
@ -88,11 +88,11 @@ class FileSystemSnapshotDatabaseTest {
try {
// Find the single chunk
BlockVector2 chunkPos = IntStream.range(0, 32).mapToObj(
x -> IntStream.range(0, 32).filter(z -> reader.hasChunk(x, z))
.mapToObj(z -> BlockVector2.at(x, z))
).flatMap(Function.identity())
.findAny()
.orElseThrow(() -> new AssertionError("No chunk in region file."));
x -> IntStream.range(0, 32).filter(z -> reader.hasChunk(x, z))
.mapToObj(z -> BlockVector2.at(x, z))
).flatMap(Function.identity())
.findAny()
.orElseThrow(() -> new AssertionError("No chunk in region file."));
ByteArrayOutputStream cap = new ByteArrayOutputStream();
try (InputStream in = reader.getChunkInputStream(chunkPos);
GZIPOutputStream gzOut = new GZIPOutputStream(cap)) {
@ -100,7 +100,7 @@ class FileSystemSnapshotDatabaseTest {
}
CHUNK_DATA = cap.toByteArray();
CHUNK_TAG = ChunkStoreHelper.readCompoundTag(() -> new GZIPInputStream(
new ByteArrayInputStream(CHUNK_DATA)
new ByteArrayInputStream(CHUNK_DATA)
));
CHUNK_POS = chunkPos.toBlockVector3();
} finally {
@ -142,14 +142,18 @@ class FileSystemSnapshotDatabaseTest {
try {
Path relative = root.getFileSystem().getPath("relative");
Files.createDirectories(relative);
FileSystemSnapshotDatabase db2 = new FileSystemSnapshotDatabase(relative,
ArchiveNioSupports.combined());
FileSystemSnapshotDatabase db2 = new FileSystemSnapshotDatabase(
relative,
ArchiveNioSupports.combined()
);
assertEquals(root.getFileSystem().getPath(".").toRealPath()
.resolve(relative), db2.getRoot());
.resolve(relative), db2.getRoot());
Path absolute = root.resolve("absolute");
Files.createDirectories(absolute);
FileSystemSnapshotDatabase db3 = new FileSystemSnapshotDatabase(absolute,
ArchiveNioSupports.combined());
FileSystemSnapshotDatabase db3 = new FileSystemSnapshotDatabase(
absolute,
ArchiveNioSupports.combined()
);
assertEquals(absolute, db3.getRoot());
} finally {
deleteTree(root);
@ -160,26 +164,28 @@ class FileSystemSnapshotDatabaseTest {
@TestFactory
Stream<DynamicNode> withSpecificNioSupport() {
return Stream.of(
ZipArchiveNioSupport.getInstance()
)
.map(nioSupport -> {
Stream<? extends DynamicNode> nodes = Stream.of(FSSDTestType.values())
.flatMap(type -> {
try {
return getTests(nioSupport, type);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
return dynamicContainer(
nioSupport.getClass().getSimpleName() + ", can, for format:",
nodes
);
});
ZipArchiveNioSupport.getInstance()
)
.map(nioSupport -> {
Stream<? extends DynamicNode> nodes = Stream.of(FSSDTestType.values())
.flatMap(type -> {
try {
return getTests(nioSupport, type);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
return dynamicContainer(
nioSupport.getClass().getSimpleName() + ", can, for format:",
nodes
);
});
}
private static Stream<? extends DynamicNode> getTests(ArchiveNioSupport nioSupport,
FSSDTestType type) throws IOException {
private static Stream<? extends DynamicNode> getTests(
ArchiveNioSupport nioSupport,
FSSDTestType type
) throws IOException {
Path root = newTempDb();
try {
Path dbRoot = root.resolve("snapshots");