|
| 1 | +/** ****************************************************************************** |
| 2 | + * Copyright (c) 2026 Eclipse Foundation and others |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * ****************************************************************************** */ |
| 10 | +package org.eclipse.openvsx.entities; |
| 11 | + |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 15 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 16 | + |
| 17 | +class ExtensionVersionTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + void setStateRejectsTransitionAwayFromDeleted() { |
| 21 | + var version = new ExtensionVersion(); |
| 22 | + version.setState(ExtensionVersion.State.DELETED); |
| 23 | + |
| 24 | + assertThrows(IllegalStateException.class, () -> version.setState(ExtensionVersion.State.ACTIVE)); |
| 25 | + assertThrows(IllegalStateException.class, () -> version.setState(ExtensionVersion.State.INACTIVE)); |
| 26 | + assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED); |
| 27 | + assertThat(version.isActive()).isFalse(); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + void setStateDeletedIsIdempotent() { |
| 32 | + var version = new ExtensionVersion(); |
| 33 | + version.setState(ExtensionVersion.State.DELETED); |
| 34 | + |
| 35 | + version.setState(ExtensionVersion.State.DELETED); |
| 36 | + assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void setActiveOnDeletedVersionThrows() { |
| 41 | + var version = new ExtensionVersion(); |
| 42 | + version.setState(ExtensionVersion.State.DELETED); |
| 43 | + |
| 44 | + assertThrows(IllegalStateException.class, () -> version.setActive(false)); |
| 45 | + assertThrows(IllegalStateException.class, () -> version.setActive(true)); |
| 46 | + assertThat(version.getState()).isEqualTo(ExtensionVersion.State.DELETED); |
| 47 | + assertThat(version.isActive()).isFalse(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void setActiveTransitionsBetweenActiveAndInactive() { |
| 52 | + var version = new ExtensionVersion(); |
| 53 | + |
| 54 | + version.setActive(false); |
| 55 | + assertThat(version.getState()).isEqualTo(ExtensionVersion.State.INACTIVE); |
| 56 | + assertThat(version.isActive()).isFalse(); |
| 57 | + |
| 58 | + version.setActive(true); |
| 59 | + assertThat(version.getState()).isEqualTo(ExtensionVersion.State.ACTIVE); |
| 60 | + assertThat(version.isActive()).isTrue(); |
| 61 | + } |
| 62 | +} |
0 commit comments