2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-02-25 20:02:42 +01:00
|
|
|
package org.pgpainless.algorithm;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
2022-03-22 15:09:09 +01:00
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
2021-02-25 20:02:42 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
2022-03-22 15:09:09 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
2021-02-25 20:02:42 +01:00
|
|
|
|
|
|
|
public class FeatureTest {
|
|
|
|
|
2022-03-22 15:09:09 +01:00
|
|
|
@Test
|
|
|
|
public void testAll() {
|
|
|
|
for (Feature feature : Feature.values()) {
|
|
|
|
assertEquals(feature, Feature.fromId(feature.getFeatureId()));
|
|
|
|
assertEquals(feature, Feature.requireFromId(feature.getFeatureId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-25 20:02:42 +01:00
|
|
|
@Test
|
|
|
|
public void testModificationDetection() {
|
|
|
|
Feature modificationDetection = Feature.MODIFICATION_DETECTION;
|
|
|
|
assertEquals(0x01, modificationDetection.getFeatureId());
|
|
|
|
assertEquals(modificationDetection, Feature.fromId((byte) 0x01));
|
2022-03-22 15:09:09 +01:00
|
|
|
assertEquals(modificationDetection, Feature.requireFromId((byte) 0x01));
|
2021-02-25 20:02:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testFromInvalidIdIsNull() {
|
|
|
|
assertNull(Feature.fromId((byte) 0x99));
|
|
|
|
}
|
2022-03-22 15:09:09 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testRequireFromInvalidThrows() {
|
|
|
|
assertThrows(NoSuchElementException.class, () -> Feature.requireFromId((byte) 0x99));
|
|
|
|
}
|
2021-02-25 20:02:42 +01:00
|
|
|
}
|