Skip to content

Commit

Permalink
[ci skip] spotlessApply with the new settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Jan 29, 2023
1 parent ae6d8d6 commit ca7a649
Show file tree
Hide file tree
Showing 1,235 changed files with 20,908 additions and 29,627 deletions.
26 changes: 14 additions & 12 deletions src/functionalTest/java/appeng/test/AppengTestMod.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package appeng.test;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import java.io.File;
import java.io.PrintWriter;
import java.nio.file.FileSystems;
import java.nio.file.Path;

import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;

import org.apache.commons.io.output.CloseShieldOutputStream;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
Expand All @@ -22,13 +20,19 @@
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLServerStartedEvent;

// Most of these don't matter as this mod never gets published
@Mod(
modid = "appeng-tests",
name = "AE2 Dev Tests",
version = "1.0",
dependencies = "required-after:appliedenergistics2")
public class AppengTestMod {

@EventHandler
public void onServerStarted(FMLServerStartedEvent startedEv) {
MinecraftServer.getServer().addChatMessage(new ChatComponentText("Running AE2 unit tests..."));
Expand All @@ -39,8 +43,7 @@ public void onServerStarted(FMLServerStartedEvent startedEv) {
public void runTests() {
// https://junit.org/junit5/docs/current/user-guide/#launcher-api
System.setProperty("junit.platform.reporting.open.xml.enabled", "false");
final Path testsXmlOutDir =
FileSystems.getDefault().getPath("./junit-out/").toAbsolutePath();
final Path testsXmlOutDir = FileSystems.getDefault().getPath("./junit-out/").toAbsolutePath();
final File testsXmlOutDirFile = testsXmlOutDir.toFile();
testsXmlOutDirFile.mkdirs();
{
Expand All @@ -54,13 +57,13 @@ public void runTests() {
}
}
final LauncherDiscoveryRequest discovery = LauncherDiscoveryRequestBuilder.request()
.selectors(DiscoverySelectors.selectPackage("appeng.test"))
.build();
.selectors(DiscoverySelectors.selectPackage("appeng.test")).build();
final SummaryGeneratingListener summaryGenerator = new SummaryGeneratingListener();
final TestExecutionSummary summary;
try (PrintWriter stderrWriter = new PrintWriter(new CloseShieldOutputStream(System.err), true)) {
final LegacyXmlReportGeneratingListener xmlGenerator =
new LegacyXmlReportGeneratingListener(testsXmlOutDir, stderrWriter);
final LegacyXmlReportGeneratingListener xmlGenerator = new LegacyXmlReportGeneratingListener(
testsXmlOutDir,
stderrWriter);
try (LauncherSession session = LauncherFactory.openSession()) {
final Launcher launcher = session.getLauncher();
final TestPlan plan = launcher.discover(discovery);
Expand All @@ -74,8 +77,7 @@ public void runTests() {
stderrWriter.flush();
}
// Throw an exception if running via `runServer`
if (summary.getTotalFailureCount() > 0
&& FMLCommonHandler.instance().getSide().isServer()) {
if (summary.getTotalFailureCount() > 0 && FMLCommonHandler.instance().getSide().isServer()) {
throw new RuntimeException("Some of the unit tests failed to execute, check the log for details");
}
}
Expand Down
109 changes: 46 additions & 63 deletions src/functionalTest/java/appeng/test/CraftingV2Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

import static org.junit.jupiter.api.Assertions.*;

import appeng.api.storage.data.IAEItemStack;
import appeng.crafting.v2.CraftingJobV2;
import appeng.test.mockme.MockAESystem;
import appeng.util.item.AEItemStack;
import appeng.util.item.ItemList;
import java.io.File;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.*;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.common.DimensionManager;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import appeng.api.storage.data.IAEItemStack;
import appeng.crafting.v2.CraftingJobV2;
import appeng.test.mockme.MockAESystem;
import appeng.util.item.AEItemStack;
import appeng.util.item.ItemList;

public class CraftingV2Tests {

static World dummyWorld = null;
final int SIMPLE_SIMULATION_TIMEOUT_MS = 100;

Expand All @@ -29,19 +33,19 @@ public CraftingV2Tests() {
DimensionManager.registerDimension(256, 256);
}
if (dummyWorld == null) {
dummyWorld =
new WorldServer(
MinecraftServer.getServer(),
new DummySaveHandler(),
"DummyTestWorld",
256,
new WorldSettings(256, GameType.SURVIVAL, false, false, WorldType.DEFAULT),
MinecraftServer.getServer().theProfiler) {
@Override
public File getChunkSaveLocation() {
return new File("dummy-ignoreme");
}
};
dummyWorld = new WorldServer(
MinecraftServer.getServer(),
new DummySaveHandler(),
"DummyTestWorld",
256,
new WorldSettings(256, GameType.SURVIVAL, false, false, WorldType.DEFAULT),
MinecraftServer.getServer().theProfiler) {

@Override
public File getChunkSaveLocation() {
return new File("dummy-ignoreme");
}
};
}
}

Expand All @@ -61,7 +65,9 @@ private void assertJobPlanEquals(CraftingJobV2 job, IAEItemStack... stacks) {
assertNotNull(matching, stack::toString);
assertEquals(stack.getStackSize(), matching.getStackSize(), () -> "Stack size of " + stack);
assertEquals(
stack.getCountRequestable(), matching.getCountRequestable(), () -> "Requestable count of " + stack);
stack.getCountRequestable(),
matching.getCountRequestable(),
() -> "Requestable count of " + stack);
matching.setStackSize(0);
matching.setCountRequestable(0);
}
Expand All @@ -72,10 +78,8 @@ private void assertJobPlanEquals(CraftingJobV2 job, IAEItemStack... stacks) {
}

private void addDummyGappleRecipe(MockAESystem aeSystem) {
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Items.gold_ingot, 1))
.addOutput(new ItemStack(Items.golden_apple, 1))
.buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Items.gold_ingot, 1))
.addOutput(new ItemStack(Items.golden_apple, 1)).buildAndAdd();
}

@Test
Expand All @@ -92,10 +96,8 @@ void noPatternSimulation() {
void simplePatternSimulation() {
MockAESystem aeSystem = new MockAESystem(dummyWorld);
// Very expensive sticks
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Items.diamond, 1))
.addOutput(new ItemStack(Items.stick, 1))
.buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Items.diamond, 1))
.addOutput(new ItemStack(Items.stick, 1)).buildAndAdd();
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
Expand Down Expand Up @@ -127,10 +129,8 @@ void simplePatternWithItemsSimulation() {
aeSystem.addStoredItem(new ItemStack(Items.diamond, 64));
aeSystem.addStoredItem(new ItemStack(Items.gold_ingot, 64));
// Very expensive sticks
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Items.diamond, 1))
.addOutput(new ItemStack(Items.stick, 1))
.buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Items.diamond, 1))
.addOutput(new ItemStack(Items.stick, 1)).buildAndAdd();
// Another pattern that shouldn't match
addDummyGappleRecipe(aeSystem);
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Items.stick, 13));
Expand All @@ -146,36 +146,27 @@ void simplePatternWithItemsSimulation() {
private void addPlankPatterns(MockAESystem aeSystem) {
// Add all types of wood
for (int meta = 0; meta < 4; meta++) {
aeSystem.newCraftingPattern()
.allowBeingASubstitute()
.addInput(new ItemStack(Blocks.log, 1, meta))
.addOutput(new ItemStack(Blocks.planks, 4, meta))
.buildAndAdd();
aeSystem.newCraftingPattern().allowBeingASubstitute().addInput(new ItemStack(Blocks.log, 1, meta))
.addOutput(new ItemStack(Blocks.planks, 4, meta)).buildAndAdd();
}
}

private void addFuzzyChestPattern(MockAESystem aeSystem) {
aeSystem.newCraftingPattern()
.allowUsingSubstitutes()
aeSystem.newCraftingPattern().allowUsingSubstitutes()
// row 1
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1)).addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1))
// row 2
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(null)
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1)).addInput(null).addInput(new ItemStack(Blocks.planks, 1))
// row 3
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1)).addInput(new ItemStack(Blocks.planks, 1))
.addInput(new ItemStack(Blocks.planks, 1))
// end
.addOutput(new ItemStack(Blocks.chest, 1))
.buildAndAdd();
.addOutput(new ItemStack(Blocks.chest, 1)).buildAndAdd();
}

