diff --git a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java index 5463ac76ad..5c5b2d5773 100644 --- a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java @@ -123,7 +123,7 @@ public void writeNewObjectExprImports_basic() { .setType(TypeNode.withReference(ConcreteReference.withClazz(ArrayList.class))) .build(); newObjectExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import java.util.ArrayList;\n\n"); + assertEquals("import java.util.ArrayList;\n\n", writerVisitor.write()); } @Test @@ -141,9 +141,9 @@ public void writeNewObjectExprImports_withArgs() { .build(); newObjectExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( - createLines(2), "import java.io.File;\n", "import java.io.FileOutputStream;\n\n")); + createLines(2), "import java.io.File;\n", "import java.io.FileOutputStream;\n\n"), + writerVisitor.write()); } @Test @@ -174,8 +174,8 @@ public void writeNewObjectExprImports_genericsAndVariableArgs() { .build(); newObjectExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format(createLines(2), "import java.util.HashMap;\n", "import java.util.List;\n\n")); + String.format(createLines(2), "import java.util.HashMap;\n", "import java.util.List;\n\n"), + writerVisitor.write()); } @Test @@ -203,9 +203,9 @@ public void writeNewObjectExprImports_methodExprArg() { .build(); newObjectExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( - createLines(2), "import java.io.IOException;\n", "import java.util.HashMap;\n\n")); + createLines(2), "import java.io.IOException;\n", "import java.util.HashMap;\n\n"), + writerVisitor.write()); } @Test @@ -239,12 +239,12 @@ public void writeTernaryExprImports() { .build(); ternaryExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import com.google.api.generator.engine.ast.Expr;\n", "import com.google.api.generator.engine.ast.TypeNode;\n", - "import com.google.common.base.Strings;\n\n")); + "import com.google.common.base.Strings;\n\n"), + writerVisitor.write()); } @Test @@ -273,12 +273,12 @@ public void writeAssignmentExprImports() { assignExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import com.google.api.generator.engine.ast.AstNode;\n", "import com.google.api.generator.engine.ast.ClassDefinition;\n", - "import com.google.api.some.pakkage.SomeClass;\n\n")); + "import com.google.api.some.pakkage.SomeClass;\n\n"), + writerVisitor.write()); } @Test @@ -328,7 +328,6 @@ public void writeAssignmentExprImports_concreteAndNestedGenerics() { assignExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(7), "import static java.util.Map.Entry;\n\n", @@ -337,7 +336,8 @@ public void writeAssignmentExprImports_concreteAndNestedGenerics() { "import com.google.api.generator.engine.ast.ClassDefinition;\n", "import java.util.ArrayList;\n", "import java.util.List;\n", - "import java.util.Map;\n\n")); + "import java.util.Map;\n\n"), + writerVisitor.write()); } @Test @@ -370,12 +370,12 @@ public void writeAssignmentExprImports_static() { assignExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import static java.util.Map.Entry;\n\n", "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import com.google.api.generator.engine.ast.AstNode;\n\n")); + "import com.google.api.generator.engine.ast.AstNode;\n\n"), + writerVisitor.write()); } @Test @@ -408,12 +408,12 @@ public void writeAssignmentExprImports_notStatic() { assignExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.AstNode;\n", - "import java.util.Map;\n\n")); + "import java.util.Map;\n\n"), + writerVisitor.write()); } @Test @@ -428,11 +428,11 @@ public void writeCastExprImports() { .build(); castExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import com.google.api.generator.engine.ast.Expr;\n\n")); + "import com.google.api.generator.engine.ast.Expr;\n\n"), + writerVisitor.write()); } @Test @@ -471,12 +471,12 @@ public void importFromVaporAndConcreteReferences() { varExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import com.google.api.generator.engine.ast.MethodDefinition;\n", "import java.util.HashMap;\n", - "import java.util.List;\n\n")); + "import java.util.List;\n\n"), + writerVisitor.write()); } @Test @@ -489,8 +489,8 @@ public void writeVariableExprImports_basic() { VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build(); variableExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format(createLines(1), "import com.google.api.generator.engine.ast.Expr;\n\n")); + String.format(createLines(1), "import com.google.api.generator.engine.ast.Expr;\n\n"), + writerVisitor.write()); } @Test @@ -509,11 +509,11 @@ public void writeVariableExprImports_staticReference() { variableExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import com.google.api.generator.engine.ast.TypeNode;\n\n")); + "import com.google.api.generator.engine.ast.TypeNode;\n\n"), + writerVisitor.write()); } @Test @@ -531,7 +531,7 @@ public void writeVariableExprImports_wildcardType() { VariableExpr.builder().setIsDecl(true).setVariable(variable).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import java.util.List;\n\n"); + assertEquals("import java.util.List;\n\n", writerVisitor.write()); } @Test @@ -553,11 +553,11 @@ public void writeVariableExprImport_wildcardTypeWithUpperBound() { variableExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.Expr;\n", - "import java.util.List;\n\n")); + "import java.util.List;\n\n"), + writerVisitor.write()); } @Test @@ -578,11 +578,11 @@ public void writeVariableExprImports_reference() { VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build(); variableExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import com.google.api.generator.engine.ast.Expr;\n\n")); + "import com.google.api.generator.engine.ast.Expr;\n\n"), + writerVisitor.write()); } @Test @@ -611,12 +611,12 @@ public void writeVariableExprImports_nestedReference() { variableExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.Expr;\n", - "import com.google.api.generator.engine.ast.VariableExpr;\n\n")); + "import com.google.api.generator.engine.ast.VariableExpr;\n\n"), + writerVisitor.write()); } @Test @@ -685,14 +685,14 @@ public void writeAnonymousClassExprImports() { .build(); anonymousClassExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(5), "import com.google.api.generator.engine.ast.MethodDefinition;\n", "import com.google.common.base.Function;\n", "import java.io.IOException;\n", "import java.util.HashMap;\n", - "import java.util.List;\n\n")); + "import java.util.List;\n\n"), + writerVisitor.write()); } @Test @@ -703,7 +703,7 @@ public void writeThrowExprImports_basic() { ThrowExpr throwExpr = ThrowExpr.builder().setType(exceptionTypes).setMessageExpr(message).build(); throwExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import java.io.IOException;\n\n"); + assertEquals("import java.io.IOException;\n\n", writerVisitor.write()); } @Test @@ -727,11 +727,11 @@ public void writeThrowExprImports_messageExpr() { throwExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.Expr;\n", - "import com.google.api.generator.engine.ast.IfStatement;\n\n")); + "import com.google.api.generator.engine.ast.IfStatement;\n\n"), + writerVisitor.write()); } @Test @@ -747,11 +747,11 @@ public void writeInstanceofExprImports_basic() { InstanceofExpr.builder().setExpr(variableExpr).setCheckType(exprType).build(); expr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import com.google.api.generator.engine.ast.Expr;\n\n")); + "import com.google.api.generator.engine.ast.Expr;\n\n"), + writerVisitor.write()); } @Test @@ -766,8 +766,8 @@ public void writeEnumRefExprImports_basic() { enumRefExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), - "import static com.google.api.generator.engine.ast.TypeNode.TypeKind;\n\n"); + "import static com.google.api.generator.engine.ast.TypeNode.TypeKind;\n\n", + writerVisitor.write()); } @Test @@ -776,7 +776,7 @@ public void writeEnumRefExprImports_nested() { TypeNode.withReference(ConcreteReference.withClazz(TypeNode.TypeKind.class)); EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build(); enumRefExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.api.generator.engine.ast.TypeNode;\n\n"); + assertEquals("import com.google.api.generator.engine.ast.TypeNode;\n\n", writerVisitor.write()); } @Test @@ -788,7 +788,7 @@ public void writeReturnExprImports_basic() { .setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))) .build()); returnExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.api.generator.engine.ast.Expr;\n\n"); + assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write()); } @Test @@ -827,11 +827,11 @@ public void writeMethodDefinitionImports_templatedMixedNamesAndTypes() { .build(); methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import java.util.Map;\n\n")); + "import java.util.Map;\n\n"), + writerVisitor.write()); } @Test @@ -842,7 +842,7 @@ public void writeReferenceConstructorExprImports_basic() { ReferenceConstructorExpr referenceConstructorExpr = ReferenceConstructorExpr.superBuilder().setType(classType).build(); referenceConstructorExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.example.v1.Parent;\n\n"); + assertEquals("import com.google.example.v1.Parent;\n\n", writerVisitor.write()); } @Test @@ -877,7 +877,7 @@ public void writeArithmeticOperationExprImports() { ArithmeticOperationExpr arithmeticOperationExpr = ArithmeticOperationExpr.concatWithExprs(lhsExpr, rhsExpr); arithmeticOperationExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.api.generator.engine.ast.Expr;\n\n"); + assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write()); } @Test @@ -897,11 +897,11 @@ public void writeSynchronizedStatementImports_basicThis() { .build(); synchronizedStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.Expr;\n", - "import java.util.Arrays;\n\n")); + "import java.util.Arrays;\n\n"), + writerVisitor.write()); } @Test @@ -920,7 +920,7 @@ public void writeSuperObjectValueImports() { .setReturnType(TypeNode.STRING) .build(); methodExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.example.examples.v1.Student;\n\n"); + assertEquals("import com.google.example.examples.v1.Student;\n\n", writerVisitor.write()); } @Test @@ -945,11 +945,11 @@ public void writeSynchronizedStatementImports_basicVariableExpr() { .build(); synchronizedStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.ast.AssignmentExpr;\n", - "import java.util.Map;\n\n")); + "import java.util.Map;\n\n"), + writerVisitor.write()); } @Test @@ -962,7 +962,7 @@ public void writeUnaryOperationExprImports_LogicalNot() { .build(); UnaryOperationExpr unaryOperationExpr = UnaryOperationExpr.logicalNotWithExpr(expr); unaryOperationExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.api.generator.engine.ast.Expr;\n\n"); + assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write()); } @Test @@ -975,7 +975,7 @@ public void writeUnaryOperationExprImports_PostIncrement() { .build(); UnaryOperationExpr unaryOperationExpr = UnaryOperationExpr.postfixIncrementWithExpr(expr); unaryOperationExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import com.google.api.generator.engine.ast.Expr;\n\n"); + assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write()); } @Test @@ -1002,11 +1002,11 @@ public void writeRelationalOperationExprImports() { RelationalOperationExpr.equalToWithExprs(lhsExpr, rhsExpr); relationalOperationExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(2), "import com.google.api.generator.engine.SomeClass;\n", - "import com.google.api.generator.engine.ast.Expr;\n\n")); + "import com.google.api.generator.engine.ast.Expr;\n\n"), + writerVisitor.write()); } @Test @@ -1024,8 +1024,8 @@ public void writeLogicalOperationExprImports() { LogicalOperationExpr.logicalAndWithExprs(lhsExpr, rhsExpr); logicalOperationExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), - "import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n"); + "import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n", + writerVisitor.write()); } @Test @@ -1052,7 +1052,7 @@ public void writePackageInfoDefinitionImports() { .build(); packageInfo.accept(writerVisitor); - assertEquals(writerVisitor.write(), "import javax.annotation.Generated;\n\n"); + assertEquals("import javax.annotation.Generated;\n\n", writerVisitor.write()); } /** =============================== HELPERS =============================== */ diff --git a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java index dac3d20756..98379fac93 100644 --- a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java @@ -90,7 +90,7 @@ public void setUp() { public void writeIdentifier() { String idName = "foobar"; IdentifierNode.builder().setName(idName).build().accept(writerVisitor); - assertEquals(writerVisitor.write(), idName); + assertEquals(idName, writerVisitor.write()); } @Test @@ -98,7 +98,7 @@ public void writePrimitiveType() { TypeNode intType = TypeNode.INT; assertThat(intType).isNotNull(); intType.accept(writerVisitor); - assertEquals(writerVisitor.write(), "int"); + assertEquals("int", writerVisitor.write()); } @Test @@ -107,7 +107,7 @@ public void writePrimitiveArrayType() { TypeNode.builder().setTypeKind(TypeNode.TypeKind.BYTE).setIsArray(true).build(); assertThat(byteArrayType).isNotNull(); byteArrayType.accept(writerVisitor); - assertEquals(writerVisitor.write(), "byte[]"); + assertEquals("byte[]", writerVisitor.write()); } @Test @@ -144,14 +144,14 @@ public void writeReferenceType_useFullName() { public void writeAnnotation_simple() { AnnotationNode annotation = AnnotationNode.OVERRIDE; annotation.accept(writerVisitor); - assertEquals(writerVisitor.write(), "@Override\n"); + assertEquals("@Override\n", writerVisitor.write()); } @Test public void writeAnnotation_withDescription() { AnnotationNode annotation = AnnotationNode.withSuppressWarnings("all"); annotation.accept(writerVisitor); - assertEquals(writerVisitor.write(), "@SuppressWarnings(\"all\")\n"); + assertEquals("@SuppressWarnings(\"all\")\n", writerVisitor.write()); } @Test @@ -161,7 +161,7 @@ public void writeNewObjectExpr_basic() { TypeNode type = TypeNode.withReference(ref); NewObjectExpr newObjectExpr = NewObjectExpr.builder().setIsGeneric(true).setType(type).build(); newObjectExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "new List<>()"); + assertEquals("new List<>()", writerVisitor.write()); } @Test @@ -182,7 +182,7 @@ public void writeNewObjectExpr_withMethodExprArgs() { .setArguments(Arrays.asList(msgExpr, causeExpr)) .build(); newObjectExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "new IOException(message, cause())"); + assertEquals("new IOException(message, cause())", writerVisitor.write()); } @Test @@ -222,7 +222,7 @@ public void writeNewObjectExpr_withGenericsAndArgs() { .build(); newObjectExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), "new HashMap>(SomeClass.foobar(), num)"); + "new HashMap>(SomeClass.foobar(), num)", writerVisitor.write()); } /** =============================== EXPRESSIONS =============================== */ @@ -231,7 +231,7 @@ public void writeValueExpr() { Value value = PrimitiveValue.builder().setType(TypeNode.INT).setValue("3").build(); ValueExpr valueExpr = ValueExpr.builder().setValue(value).build(); valueExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "3"); + assertEquals("3", writerVisitor.write()); } @Test @@ -240,7 +240,7 @@ public void writeVariableExpr_basic() { VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x"); + assertEquals("x", writerVisitor.write()); } @Test @@ -257,7 +257,7 @@ public void writeVariableExpr_wildcardType() { VariableExpr.builder().setIsDecl(true).setVariable(variable).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "List x"); + assertEquals("List x", writerVisitor.write()); } @Test @@ -277,7 +277,7 @@ public void writeVariableExpr_wildcardTypeWithUpperBound() { VariableExpr.builder().setIsDecl(true).setVariable(variable).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "List x"); + assertEquals("List x", writerVisitor.write()); } @Test @@ -290,7 +290,7 @@ public void writeVariableExpr_staticReference() { .build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "Integer.MAX_VALUE"); + assertEquals("Integer.MAX_VALUE", writerVisitor.write()); } @Test @@ -305,7 +305,7 @@ public void writeVariableExpr_nonDeclIgnoresModifiers() { .build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x"); + assertEquals("x", writerVisitor.write()); } @Test @@ -314,7 +314,7 @@ public void writeVariableExpr_basicLocalDecl() { VariableExpr expr = VariableExpr.builder().setVariable(variable).setIsDecl(true).build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "int x"); + assertEquals("int x", writerVisitor.write()); } @Test @@ -325,7 +325,7 @@ public void writeVariableExpr_localFinalDecl() { VariableExpr.builder().setVariable(variable).setIsFinal(true).setIsDecl(true).build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "final boolean x"); + assertEquals("final boolean x", writerVisitor.write()); } @Test @@ -340,7 +340,7 @@ public void writeVariableExpr_scopedDecl() { .build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "private int x"); + assertEquals("private int x", writerVisitor.write()); } @Test @@ -357,7 +357,7 @@ public void writeVariableExpr_scopedStaticFinalDecl() { .build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public static final boolean x"); + assertEquals("public static final boolean x", writerVisitor.write()); } @Test @@ -375,7 +375,7 @@ public void writeVariableExpr_scopedStaticFinalVolatileDecl() { .build(); expr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "private static final volatile boolean x"); + assertEquals("private static final volatile boolean x", writerVisitor.write()); } @Test @@ -387,7 +387,7 @@ public void writeVariableExpr_basicReference() { variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x.length"); + assertEquals("x.length", writerVisitor.write()); } @Test @@ -405,7 +405,7 @@ public void writeVariableExpr_basicReferenceWithModifiersSet() { .setIsStatic(true) .build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x.length"); + assertEquals("x.length", writerVisitor.write()); } @Test @@ -424,7 +424,7 @@ public void writeVariableExpr_nestedReference() { variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build(); variableExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x.someStringField.anotherStringField.lengthField"); + assertEquals("x.someStringField.anotherStringField.lengthField", writerVisitor.write()); } @Test @@ -463,7 +463,7 @@ public void writeBlockCommentStatement_basic() { CommentStatement commentStatement = CommentStatement.withComment(blockComment); String expected = String.format(createLines(3), "/*\n", "* this is a test comment\n", "*/\n"); commentStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -473,7 +473,7 @@ public void writeLineCommentStatement_basic() { CommentStatement commentStatement = CommentStatement.withComment(lineComment); String expected = "// this is a test comment\n"; commentStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -535,7 +535,7 @@ public void writeJavaDocCommentStatement_allComponents() { "* @deprecated Use the {@link ArchivedBookName} class instead.\n", "*/\n"); commentStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -546,7 +546,7 @@ public void writeBlockComment_shortLines() { String.format( createLines(4), "/*\n", "* Apache License\n", "* This is a test file header\n", "*/\n"); blockComment.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -566,7 +566,7 @@ public void writeBlockComment_newLineInBetween() { "* you may not use this file except in compliance with the License.\n", "*/\n"); blockComment.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -582,7 +582,7 @@ public void writeLineComment_longLine() { + " for 3 times,\n", "// blah, blah!\n"); lineComment.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -599,7 +599,7 @@ public void writeLineComment_specialChar() { + "// \\r" + "\"]']\n"; lineComment.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -639,7 +639,7 @@ public void writeJavaDocComment_specialChar() { "* RPC method comment may include special characters: <>&\"`'{@literal @}.\n", "*/\n"); javaDocComment.accept(writerVisitor); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -663,7 +663,7 @@ public void writeTernaryExpr_basic() { .setElseExpr(elseExpr) .build(); ternaryExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "condition ? 3 : 4"); + assertEquals("condition ? 3 : 4", writerVisitor.write()); } @Test @@ -679,7 +679,7 @@ public void writeAssignmentExpr_basicValue() { AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build(); assignExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "int x = 3"); + assertEquals("int x = 3", writerVisitor.write()); } @Test @@ -701,7 +701,7 @@ public void writeAssignmentExpr_varToVar() { AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build(); assignExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "private static final int foobar = y"); + assertEquals("private static final int foobar = y", writerVisitor.write()); } @Test @@ -717,7 +717,7 @@ public void writeAssignmentExpr_nullObjectValueReferenceType() { AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build(); assignExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "String x = null"); + assertEquals("String x = null", writerVisitor.write()); } @Test @@ -749,7 +749,7 @@ public void writeMethodInvocationExpr_basic() { MethodInvocationExpr.builder().setMethodName("foobar").build(); methodExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "foobar()"); + assertEquals("foobar()", writerVisitor.write()); } @Test @@ -768,7 +768,7 @@ public void writeMethodInvocationExpr_staticRef() { .build(); methodExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "SomeClass.foobar()"); + assertEquals("SomeClass.foobar()", writerVisitor.write()); } @Test @@ -813,9 +813,9 @@ public void writeMethodInvocationExpr_genericWithArgs() { assignExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), "final String someStr = anArg.," - + " HashMap>>foobar(anArg, anArg, anArg)"); + + " HashMap>>foobar(anArg, anArg, anArg)", + writerVisitor.write()); } @Test @@ -841,7 +841,7 @@ public void writeMethodInvocationExpr_chained() { methodExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), "libraryClient.streamBooksCallable().doAnotherThing().call()"); + "libraryClient.streamBooksCallable().doAnotherThing().call()", writerVisitor.write()); } @Test @@ -854,7 +854,7 @@ public void writeCastExpr_basic() { .setExpr(varExpr) .build(); castExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "((Object) str)"); + assertEquals("((Object) str)", writerVisitor.write()); } @Test @@ -878,7 +878,7 @@ public void writeCastExpr_methodInvocation() { .setExpr(methodExpr) .build(); castExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "((Object) SomeClass.foobar())"); + assertEquals("((Object) SomeClass.foobar())", writerVisitor.write()); } @Test @@ -892,7 +892,7 @@ public void writeCastExpr_nested() { .build(); castExpr = CastExpr.builder().setType(TypeNode.STRING).setExpr(castExpr).build(); castExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "((String) ((Object) str))"); + assertEquals("((String) ((Object) str))", writerVisitor.write()); } @Test @@ -914,13 +914,13 @@ public void writeAnonymousClassExpr_basic() { AnonymousClassExpr.builder().setType(type).setMethods(Arrays.asList(method)).build(); anonymousClassExpr.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(4), "new Runnable() {\n", "@Override\n", "public void run() {\n", - "boolean foobar = false;\n}\n\n}")); + "boolean foobar = false;\n}\n\n}"), + writerVisitor.write()); } @Test @@ -966,7 +966,7 @@ public void writeAnonymousClassExpr_withStatementsMethods() { "@Override\n", "public void run() {\n", "int x = 3;\n}\n\n}"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -1023,7 +1023,7 @@ public void writeAnonymousClassExpr_generics() { "public MethodDefinition apply(List arg) {\n", "return returnArg;\n", "}\n\n}"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -1032,7 +1032,7 @@ public void writeThrowExpr_basic() { TypeNode.withReference(ConcreteReference.withClazz(NullPointerException.class)); ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).build(); throwExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "throw new NullPointerException()"); + assertEquals("throw new NullPointerException()", writerVisitor.write()); } @Test @@ -1042,7 +1042,7 @@ public void writeThrowExpr_basicWithMessage() { String message = "Some message asdf"; ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).setMessageExpr(message).build(); throwExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "throw new NullPointerException(\"Some message asdf\")"); + assertEquals("throw new NullPointerException(\"Some message asdf\")", writerVisitor.write()); } @Test @@ -1056,7 +1056,7 @@ public void writeThrowExpr_messageExpr() { ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).setMessageExpr(messageExpr).build(); throwExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "throw new NullPointerException(foobar())"); + assertEquals("throw new NullPointerException(foobar())", writerVisitor.write()); } @Test @@ -1066,7 +1066,7 @@ public void writeInstanceofExpr() { InstanceofExpr instanceofExpr = InstanceofExpr.builder().setCheckType(TypeNode.STRING).setExpr(variableExpr).build(); instanceofExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "x instanceof String"); + assertEquals("x instanceof String", writerVisitor.write()); } @Test @@ -1080,7 +1080,7 @@ public void writeEnumRefExpr_basic() { EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build(); enumRefExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "TypeKind.VOID"); + assertEquals("TypeKind.VOID", writerVisitor.write()); } @Test @@ -1089,7 +1089,7 @@ public void writeEnumRefExpr_nested() { TypeNode.withReference(ConcreteReference.withClazz(TypeNode.TypeKind.class)); EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build(); enumRefExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "TypeNode.TypeKind.VOID"); + assertEquals("TypeNode.TypeKind.VOID", writerVisitor.write()); } @Test @@ -1097,7 +1097,7 @@ public void writeReturnExpr_basic() { ReturnExpr returnExpr = ReturnExpr.withExpr(ValueExpr.withValue(StringObjectValue.withValue("asdf"))); returnExpr.accept(writerVisitor); - assertEquals(writerVisitor.write(), "return \"asdf\""); + assertEquals("return \"asdf\"", writerVisitor.write()); } /** =============================== STATEMENTS =============================== */ @@ -1118,14 +1118,14 @@ public void writeExprStatement() { ExprStatement exprStatement = ExprStatement.withExpr(methodExpr); exprStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), "SomeClass.foobar();\n"); + assertEquals("SomeClass.foobar();\n", writerVisitor.write()); } @Test public void writeBlockStatement_empty() { BlockStatement blockStatement = BlockStatement.builder().build(); blockStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), "{\n}\n"); + assertEquals("{\n}\n", writerVisitor.write()); } @Test @@ -1146,7 +1146,7 @@ public void writeBlockStatement_simple() { BlockStatement.builder().setBody(Arrays.asList(ExprStatement.withExpr(methodExpr))).build(); blockStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), "{\nSomeClass.foobar();\n}\n"); + assertEquals("{\nSomeClass.foobar();\n}\n", writerVisitor.write()); } @Test @@ -1172,7 +1172,7 @@ public void writeBlockStatement_static() { .build(); blockStatement.accept(writerVisitor); - assertEquals(writerVisitor.write(), "static {\nSomeClass.foobar();\nSomeClass.foobar();\n}\n"); + assertEquals("static {\nSomeClass.foobar();\nSomeClass.foobar();\n}\n", writerVisitor.write()); } @Test @@ -1187,8 +1187,8 @@ public void writeIfStatement_simple() { ifStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format("%s%s%s%s", "if (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n")); + String.format("%s%s%s%s", "if (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), + writerVisitor.write()); } @Test @@ -1207,7 +1207,6 @@ public void writeIfStatement_withElse() { ifStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s" + "%s%s%s%s", "if (condition) {\n", @@ -1216,7 +1215,8 @@ public void writeIfStatement_withElse() { "} else {\n", "int x = 3;\n", "int x = 3;\n", - "}\n")); + "}\n"), + writerVisitor.write()); } @Test @@ -1258,7 +1258,7 @@ public void writeIfStatement_elseIfs() { "boolean fooBar = true;\n", "}\n"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -1322,7 +1322,7 @@ public void writeIfStatement_nested() { "boolean fooBar = true;\n", "}\n", "}\n"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -1337,8 +1337,8 @@ public void writeWhileStatement_simple() { whileStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format("%s%s%s%s", "while (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n")); + String.format("%s%s%s%s", "while (condition) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), + writerVisitor.write()); } @Test @@ -1359,10 +1359,10 @@ public void writeForStatement() { forStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s", - "for (String str : getSomeStrings()) {\n", "int x = 3;\n", "int x = 3;\n", "}\n")); + "for (String str : getSomeStrings()) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), + writerVisitor.write()); } @Test @@ -1382,10 +1382,10 @@ public void writeGeneralForStatement_basicIsDecl() { forStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s", - "for (int i = 0; i < maxSize(); i++) {\n", "int x = 3;\n", "int x = 3;\n", "}\n")); + "for (int i = 0; i < maxSize(); i++) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), + writerVisitor.write()); } @Test @@ -1405,9 +1405,9 @@ public void writeGeneralForStatement_basicIsNotDecl() { forStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( - "%s%s%s%s", "for (i = 1; i < 10; i++) {\n", "int x = 3;\n", "int x = 3;\n", "}\n")); + "%s%s%s%s", "for (i = 1; i < 10; i++) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), + writerVisitor.write()); } @Test @@ -1426,10 +1426,10 @@ public void writeTryCatchStatement_simple() { tryCatch.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s", - "try {\n", "int x = 3;\n", "} catch (IllegalArgumentException e) {\n", "}\n")); + "try {\n", "int x = 3;\n", "} catch (IllegalArgumentException e) {\n", "}\n"), + writerVisitor.write()); } @Test @@ -1452,14 +1452,14 @@ public void writeTryCatchStatement_withResources() { tryCatch.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s%s", "try (boolean aBool = false) {\n", "int y = 4;\n", "} catch (IllegalArgumentException e) {\n", "int foobar = 123;\n", - "}\n")); + "}\n"), + writerVisitor.write()); } @Test @@ -1477,7 +1477,7 @@ public void writeTryCatchStatement_sampleCodeNoCatch() { .build(); tryCatch.accept(writerVisitor); - assertEquals(writerVisitor.write(), String.format("%s%s%s", "try {\n", "int x = 3;\n", "}\n")); + assertEquals(String.format("%s%s%s", "try {\n", "int x = 3;\n", "}\n"), writerVisitor.write()); } @Test @@ -1501,14 +1501,14 @@ public void writeTryCatchStatement_sampleCodeWithCatch() { tryCatch.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s%s", "try (boolean aBool = false) {\n", "int y = 4;\n", "} catch (IllegalArgumentException e) {\n", "int foobar = 123;\n", - "}\n")); + "}\n"), + writerVisitor.write()); } @Test @@ -1524,8 +1524,8 @@ public void writeSynchronizedStatement_basicThis() { .build(); synchronizedStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format(createLines(3), "synchronized (this) {\n", "doStuff();\n", "}\n")); + String.format(createLines(3), "synchronized (this) {\n", "doStuff();\n", "}\n"), + writerVisitor.write()); } @Test @@ -1543,8 +1543,8 @@ public void writeSynchronizedStatement_basicVariableExpr() { .build(); synchronizedStatement.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format(createLines(3), "synchronized (str) {\n", "doStuff();\n", "}\n")); + String.format(createLines(3), "synchronized (str) {\n", "doStuff();\n", "}\n"), + writerVisitor.write()); } @Test @@ -1560,8 +1560,8 @@ public void writeMethodDefinition_basic() { methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format("%s%s%s", "public void close() {\n", "int x = 3;\n", "}\n\n")); + String.format("%s%s%s", "public void close() {\n", "int x = 3;\n", "}\n\n"), + writerVisitor.write()); } @Test @@ -1579,7 +1579,7 @@ public void writeMethodDefinition_constructor() { .build(); methodDefinition.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public LibrarySettings() {\n}\n\n"); + assertEquals("public LibrarySettings() {\n}\n\n", writerVisitor.write()); } @Test @@ -1592,7 +1592,7 @@ public void writeMethodDefinition_basicEmptyBody() { .build(); methodDefinition.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public void close() {\n}\n\n"); + assertEquals("public void close() {\n}\n\n", writerVisitor.write()); } @Test @@ -1609,8 +1609,8 @@ public void writeMethodDefinition_basicAbstract() { methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format("%s%s%s", "public abstract void close() {\n", "int x = 3;\n", "}\n\n")); + String.format("%s%s%s", "public abstract void close() {\n", "int x = 3;\n", "}\n\n"), + writerVisitor.write()); } @Test @@ -1624,7 +1624,7 @@ public void writeMethodDefinition_basicAbstractEmptyBody() { .build(); methodDefinition.accept(writerVisitor); - assertEquals(writerVisitor.write(), "public abstract void close();\n"); + assertEquals("public abstract void close();\n", writerVisitor.write()); } @Test @@ -1658,13 +1658,13 @@ public void writeMethodDefinition_withArgumentsAndReturnExpr() { methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( "%s%s%s%s", "public int close(int x, int y) {\n", "boolean foobar = false;\n", "return 3;\n", - "}\n\n")); + "}\n\n"), + writerVisitor.write()); } @Test @@ -1742,7 +1742,7 @@ public void writeMethodDefinition_withCommentsAnnotationsAndThrows() { "boolean foobar = false;\n", "return 3;\n", "}\n\n"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -1779,12 +1779,12 @@ public void writeMethodDefinition_templatedReturnTypeAndArguments() { methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(3), "public Map close(Map x, Map y) {\n", "return foobar();\n", - "}\n\n")); + "}\n\n"), + writerVisitor.write()); } @Test @@ -1801,7 +1801,6 @@ public void writeClassDefinition_basicWithFileHeader() { classDef.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(6), "/*\n", @@ -1809,7 +1808,8 @@ public void writeClassDefinition_basicWithFileHeader() { " */\n\n", "package com.google.example.library.v1.stub;\n", "\n", - "public class LibraryServiceStub {}\n")); + "public class LibraryServiceStub {}\n"), + writerVisitor.write()); } @Test @@ -1833,7 +1833,6 @@ public void writeClassDefinition_withAnnotationsExtendsAndImplements() { classDef.accept(writerVisitor); assertEquals( - writerVisitor.write(), String.format( createLines(5), "package com.google.example.library.v1.stub;\n", @@ -1841,7 +1840,8 @@ public void writeClassDefinition_withAnnotationsExtendsAndImplements() { "@Deprecated\n", "@SuppressWarnings(\"all\")\n", "public final class LibraryServiceStub extends String implements Appendable," - + " Cloneable, Readable {}\n")); + + " Cloneable, Readable {}\n"), + writerVisitor.write()); } @Test @@ -1981,7 +1981,7 @@ public void writeClassDefinition_commentsStatementsAndMethods() { " }\n", " }\n", "}\n"); - assertEquals(writerVisitor.write(), expected); + assertEquals(expected, writerVisitor.write()); } @Test @@ -2032,8 +2032,8 @@ public void writeThisObjectValue_methodReturn() { .build(); methodDefinition.accept(writerVisitor); assertEquals( - writerVisitor.write(), - String.format("public Student apply() {\n" + "return this;\n" + "}\n\n")); + String.format("public Student apply() {\n" + "return this;\n" + "}\n\n"), + writerVisitor.write()); } @Test @@ -2241,7 +2241,7 @@ public void writeAssignmentOperationExpr_xorAssignment() { public void writeEmptyLineStatement() { EmptyLineStatement statement = EmptyLineStatement.create(); statement.accept(writerVisitor); - assertEquals(writerVisitor.write(), "\n"); + assertEquals("\n", writerVisitor.write()); } @Test