package com.google.api.generator.engine.ast;

import static org.junit.Assert.assertThrows;

import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Test;

public class MethodInvocationExprTest {

  @Test
  public void validBuildMethodInvocationExpr() {
    Reference stringRef = ConcreteReference.withClazz(String.class);
    TypeNode returnType =
        TypeNode.withReference(
            ConcreteReference.builder()
                .setClazz(ArrayList.class)
                .setGenerics(Arrays.asList(stringRef))
                .build());

    MethodInvocationExpr.builder().setMethodName("getSomeList").setReturnType(returnType).build();
    // No exception thrown, we're good.
  }

  @Test
  public void invalidBuildMethodInvocationExpr_nullReturnType() {
    assertThrows(
        IllegalStateException.class,
        () -> {
          MethodInvocationExpr.builder()
              .setMethodName("invalid")
              .setReturnType(TypeNode.NULL)
              .build();
        });
  }

  @Test
  public void invalidBuildMethodInvocationExpr_staticAndExprBoth() {
    assertThrows(
        IllegalStateException.class,
        () -> {
          Variable variable = Variable.builder().setType(TypeNode.INT).setName("someVar").build();
          VariableExpr varExpr = VariableExpr.builder().setVariable(variable).build();
          MethodInvocationExpr.builder()
              .setMethodName("foobar")
              .setGenerics(Arrays.asList(ConcreteReference.withClazz(String.class)))
              .setStaticReferenceName("someClass")
              .setExprReferenceExpr(varExpr)
              .setReturnType(TypeNode.STRING)
              .build();
        });
  }
}

@@ -1,8 +1,597 @@
+// Copyright 2020 Google LLC%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%0A
 package 

add license