Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void setup() {
@Test
public void testItems() {
Identifier id = Registries.ITEM.getId(Items.DIAMOND);
assertEquals(id.toString(), "minecraft:diamond");
assertEquals("minecraft:diamond", id.toString());

System.out.println(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) throws IOException {
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (file.getFileName().toString().endsWith(".jar")) {
check(file, path.relativize(file).toString(), invalid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public void setup() {
Type listType = new TypeToken<List<MinecraftVersion>>() {
}.getType();

try (Reader reader = new InputStreamReader(VersionNormalizationAntiRegressionTest.class.getClassLoader()
.getResourceAsStream(MINECRAFT_VERSIONS_RESOURCE))) {
try (Reader reader = new InputStreamReader(Objects
.requireNonNull(VersionNormalizationAntiRegressionTest.class.getClassLoader()
.getResourceAsStream(MINECRAFT_VERSIONS_RESOURCE)))) {
expectedResults = gson.fromJson(reader, listType);
} catch (IOException e) {
throw new RuntimeException("Failed to read in existing versions from json", e);
Expand Down Expand Up @@ -174,8 +175,9 @@ public void confirmAllUnique() throws VersionParsingException {
private Set<Set<String>> getRereleasedVersions() {
Set<Set<String>> vs = new HashSet<>();

try (Reader reader = new InputStreamReader(VersionNormalizationAntiRegressionTest.class.getClassLoader()
.getResourceAsStream("duplicate_versions.json"))) {
try (Reader reader = new InputStreamReader(Objects
.requireNonNull(VersionNormalizationAntiRegressionTest.class.getClassLoader()
.getResourceAsStream("duplicate_versions.json")))) {
JsonParser parser = new JsonParser();

for (JsonElement grpElem : parser.parse(reader).getAsJsonObject().getAsJsonArray("duplicates")) {
Expand Down Expand Up @@ -254,9 +256,8 @@ private static List<MinecraftVersion> getMojangData() throws MalformedURLExcepti

try (Reader in = new InputStreamReader(url.openStream())) {
PistonMetaV2 pistonMetaV2 = gson.fromJson(in, PistonMetaV2.class);
pistonMetaV2.versions.forEach(v -> {
minecraftVersions.add(new MinecraftVersion(v.id, v.releaseTime.toInstant()));
});
pistonMetaV2.versions.forEach(v ->
minecraftVersions.add(new MinecraftVersion(v.id, v.releaseTime.toInstant())));
} catch (IOException e) {
throw new RuntimeException("Failed to read PistonV2 meta", e);
}
Expand All @@ -279,9 +280,8 @@ private static List<MinecraftVersion> getFabricMirror() throws MalformedURLExcep

try (Reader in = new InputStreamReader(url.openStream())) {
FabricMeta fabricMeta = gson.fromJson(in, FabricMeta.class);
fabricMeta.versions.forEach(v -> {
minecraftVersions.add(new MinecraftVersion(v.id, v.releaseTime.toInstant()));
});
fabricMeta.versions.forEach(v ->
minecraftVersions.add(new MinecraftVersion(v.id, v.releaseTime.toInstant())));
} catch (IOException e) {
throw new RuntimeException("Failed to read PistonV2 meta", e);
}
Expand Down Expand Up @@ -351,14 +351,15 @@ private static List<MinecraftVersion> getVersionsFromOmniArchive(String urlS) th
}

private static List<String> parseCsvLine(String line) {
// Let's just do the simple parsing for this, it isn't run often anyways
// Let's just do the simple parsing for this, it isn't run often anyway
return Arrays.asList(line.split(","));
}

/**
* <a href="https://piston-meta.mojang.com/mc/game/version_manifest_v2.json">Metadata</a>.
*/
private static class PistonMetaV2 {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
List<Version> versions;

static class Version {
Expand All @@ -372,6 +373,7 @@ static class Version {
* <a href="https://maven.fabricmc.net/net/minecraft/experimental_versions.json">Metadata</a>.
*/
private static class FabricMeta {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
List<Version> versions;

static class Version {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package net.fabricmc.test;

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -241,7 +242,7 @@ public void tearDown() {
public void testGetRelease() {
for (MinecraftVersion result : expectedResults) {
for (NormalizedVersion entry : result.entries) {
Assertions.assertEquals(entry.release, McVersionLookup.getRelease(entry.version), "getRelease(" + entry.version + ")");
assertEquals(entry.release, McVersionLookup.getRelease(entry.version), "getRelease(" + entry.version + ")");
}
}
}
Expand All @@ -250,7 +251,7 @@ public void testGetRelease() {
public void testNormalizeVersion() {
for (MinecraftVersion result : expectedResults) {
for (NormalizedVersion entry : result.entries) {
Assertions.assertEquals(entry.normalizedVersion, McVersionLookup.normalizeVersion(entry.version, entry.release), "normalizeVersion(" + entry.version + ", " + entry.release + ")");
assertEquals(entry.normalizedVersion, McVersionLookup.normalizeVersion(entry.version, entry.release), "normalizeVersion(" + entry.version + ", " + entry.release + ")");
}
}
}
Expand All @@ -270,9 +271,9 @@ public void testVersionComparison() throws Exception {
Version v2 = result2.entries.get(l).semver();

if (i == k) {
Assertions.assertEquals(true, v1.compareTo(v2) == 0, v1.toString() + " == " + v2.toString());
assertEquals(0, v1.compareTo(v2), v1 + " == " + v2);
} else {
Assertions.assertEquals(i > k, v1.compareTo(v2) > 0, v1.toString() + " > " + v2.toString());
assertEquals(i > k, v1.compareTo(v2) > 0, v1 + " > " + v2);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void tearDown() {
*/
@Test
public void testGetNonFabricMods() throws ModResolutionException {
List<ModCandidateImpl> acceptedMods = discoverer.discoverMods(loader, new HashMap<String, Set<ModCandidateImpl>>());
List<ModCandidateImpl> acceptedMods = discoverer.discoverMods(loader, new HashMap<>());

boolean foundDummyFabricMod = false;

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/net/fabricmc/test/ArgumentParsingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package net.fabricmc.test;

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

import org.junit.jupiter.api.Test;

import net.fabricmc.loader.impl.util.Arguments;
Expand All @@ -28,9 +29,9 @@ public void parseNormal() {
arguments.parse(new String[]{"--clientId", "123", "--xuid", "abc", "--versionType", "release"});
arguments.put("versionType", "Fabric");

Assertions.assertEquals(arguments.keys().size(), 3);
Assertions.assertEquals(arguments.get("xuid"), "abc");
Assertions.assertEquals(arguments.get("versionType"), "Fabric");
assertEquals(3, arguments.keys().size());
assertEquals("abc", arguments.get("xuid"));
assertEquals("Fabric", arguments.get("versionType"));
}

@Test
Expand All @@ -39,8 +40,8 @@ public void parseMissing() {
arguments.parse(new String[]{"--clientId", "123", "--xuid", "--versionType", "release"});
arguments.put("versionType", "Fabric");

Assertions.assertEquals(arguments.keys().size(), 3);
Assertions.assertEquals(arguments.get("xuid"), "");
Assertions.assertEquals(arguments.get("versionType"), "Fabric");
assertEquals(3, arguments.keys().size());
assertEquals("", arguments.get("xuid"));
assertEquals("Fabric", arguments.get("versionType"));
}
}
2 changes: 1 addition & 1 deletion src/test/java/net/fabricmc/test/LogNonFabricModsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setUp() {
*/
@Test
public void testLogNonFabricMods() {
List<Path> nonFabricMods = new ArrayList<Path>();
List<Path> nonFabricMods = new ArrayList<>();
nonFabricMods.add(Paths.get("mods/non_fabric_mod1.jar"));
nonFabricMods.add(Paths.get("mods/non_fabric_mod2.jar"));
nonFabricMods.add(Paths.get("mods/non_fabric_mod3.jar"));
Expand Down
24 changes: 10 additions & 14 deletions src/test/java/net/fabricmc/test/V1ModJsonParsingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package net.fabricmc.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -43,14 +38,15 @@
import net.fabricmc.loader.impl.metadata.ParseMetadataException;
import net.fabricmc.loader.impl.metadata.VersionOverrides;

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

final class V1ModJsonParsingTests {
private static Path testLocation;
private static Path specPath;
private static Path errorPath;

@BeforeAll
public static void setupPaths() {
testLocation = new File(System.getProperty("user.dir"))
Path testLocation = new File(System.getProperty("user.dir"))
.toPath()
.resolve("src")
.resolve("test")
Expand Down Expand Up @@ -142,7 +138,7 @@ private void validateRequiredValues(LoaderModMetadata metadata) {
final String friendlyString = metadata.getVersion().getFriendlyString();
assertEquals("1.0.0-SNAPSHOT", friendlyString, String.format("Version \"%s\" was found, expected \"1.0.0-SNAPSHOT\"", friendlyString));

assertTrue(metadata.getVersion() instanceof SemanticVersion, "Parsed version was not a semantic version, expected a semantic version");
assertInstanceOf(SemanticVersion.class, metadata.getVersion(), "Parsed version was not a semantic version, expected a semantic version");
}

@Test
Expand Down Expand Up @@ -202,16 +198,16 @@ private void validateIconPath(LoaderModMetadata metadata, int preferredSize, int
@Test
public void verifyMissingVersionFails() {
// Missing version should throw an exception
assertThrows(ParseMetadataException.MissingField.class, () -> {
parseMetadata(errorPath.resolve("missing_version.json"));
}, "Missing version exception was not caught");
assertThrows(ParseMetadataException.MissingField.class, () ->
parseMetadata(errorPath.resolve("missing_version.json")),
"Missing version exception was not caught");
}

@Test
public void validateDuplicateSchemaVersionMismatchFails() {
assertThrows(ParseMetadataException.class, () -> {
parseMetadata(errorPath.resolve("missing_version.json"));
}, "Parser did not fail when the duplicate \"schemaVersion\" mismatches");
assertThrows(ParseMetadataException.class, () ->
parseMetadata(errorPath.resolve("missing_version.json")),
"Parser did not fail when the duplicate \"schemaVersion\" mismatches");
}

/*
Expand Down