aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java')
-rw-r--r--src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java b/src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java
new file mode 100644
index 0000000..8fd68be
--- /dev/null
+++ b/src/test/java/com/squareup/javawriter/builders/TypeSpecTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 Square, Inc.
+ *
+ * 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.squareup.javawriter.builders;
+
+import com.squareup.javawriter.ClassName;
+import javax.lang.model.element.Modifier;
+import org.junit.Test;
+
+import static com.google.common.truth.Truth.assertThat;
+
+public class TypeSpecTest {
+ @Test public void test() throws Exception {
+ TypeSpec taco = new TypeSpec.Builder()
+ .name(ClassName.create("com.squareup.tacos", "Taco"))
+ .addMethod(new MethodSpec.Builder()
+ .name("toString")
+ .addAnnotation(Override.class)
+ .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
+ .returns(String.class)
+ .addCode("return $S;\n", "taco")
+ .build())
+ .build();
+
+ // TODO: fix modifiers
+ // TODO: fix annotations
+
+ assertThat(toString(taco)).isEqualTo(""
+ + "package com.squareup.tacos;\n"
+ + "\n"
+ + "import java.lang.String;\n"
+ + "\n"
+ + "class Taco {\n"
+ + " String toString() {\n"
+ + " return \"taco\";\n"
+ + " }\n"
+ + "}\n");
+ }
+
+ private String toString(TypeSpec typeSpec) {
+ return new JavaFile.Builder()
+ .classSpec(typeSpec)
+ .build()
+ .toString();
+ }
+}