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

review: test: add tests for CtCommentIMmpl class #4053

Merged
merged 7 commits into from
Jul 26, 2021
73 changes: 73 additions & 0 deletions src/test/java/spoon/test/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import static spoon.test.SpoonTestHelpers.assumeNotWindows;

Expand Down Expand Up @@ -775,6 +776,78 @@ public void testSnippedWithComments() {
assertEquals("inline comment", returnSt.getComments().get(1).getContent());
}

@Test
public void testEqualsWithDifferentClassObjects() {
// contract: equals return false when two objects of different classes are compared

Factory factory = new Launcher().getFactory();
CtNamedElement object = factory.Interface().get(CtNamedElement.class);
CtCommentImpl ctComment = new CtCommentImpl();

Boolean expectedBoolean = ctComment.equals(object);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

assertFalse(expectedBoolean);
}

@Test
public void testEqualsWithDifferentContent() {
// contract: equals return false when two comments with different contents are compared

Factory factory = new Launcher().getFactory();

CtComment comment = factory.Core().createComment();
String commentContent = "testContent";
comment.setContent(commentContent);

CtCommentImpl ctComment = new CtCommentImpl();
String ctCommentContent = "notTestContent";
ctComment.setContent(ctCommentContent);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

boolean expectedBoolean = ctComment.equals(comment);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

assertFalse(expectedBoolean);
}

@Test
public void testEqualsWithSameContentAndSameType() {
// contract: equals return true when comments with same content and type are compared

Factory factory = new Launcher().getFactory();

CtComment comment = factory.Core().createComment();
String commentContent = "testContent";
comment.setCommentType(CtComment.CommentType.INLINE);
comment.setContent(commentContent);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

CtCommentImpl ctComment = new CtCommentImpl();
ctComment.setCommentType(CtComment.CommentType.INLINE);
ctComment.setContent(commentContent);

boolean expectedBoolean = ctComment.equals(comment);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

assertTrue(expectedBoolean);
}

@Test
public void testEqualsWithSameContentAndDifferentType() {
// contract: equals return false when comments with same content but different types are compared

Factory factory = new Launcher().getFactory();

CtComment comment = factory.Core().createComment();
String commentContent = "testContent";
comment.setCommentType(CtComment.CommentType.BLOCK);
comment.setContent(commentContent);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

CtCommentImpl ctComment = new CtCommentImpl();
ctComment.setCommentType(CtComment.CommentType.INLINE);
ctComment.setContent(commentContent);

boolean expectedBoolean = ctComment.equals(comment);
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved

assertFalse(expectedBoolean);
}

@Test
public void testAddCommentsToSnippet() {
Factory factory = new FactoryImpl(new DefaultCoreFactory(),
Expand Down