创建 OSVersion 工具类 (#4480)

This commit is contained in:
Glavo
2025-09-14 20:13:43 +08:00
committed by GitHub
parent c2d5a07053
commit a10e9a04b1
11 changed files with 265 additions and 192 deletions

View File

@@ -0,0 +1,57 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.platform.OSVersion;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.versioning.VersionNumber;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/// @author Glavo
public class OSVersionTest {
@Test
public void testNotAcceptSystem() {
assertThrows(IllegalArgumentException.class, () -> new OSVersion.Generic(OperatingSystem.WINDOWS, VersionNumber.ZERO));
}
@Test
public void testParse() {
assertEquals(OSVersion.WINDOWS_7, OSVersion.Windows.parse("6.1"));
assertEquals(OSVersion.WINDOWS_10, OSVersion.Windows.parse("10.0"));
assertEquals(new OSVersion.Windows(10, 0, 26120), OSVersion.Windows.parse("10.0.26120"));
assertEquals(new OSVersion.Windows(10, 0, 26120), OSVersion.Windows.parse("10.0.26120-unknown"));
assertEquals(new OSVersion.Windows(10, 0, 26120, 3964), OSVersion.Windows.parse("10.0.26120.3964"));
assertEquals(new OSVersion.Windows(10, 0, 26120, 3964), OSVersion.Windows.parse("10.0.26120.3964-unknown"));
}
@Test
public void testIsAtLeast() {
assertTrue(OSVersion.WINDOWS_10.isAtLeast(OSVersion.WINDOWS_7));
assertTrue(OSVersion.WINDOWS_10.isAtLeast(OSVersion.WINDOWS_10));
assertFalse(OSVersion.WINDOWS_10.isAtLeast(OSVersion.WINDOWS_11));
assertFalse(OSVersion.WINDOWS_10.isAtLeast(OSVersion.of(OperatingSystem.LINUX, "4.0")));
assertTrue(OSVersion.of(OperatingSystem.LINUX, "4.0").isAtLeast(OSVersion.of(OperatingSystem.LINUX, "4.0")));
assertTrue(OSVersion.of(OperatingSystem.LINUX, "4.0").isAtLeast(OSVersion.of(OperatingSystem.LINUX, "3.0")));
assertFalse(OSVersion.of(OperatingSystem.LINUX, "4.0").isAtLeast(OSVersion.of(OperatingSystem.LINUX, "5.0")));
assertFalse(OSVersion.of(OperatingSystem.LINUX, "4.0").isAtLeast(OSVersion.of(OperatingSystem.WINDOWS, "4.0")));
}
}

View File

@@ -17,24 +17,10 @@
*/
package org.jackhuang.hmcl.util.platform.windows;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Glavo
*/
public final class WindowsVersionTest {
@Test
public void testParse() {
assertEquals(WindowsVersion.WINDOWS_7, new WindowsVersion("6.1"));
assertEquals(WindowsVersion.WINDOWS_10, new WindowsVersion("10.0"));
assertEquals(new WindowsVersion(10, 0, 26120), new WindowsVersion("10.0.26120"));
assertEquals(new WindowsVersion(10, 0, 26120), new WindowsVersion("10.0.26120-unknown"));
assertEquals(new WindowsVersion(10, 0, 26120, 3964), new WindowsVersion("10.0.26120.3964"));
assertEquals(new WindowsVersion(10, 0, 26120, 3964), new WindowsVersion("10.0.26120.3964-unknown"));
assertEquals(WindowsVersion.UNKNOWN, new WindowsVersion("unknown"));
}
}