Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added tests and fixed invalid comparison #828

Merged
merged 1 commit into from
Mar 11, 2025
Merged
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
11 changes: 8 additions & 3 deletions evita_common/src/main/java/io/evitadb/utils/VersionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2023-2024
* Copyright (c) 2023-2025
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,7 +83,12 @@ public record SemVer(
int minor,
@Nullable String patch,
boolean snapshot
) {
) implements Comparable<SemVer> {

@Override
public int compareTo(@Nonnull SemVer o) {
return compare(this, o);
}

/**
* Constructs a SemVer object from a string version.
Expand Down Expand Up @@ -132,7 +137,7 @@ public String toString() {
* -1 if v1 has a lesser major or minor version than v2
*/
public static int compare(@Nonnull SemVer v1, @Nonnull SemVer v2) {
if (v1.major() > v2.major() || v1.minor() > v2.minor()) {
if (v1.major() > v2.major() || (v1.major() == v2.major() && v1.minor() > v2.minor())) {
return 1;
} else if (v1.major() < v2.major() || v1.minor() < v2.minor()) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* _ _ ____ ____
* _____ _(_) |_ __ _| _ \| __ )
* / _ \ \ / / | __/ _` | | | | _ \
* | __/\ V /| | || (_| | |_| | |_) |
* \___| \_/ |_|\__\__,_|____/|____/
*
* Copyright (c) 2025
*
* Licensed under the Business Source License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/FgForrest/evitaDB/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.evitadb.utils;


import io.evitadb.utils.VersionUtils.SemVer;
import org.junit.jupiter.api.Test;

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

/**
* This test verifies contract of the {@link VersionUtils} class.
*
* @author Jan Novotný ([email protected]), FG Forrest a.s. (c) 2025
*/
public class VersionUtilsTest {

@Test
void shouldReturnExpectedSemVerComparisonResults() {
assertEquals(0, SemVer.fromString("1.0.0").compareTo(SemVer.fromString("1.0.0")));
assertEquals(0, SemVer.fromString("1.0.1").compareTo(SemVer.fromString("1.0.0")));
assertEquals(1, SemVer.fromString("1.1.0").compareTo(SemVer.fromString("1.0.0")));
assertEquals(-1, SemVer.fromString("1.1.0").compareTo(SemVer.fromString("1.2.0")));
assertEquals(1, SemVer.fromString("2025.1.0").compareTo(SemVer.fromString("2024.12.0")));
assertEquals(-1, SemVer.fromString("2024.12.0").compareTo(SemVer.fromString("2025.1.0")));
}
}
Loading