@ParameterizedTest
@ValueSource(ints = {0, 1})
@ValueSource(ints = { 0, 1 })
void craftChestFromLogs(int woodMetadata) {
MockAESystem aeSystem = new MockAESystem(dummyWorld);
aeSystem.addStoredItem(new ItemStack(Blocks.log, 64, woodMetadata));
Expand All @@ -191,8 +182,7 @@ void craftChestFromLogs(int woodMetadata) {
assertJobPlanEquals(
job,
AEItemStack.create(new ItemStack(Blocks.log, 2, woodMetadata)),
AEItemStack.create(new ItemStack(Blocks.planks, 0, woodMetadata))
.setCountRequestable(8),
AEItemStack.create(new ItemStack(Blocks.planks, 0, woodMetadata)).setCountRequestable(8),
AEItemStack.create(new ItemStack(Blocks.chest, 0)).setCountRequestable(1));
}

Expand Down Expand Up @@ -223,14 +213,10 @@ void craftChestFromMixedLogs() {
void canHandleCyclicalPatterns() {
MockAESystem aeSystem = new MockAESystem(dummyWorld);
aeSystem.addStoredItem(new ItemStack(Blocks.log, 4, 0));
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Blocks.log, 1))
.addOutput(new ItemStack(Blocks.planks, 4))
.buildAndAdd();
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Blocks.planks, 4))
.addOutput(new ItemStack(Blocks.log, 1))
.buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Blocks.log, 1))
.addOutput(new ItemStack(Blocks.planks, 4)).buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Blocks.planks, 4))
.addOutput(new ItemStack(Blocks.log, 1)).buildAndAdd();
for (int plankAmount = 1; plankAmount < 64; plankAmount++) {
final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.planks, plankAmount));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
Expand All @@ -242,11 +228,8 @@ void canHandleCyclicalPatterns() {
void strictNamedItems() {
MockAESystem aeSystem = new MockAESystem(dummyWorld);
aeSystem.addStoredItem(new ItemStack(Blocks.log, 4, 0).setStackDisplayName("Named Log"));
aeSystem.newProcessingPattern()
.addInput(new ItemStack(Blocks.log, 1))
.addOutput(new ItemStack(Blocks.planks, 4))
.allowBeingASubstitute()
.buildAndAdd();
aeSystem.newProcessingPattern().addInput(new ItemStack(Blocks.log, 1))
.addOutput(new ItemStack(Blocks.planks, 4)).allowBeingASubstitute().buildAndAdd();

final CraftingJobV2 job = aeSystem.makeCraftingJob(new ItemStack(Blocks.planks, 1));
simulateJobAndCheck(job, SIMPLE_SIMULATION_TIMEOUT_MS);
Expand Down
2 changes: 2 additions & 0 deletions src/functionalTest/java/appeng/test/DummySaveHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package appeng.test;

import java.io.File;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.MinecraftException;
import net.minecraft.world.WorldProvider;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.world.storage.WorldInfo;

public class DummySaveHandler implements ISaveHandler {

@Override
public WorldInfo loadWorldInfo() {
return null;
Expand Down
33 changes: 18 additions & 15 deletions src/functionalTest/java/appeng/test/mockme/MockAESystem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package appeng.test.mockme;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;

import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingGrid;
Expand All @@ -17,15 +26,9 @@
import appeng.me.storage.MEPassThrough;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;

public class MockAESystem implements ICellProvider {

public final World world;
public final MockGrid grid = new MockGrid();
public final BaseActionSource dummyActionSource = new BaseActionSource();
Expand All @@ -44,7 +47,9 @@ public MockAESystem addStoredItem(ItemStack stack) {
final IAEItemStack aeStack = AEItemStack.create(stack);
this.itemStorage.injectItems(aeStack, Actionable.MODULATE, dummyActionSource);
this.sgCache.postAlterationOfStoredItems(
StorageChannel.ITEMS, Collections.singletonList(aeStack), dummyActionSource);
StorageChannel.ITEMS,
Collections.singletonList(aeStack),
dummyActionSource);
return this;
}

Expand All @@ -67,6 +72,7 @@ public PatternBuilder newCraftingPattern() {
}

public class PatternBuilder {

public final boolean isCrafting;
public final List<ItemStack> inputs = new ArrayList<>(9);
public final List<ItemStack> outputs = new ArrayList<>(9);
Expand Down Expand Up @@ -108,11 +114,7 @@ public PatternBuilder addOutput(ItemStack stack) {
}

public void buildAndAdd() {
final ItemStack encodedPattern = AEApi.instance()
.definitions()
.items()
.encodedPattern()
.maybeStack(1)
final ItemStack encodedPattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1)
.get();
final NBTTagCompound patternTags = new NBTTagCompound();
patternTags.setBoolean("crafting", isCrafting);
Expand Down Expand Up @@ -145,8 +147,9 @@ public void buildAndAdd() {

// Simulated inventories
private final MECraftingInventory itemStorage = new MECraftingInventory();
private final IMEInventoryHandler<IAEItemStack> storageHandler =
new MEPassThrough<>(itemStorage, StorageChannel.ITEMS);
private final IMEInventoryHandler<IAEItemStack> storageHandler = new MEPassThrough<>(
itemStorage,
StorageChannel.ITEMS);

@Override
public List<IMEInventoryHandler> getCellArray(StorageChannel channel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package appeng.test.mockme;

import net.minecraft.inventory.InventoryCrafting;

import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import net.minecraft.inventory.InventoryCrafting;

public class MockCraftingMedium implements ICraftingMedium {

@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/functionalTest/java/appeng/test/mockme/MockGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import appeng.me.Grid;

public class MockGrid extends Grid {

public final MockGridNode rootNode;

public MockGrid() {
Expand Down
Loading

0 comments on commit ca7a649

Please sign in to comment.