Skip to content

Commit

Permalink
test: migrate CtTypeReferenceTest to Junit5 (#3969)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Larsén <[email protected]>
  • Loading branch information
Rohitesh-Kumar-Jain and slarse authored Jun 1, 2021
1 parent 011be63 commit ba184e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<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>
<!-- must come after junit5 deps, otherwise it overrides the junit version -->
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

0 comments on commit ba184e7

Please sign in to comment.