NoteDbSchemaUpdaterTest: Migrate from try-catch-fail to assertThrows
Change-Id: I8773b0503979115a6f48ba1958fe5d7aad65fae3
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
package com.google.gerrit.server.schema;
|
package com.google.gerrit.server.schema;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth.assert_;
|
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static com.google.gerrit.server.schema.NoteDbSchemaUpdater.requiredUpgrades;
|
import static com.google.gerrit.server.schema.NoteDbSchemaUpdater.requiredUpgrades;
|
||||||
|
import static com.google.gerrit.testing.GerritJUnit.assertThrows;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
@@ -61,26 +61,20 @@ public class NoteDbSchemaUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downgradeNotSupported() throws Exception {
|
public void downgradeNotSupported() throws Exception {
|
||||||
try {
|
StorageException thrown =
|
||||||
requiredUpgrades(14, versions(10, 11, 12, 13));
|
assertThrows(StorageException.class, () -> requiredUpgrades(14, versions(10, 11, 12, 13)));
|
||||||
assert_().fail("expected StorageException");
|
assertThat(thrown)
|
||||||
} catch (StorageException e) {
|
.hasMessageThat()
|
||||||
assertThat(e)
|
.contains("Cannot downgrade NoteDb schema from version 14 to 13");
|
||||||
.hasMessageThat()
|
|
||||||
.contains("Cannot downgrade NoteDb schema from version 14 to 13");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void skipToFirstVersionNotSupported() throws Exception {
|
public void skipToFirstVersionNotSupported() throws Exception {
|
||||||
ImmutableSortedSet<Integer> versions = versions(10, 11, 12);
|
ImmutableSortedSet<Integer> versions = versions(10, 11, 12);
|
||||||
assertThat(requiredUpgrades(9, versions)).containsExactly(10, 11, 12).inOrder();
|
assertThat(requiredUpgrades(9, versions)).containsExactly(10, 11, 12).inOrder();
|
||||||
try {
|
StorageException thrown =
|
||||||
requiredUpgrades(8, versions);
|
assertThrows(StorageException.class, () -> requiredUpgrades(8, versions));
|
||||||
assert_().fail("expected StorageException");
|
assertThat(thrown).hasMessageThat().contains("Cannot skip NoteDb schema from version 8 to 10");
|
||||||
} catch (StorageException e) {
|
|
||||||
assertThat(e).hasMessageThat().contains("Cannot skip NoteDb schema from version 8 to 10");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestUpdate {
|
private static class TestUpdate {
|
||||||
@@ -230,12 +224,8 @@ public class NoteDbSchemaUpdaterTest {
|
|||||||
seedGroupSequenceRef();
|
seedGroupSequenceRef();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
StorageException thrown = assertThrows(StorageException.class, () -> u.update());
|
||||||
u.update();
|
assertThat(thrown).hasMessageThat().contains("NoteDb change migration was not completed");
|
||||||
assert_().fail("expected StorageException");
|
|
||||||
} catch (StorageException e) {
|
|
||||||
assertThat(e).hasMessageThat().contains("NoteDb change migration was not completed");
|
|
||||||
}
|
|
||||||
assertThat(u.getMessages()).isEmpty();
|
assertThat(u.getMessages()).isEmpty();
|
||||||
assertThat(u.readVersion()).isEmpty();
|
assertThat(u.readVersion()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -249,12 +239,8 @@ public class NoteDbSchemaUpdaterTest {
|
|||||||
setNotesMigrationConfig();
|
setNotesMigrationConfig();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
StorageException thrown = assertThrows(StorageException.class, () -> u.update());
|
||||||
u.update();
|
assertThat(thrown).hasMessageThat().contains("upgrade to 2.16.x first");
|
||||||
assert_().fail("expected StorageException");
|
|
||||||
} catch (StorageException e) {
|
|
||||||
assertThat(e).hasMessageThat().contains("upgrade to 2.16.x first");
|
|
||||||
}
|
|
||||||
assertThat(u.getMessages()).isEmpty();
|
assertThat(u.getMessages()).isEmpty();
|
||||||
assertThat(u.readVersion()).isEmpty();
|
assertThat(u.readVersion()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user