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

test: migrate CtTypeReferenceTest to Junit5 #3969

Merged
merged 3 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.10.0</version>
<scope>test</scope>
</dependency>

<dependency>
<dependency>
Rohitesh-Kumar-Jain marked this conversation as resolved.
Show resolved Hide resolved
<!-- must come after junit5 deps, otherwise it overrides the junit version -->
<!-- must be here in the parent POM, because the parent always comes last, see https://stackoverflow.com/questions/28999057/order-of-inherited-dependencies-in-maven-3 -->
<groupId>com.github.stefanbirkner</groupId>
Expand Down
21 changes: 11 additions & 10 deletions src/test/java/spoon/reflect/reference/CtTypeReferenceTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package spoon.reflect.reference;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.Mock;
import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;
import spoon.compiler.Environment;
import spoon.reflect.factory.Factory;
Expand All @@ -17,24 +18,24 @@

import static com.google.common.primitives.Primitives.allPrimitiveTypes;
import static com.google.common.primitives.Primitives.wrap;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
import static org.mockito.junit.MockitoJUnit.rule;
import static spoon.testing.utils.Check.assertNotNull;

@ExtendWith(MockitoExtension.class)
public class CtTypeReferenceTest {
private final TypeFactory typeFactory = new TypeFactory();
@Rule public MockitoRule mockito = rule();

@Mock private Factory factory;
@Mock private Environment environment;
@Mock private FineModelChangeListener listener;
@Mock private ClassLoader classLoader;

@Before public void setUp() {
@BeforeEach public void setUp() {
when(factory.Type()).thenReturn(typeFactory);
when(factory.getEnvironment()).thenReturn(environment);
when(environment.getModelChangeListener()).thenReturn(listener);
when(environment.getInputClassLoader()).thenReturn(classLoader);
Mockito.lenient().when(environment.getInputClassLoader()).thenReturn(classLoader);
}

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ private void testBoxingFunction(Supplier<? extends CtTypeReference<?>> supplier,
reference.setFactory(factory);
reference.setSimpleName(inputClass.getName());
if (mockClassLoader) {
when(classLoader.loadClass(inputClass.getName()))
Mockito.lenient().when(classLoader.loadClass(inputClass.getName()))
.thenAnswer((Answer<Object>) invocationOnMock -> inputClass);
}

Expand Down