Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warnings for test code #842

Merged
merged 11 commits into from
Sep 17, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,7 @@ private static MethodDefinition createToStringMethod(

List<Expr> instantiateArgExprs = new ArrayList<>();
List<String> tokens = getTokenSet(tokenHierarchies).stream().collect(Collectors.toList());
for (int i = 0; i < tokens.size(); i++) {
String token = tokens.get(i);
for (String token : tokens) {
Preconditions.checkNotNull(
patternTokenVarExprs.get(token),
String.format(
Expand Down Expand Up @@ -1645,9 +1644,9 @@ private static ClassDefinition createNestedBuilderClass(
.build());
}

for (int i = 0; i < tokens.size(); i++) {
for (VariableExpr memberVarExpr : classMemberVarExprs) {
VariableExpr currClassTokenVarExpr =
classMemberVarExprs.get(i).toBuilder().setExprReferenceExpr(thisExpr).build();
memberVarExpr.toBuilder().setExprReferenceExpr(thisExpr).build();
builderCtorBodyExprs.add(
AssignmentExpr.builder()
.setVariableExpr(currClassTokenVarExpr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private VariableExpr createVarPublicDeclExpr(Variable var) {
.build();
}

private NewObjectExpr createNewObjectExpr(Class clazz) {
private NewObjectExpr createNewObjectExpr(Class<?> clazz) {
return NewObjectExpr.builder()
.setType(TypeNode.withReference(ConcreteReference.withClazz(clazz)))
.setIsGeneric(true)
Expand Down Expand Up @@ -460,11 +460,8 @@ private MethodDefinition createOverrideCreateBookMethod(
}

private MethodDefinition createAddShelfMethod() {
ConcreteReference integerUtilRef =
ConcreteReference.builder().setClazz(Integer.class).setIsStaticImport(true).build();
Variable nameVar = createVarFromType(TypeNode.STRING, "name");
Variable seriesDoubleNumVar = createVarFromType(TypeNode.DOUBLE, "seriesDoubleNum");
Variable maxValueVar = createVarFromConcreteRef(integerUtilRef, "MAX_VALUE");
CastExpr seriesNumDoubleToIntExpr =
CastExpr.builder()
.setExpr(VariableExpr.withVariable(seriesDoubleNumVar))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

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

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.common.base.Function;
import java.util.Arrays;
Expand Down Expand Up @@ -103,10 +103,7 @@ public void validAnonymousClass_genericAndVariableExpr() {
public void invalidAnonymousClass_primitiveType() {
assertThrows(
IllegalStateException.class,
() -> {
AnonymousClassExpr anonymousClassExpr =
AnonymousClassExpr.builder().setType(TypeNode.INT).build();
});
() -> AnonymousClassExpr.builder().setType(TypeNode.INT).build());
}

@Test
Expand All @@ -126,10 +123,7 @@ public void invalidAnonymousClass_staticMethod() {

assertThrows(
IllegalStateException.class,
() -> {
AnonymousClassExpr anonymousClassExpr =
AnonymousClassExpr.builder().setType(type).setMethods(Arrays.asList(method)).build();
});
() -> AnonymousClassExpr.builder().setType(type).setMethods(Arrays.asList(method)).build());
}

@Test
Expand All @@ -145,10 +139,7 @@ public void invalidAnonymousClass_explicitConstructor() {
.build();
assertThrows(
IllegalStateException.class,
() -> {
AnonymousClassExpr anonymousClassExpr =
AnonymousClassExpr.builder().setType(type).setMethods(Arrays.asList(method)).build();
});
() -> AnonymousClassExpr.builder().setType(type).setMethods(Arrays.asList(method)).build());
}

@Test
Expand All @@ -162,13 +153,11 @@ public void invalidAnonymousClass_staticVariableExpr() {
ExprStatement exprStatement = ExprStatement.withExpr(variableExpr);
assertThrows(
IllegalStateException.class,
() -> {
AnonymousClassExpr anonymousClassExpr =
AnonymousClassExpr.builder()
.setType(type)
.setStatements(Arrays.asList(exprStatement))
.build();
});
() ->
AnonymousClassExpr.builder()
.setType(type)
.setStatements(Arrays.asList(exprStatement))
.build());
}

private static AssignmentExpr createAssignmentExpr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public void validCastExpr_basic() {

@Test
public void validCastExpr_basicNull() {
Variable variable = Variable.builder().setName("x").setType(TypeNode.STRING).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
CastExpr.builder()
.setType(TypeNode.withReference(ConcreteReference.withClazz(Object.class)))
.setExpr(ValueExpr.createNullExpr())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

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

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ public void invalidForStatement() {
MethodInvocationExpr.builder().setMethodName("getSomeStrings").build();
assertThrows(
IllegalStateException.class,
() -> {
ForStatement forStatement =
ForStatement.builder()
.setLocalVariableExpr(variableExpr)
.setCollectionExpr(methodExpr)
.setBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.build();
});
() ->
ForStatement.builder()
.setLocalVariableExpr(variableExpr)
.setCollectionExpr(methodExpr)
.setBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.build());
}

private static AssignmentExpr createAssignmentExpr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import com.google.api.generator.engine.ast.IdentifierNode.InvalidIdentifierException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;

import com.google.api.generator.testutils.LineFormatter;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.api.generator.engine.ast;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.api.generator.engine.ast;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import com.google.api.generator.engine.ast.TypeNode.TypeKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.Arrays;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.api.generator.engine.ast;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import java.util.Arrays;
Expand Down Expand Up @@ -86,11 +86,6 @@ public void validTryCatchStatement_withResources() {

@Test
public void validTryCatchStatement_sampleCode() {
Reference exceptionReference = ConcreteReference.withClazz(IllegalArgumentException.class);
TypeNode type = TypeNode.withReference(exceptionReference);
VariableExpr variableExpr =
VariableExpr.builder().setVariable(createVariable("e", type)).setIsDecl(true).build();

TryCatchStatement tryCatch =
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
Expand All @@ -101,18 +96,12 @@ public void validTryCatchStatement_sampleCode() {

@Test
public void invalidTryCatchStatement_missingCatchVariable() {
Reference exceptionReference = ConcreteReference.withClazz(IllegalArgumentException.class);
TypeNode type = TypeNode.withReference(exceptionReference);
VariableExpr variableExpr =
VariableExpr.builder().setVariable(createVariable("e", type)).setIsDecl(true).build();

assertThrows(
IllegalStateException.class,
() -> {
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.build();
});
() ->
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.build());
}

@Test
Expand All @@ -124,13 +113,11 @@ public void invalidTryCatchStatement_catchVariableNotDecl() {

assertThrows(
IllegalStateException.class,
() -> {
TryCatchStatement tryCatch =
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.addCatch(variableExpr, Collections.emptyList())
.build();
});
() ->
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.addCatch(variableExpr, Collections.emptyList())
.build());
}

@Test
Expand All @@ -142,13 +129,11 @@ public void invalidTryCatchStatement_nonExceptionReference() {

assertThrows(
IllegalStateException.class,
() -> {
TryCatchStatement tryCatch =
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.addCatch(variableExpr, Collections.emptyList())
.build();
});
() ->
TryCatchStatement.builder()
.setTryBody(Arrays.asList(ExprStatement.withExpr(createAssignmentExpr())))
.addCatch(variableExpr, Collections.emptyList())
.build());
}

private static AssignmentExpr createAssignmentExpr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package com.google.api.generator.engine.ast;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.api.generator.engine.ast.TypeNode.TypeKind;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

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

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

Expand Down Expand Up @@ -52,7 +52,6 @@ public void basic_isStaticImport() {
public void basic_nested() {
String pkg = "com.google.example.examples.library.v1";
String name = "Charles";
String enclosingClassName = "Babbage";
Reference ref =
VaporReference.builder()
.setEnclosingClassNames("Babbage", "Ada")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.api.generator.engine.ast;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import com.google.api.generator.engine.ast.TypeNode.TypeKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.google.api.generator.engine.writer;

import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;

import com.google.api.generator.engine.ast.AnnotationNode;
import com.google.api.generator.engine.ast.AnonymousClassExpr;
Expand Down Expand Up @@ -894,10 +894,6 @@ public void writeLambdaExprImports() {
}

/** =============================== HELPERS =============================== */
private static TypeNode createType(Class clazz) {
return TypeNode.withReference(ConcreteReference.withClazz(clazz));
}

private static Variable createVariable(String variableName, TypeNode type) {
return Variable.builder().setName(variableName).setType(type).build();
}
Expand Down
Loading