snoopdave commented on code in PR #182:
URL: https://github.com/apache/roller/pull/182#discussion_r3952334794


##########
app/src/test/java/org/apache/roller/weblogger/business/startup/DatabaseInstallerUpgradeTest.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0.
+ */
+package org.apache.roller.weblogger.business.startup;
+
+import java.sql.*;
+import org.apache.roller.weblogger.business.DatabaseProvider;
+import org.junit.jupiter.api.Test;
+import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+class DatabaseInstallerUpgradeTest {
+    @Test
+    void versionOnlyUpgradeReportsCompletion() throws Exception {
+        DatabaseProvider db = mock(DatabaseProvider.class);
+        DatabaseScriptProvider scripts = mock(DatabaseScriptProvider.class);
+        Connection con = mock(Connection.class);
+        Statement query = mock(Statement.class);
+        ResultSet rows = mock(ResultSet.class);
+        PreparedStatement update = mock(PreparedStatement.class);
+        when(db.getConnection()).thenReturn(con);
+        when(con.createStatement()).thenReturn(query);
+        when(query.executeQuery(anyString())).thenReturn(rows);
+        when(rows.next()).thenReturn(true);
+        when(rows.getString(1)).thenReturn("610");
+        when(con.prepareStatement(anyString())).thenReturn(update);
+        DatabaseInstaller installer = new DatabaseInstaller(db, scripts);
+        installer.upgradeDatabase(true);
+        verify(update).setString(1, "616");
+        verify(update).executeUpdate();
+        verifyNoInteractions(scripts);
+        assertTrue(installer.getMessages().stream().anyMatch(m -> 
m.contains("No table changes were required.")));
+        assertTrue(installer.getMessages().stream().anyMatch(m -> 
m.contains("Database version updated to 616.")));

Review Comment:
   🐞GLM Issue: **Important:** The expected version is hardcoded as `"616"` here 
and in `verify(update).setString(1, "616")` above, which pins this test to the 
current release number. The next version bump (6.1.6 → 6.1.7) will fail the 
test even though the behavior it checks is unchanged. Consider deriving the 
expectation from the same source `DatabaseInstaller` uses (the `ro.version` 
property in `/roller-version.properties`, parsed the same way 
`DatabaseInstaller.upgradeDatabase` does), or loosening the assertion to a 
pattern such as `Database version updated to \d+\.` — that keeps the test 
asserting the behavior (a version-only upgrade reports completion) rather than 
a specific release constant.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to