@@ -0,0 +1,3739 @@
+// Copyright (C) 2021 The Android Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.gerrit.plugins.codeowners.acceptance.api;%0A%0Aimport static com.google.common.truth.Truth.assertWithMessage;%0Aimport static com.google.gerrit.testing.GerritJUnit.assertThrows;%0A%0Aimport com.google.common.collect.Iterables;%0Aimport com.google.gerrit.extensions.restapi.NotImplementedException;%0Aimport com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;%0Aimport com.google.gerrit.plugins.codeowners.api.BranchCodeOwners;%0Aimport com.google.gerrit.plugins.codeowners.api.ChangeCodeOwners;%0Aimport com.google.gerrit.plugins.codeowners.api.CodeOwnerConfigs;%0Aimport com.google.gerrit.plugins.codeowners.api.CodeOwners;%0Aimport com.google.gerrit.plugins.codeowners.api.ProjectCodeOwners;%0Aimport com.google.gerrit.plugins.codeowners.api.RevisionCodeOwners;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0Aimport java.util.Arrays;%0Aimport org.junit.Test;%0A%0A/** Tests the %7B@code NotImplemented%7D classes of the code owners Java API. */%0Apublic class NotImplementedIT extends AbstractCodeOwnersTest %7B%0A  @Test%0A  public void allMethodsThrowNotImplementedException() throws Exception %7B%0A    assertNotImplemented(BranchCodeOwners.NotImplemented.class);%0A    assertNotImplemented(ChangeCodeOwners.NotImplemented.class);%0A    assertNotImplemented(CodeOwners.NotImplemented.class);%0A    assertNotImplemented(ProjectCodeOwners.NotImplemented.class);%0A    assertNotImplemented(RevisionCodeOwners.NotImplemented.class);%0A    assertNotImplemented(CodeOwnerConfigs.NotImplemented.class);%0A  %7D%0A%0A  private %3CT%3E void assertNotImplemented(Class%3CT%3E notImplementedClass) throws Exception %7B%0A    // Instantiate the NotImplemented class.%0A    T instance = notImplementedClass.getDeclaredConstructor().newInstance();%0A%0A    // NotImplemented classes should have exactly 1 interface.%0A    Class%3C?%3E apiInterface =%0A        Iterables.getOnlyElement(Arrays.asList(notImplementedClass.getInterfaces()));%0A%0A    // Iterator over all methods from the interface (if we would iterator over all methods from the%0A    // class, we would also get the methods that are inherited from Object, which we want to skip).%0A    for (Method method : apiInterface.getMethods()) %7B%0A      Object%5B%5D parameters = new Object%5Bmethod.getParameterCount()%5D;%0A      for (int i = 0; i %3C method.getParameterCount(); i++) %7B%0A        // For invoking the method use null for each parameter, except if it's a String, then use an%0A        // empty String (that's needed because there are some default method implementations that%0A        // fail with NPE if a null String is passed in).%0A        parameters%5Bi%5D = method.getParameterTypes()%5Bi%5D.equals(String.class) ? %22%22 : null;%0A      %7D%0A      // Invoking the method should throw a NotImplementedException. Since we use reflection to%0A      // invoke it, the NotImplementedException is wrapped in a InvocationTargetException.%0A      InvocationTargetException ex =%0A          assertThrows(InvocationTargetException.class, () -%3E method.invoke(instance, parameters));%0A      assertWithMessage(method.getName())%0A          .that(ex)%0A          .hasCauseThat()%0A          .isInstanceOf(NotImplementedException.class);%0A    %7D%0A  %7D%0A%7D%0A

Test NotImplemented Java API implementations