// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // 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 com.google.crypto.tink.internal; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import com.google.crypto.tink.Key; import com.google.crypto.tink.Parameters; import com.google.errorprone.annotations.Immutable; import java.security.GeneralSecurityException; import javax.annotation.Nullable; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Tests for {@link MutablePrimitiveRegistryTest}. * *
We repeat the main tests in PrimitiveRegistryTest. There really shouldn't be both classes, but
* currently this is what we need, and the other is what we should have.
*/
@RunWith(JUnit4.class)
public final class MutablePrimitiveRegistryTest {
@Immutable
private static final class TestKey1 extends Key {
@Override
public Parameters getParameters() {
throw new UnsupportedOperationException("Not needed in test");
}
@Override
@Nullable
public Integer getIdRequirementOrNull() {
throw new UnsupportedOperationException("Not needed in test");
}
@Override
public boolean equalsKey(Key other) {
throw new UnsupportedOperationException("Not needed in test");
}
}
@Immutable
private static final class TestKey2 extends Key {
@Override
public Parameters getParameters() {
throw new UnsupportedOperationException("Not needed in test");
}
@Override
@Nullable
public Integer getIdRequirementOrNull() {
throw new UnsupportedOperationException("Not needed in test");
}
@Override
public boolean equalsKey(Key other) {
throw new UnsupportedOperationException("Not needed in test");
}
}
@Immutable
private static final class TestPrimitiveA {
public TestPrimitiveA() {}
}
@Immutable
private static final class TestPrimitiveB {
public TestPrimitiveB() {}
}
private static MutablePrimitiveRegistryTest.TestPrimitiveA getPrimitiveAKey1(
MutablePrimitiveRegistryTest.TestKey1 key) {
return new MutablePrimitiveRegistryTest.TestPrimitiveA();
}
private static MutablePrimitiveRegistryTest.TestPrimitiveA getPrimitiveAKey2(
MutablePrimitiveRegistryTest.TestKey2 key) {
return new MutablePrimitiveRegistryTest.TestPrimitiveA();
}
private static MutablePrimitiveRegistryTest.TestPrimitiveB getPrimitiveBKey1(
MutablePrimitiveRegistryTest.TestKey1 key) {
return new MutablePrimitiveRegistryTest.TestPrimitiveB();
}
private static MutablePrimitiveRegistryTest.TestPrimitiveB getPrimitiveBKey2(
MutablePrimitiveRegistryTest.TestKey2 key) {
return new MutablePrimitiveRegistryTest.TestPrimitiveB();
}
@Immutable
private static final class TestWrapperA
implements PrimitiveWrapper