• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.internal.codegen.javapoet;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static dagger.internal.codegen.javapoet.CodeBlocks.toParametersCodeBlock;
21 
22 import com.squareup.javapoet.CodeBlock;
23 import java.util.stream.Stream;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.JUnit4;
27 
28 /** Tests for {@link CodeBlocks}. */
29 @RunWith(JUnit4.class)
30 public final class CodeBlocksTest {
31   private static final CodeBlock objectO = CodeBlock.of("$T o", Object.class);
32   private static final CodeBlock stringS = CodeBlock.of("$T s", String.class);
33   private static final CodeBlock intI = CodeBlock.of("$T i", int.class);
34 
35   @Test
testToParametersCodeBlock()36   public void testToParametersCodeBlock() {
37     assertThat(Stream.of(objectO, stringS, intI).collect(toParametersCodeBlock()))
38         .isEqualTo(CodeBlock.of("$T o, $T s, $T i", Object.class, String.class, int.class));
39   }
40 
41   @Test
testToParametersCodeBlock_empty()42   public void testToParametersCodeBlock_empty() {
43     assertThat(Stream.<CodeBlock>of().collect(toParametersCodeBlock())).isEqualTo(CodeBlock.of(""));
44   }
45 
46   @Test
testToParametersCodeBlock_oneElement()47   public void testToParametersCodeBlock_oneElement() {
48     assertThat(Stream.of(objectO).collect(toParametersCodeBlock())).isEqualTo(objectO);
49   }
50 }
51