Skip to content

Commit

Permalink
added MethodDeclarationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 19, 2023
1 parent e9dde77 commit 7146f61
Showing 1 changed file with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.jd.core.v1.model.javasyntax.declaration;

import org.jd.core.v1.model.javasyntax.expression.StringConstantExpression;
import org.jd.core.v1.model.javasyntax.statement.BaseStatement;
import org.jd.core.v1.model.javasyntax.statement.ReturnExpressionStatement;
import org.jd.core.v1.model.javasyntax.type.ObjectType;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.TestDeclarationVisitor;

public class MethodDeclarationTest {

private MethodDeclaration methodDeclaration;

@Before
public void setUp() {
BaseStatement statements = new ReturnExpressionStatement(new StringConstantExpression("Hello World"));
methodDeclaration = new MethodDeclaration(0, "methodName", ObjectType.TYPE_STRING, "()V", statements);
}

@Test
public void testGetAnnotationReferences() {
Assert.assertNull(methodDeclaration.getAnnotationReferences());
}

@Test
public void testGetFlags() {
Assert.assertEquals(0, methodDeclaration.getFlags());
}

@Test
public void testIsStatic() {
Assert.assertFalse(methodDeclaration.isStatic());
}

@Test
public void testIsPublic() {
Assert.assertFalse(methodDeclaration.isPublic());
}

@Test
public void testIsAbstract() {
Assert.assertFalse(methodDeclaration.isAbstract());
}

@Test
public void testGetName() {
Assert.assertEquals("methodName", methodDeclaration.getName());
}

@Test
public void testGetTypeParameters() {
Assert.assertNull(methodDeclaration.getTypeParameters());
}

@Test
public void testGetReturnedType() {
Assert.assertEquals(ObjectType.TYPE_STRING, methodDeclaration.getReturnedType());
}

@Test
public void testGetFormalParameters() {
Assert.assertNull(methodDeclaration.getFormalParameters());
}

@Test
public void testGetExceptionTypes() {
Assert.assertNull(methodDeclaration.getExceptionTypes());
}

@Test
public void testGetDescriptor() {
Assert.assertEquals("()V", methodDeclaration.getDescriptor());
}

@Test
public void testGetStatements() {
Assert.assertNotNull(methodDeclaration.getStatements());
Assert.assertTrue(methodDeclaration.getStatements().isReturnExpressionStatement());
methodDeclaration = new MethodDeclaration(methodDeclaration.getFlags(), methodDeclaration.getName(), methodDeclaration.getReturnedType(), methodDeclaration.getDescriptor());
Assert.assertNull(methodDeclaration.getStatements());
}

@Test
public void testGetDefaultAnnotationValue() {
Assert.assertNull(methodDeclaration.getDefaultAnnotationValue());
}

@Test
public void testToString() {
Assert.assertEquals("MethodDeclaration{methodName ()V}", methodDeclaration.toString());
}

@Test
public void testAccept() {
TestDeclarationVisitor visitor = new TestDeclarationVisitor();
methodDeclaration.accept(visitor);

Assert.assertEquals(1, visitor.getMethodDeclarationCount());
}
}

0 comments on commit 7146f61

Please sign in to comment.