Skip to content

Commit

Permalink
Updated to Junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Feb 7, 2025
1 parent 1de8118 commit b9b11a7
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 77 deletions.
25 changes: 18 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.4</version>
</dependency>

<dependency>
Expand All @@ -126,9 +125,8 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.15.2</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -173,6 +171,19 @@
</configuration>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<argLine>
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;
import edu.stanford.webprotege.shared.annotations.Portlet;
import org.apache.maven.plugin.logging.Log;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -24,7 +23,7 @@
* Stanford Center for Biomedical Informatics Research
* 27 May 16
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class AnnotatedPortletClassExtractor_TestCase {


Expand All @@ -42,7 +41,7 @@ public class AnnotatedPortletClassExtractor_TestCase {
@Mock
private JavaClass portletAnnotationClass;

@Before
@BeforeEach
public void setUp() throws Exception {
when(projectBuilder.getClasses()).thenReturn(Collections.singleton(portletClass));
when(portletClass.getAnnotations()).thenReturn(Arrays.asList(portletAnnotation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.lang.NullPointerException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class AnnotatedPortletClass_TestCase {
@ExtendWith(MockitoExtension.class)
class AnnotatedPortletClass_TestCase {

private AnnotatedPortletClass annotatedPortletClass;

Expand All @@ -28,24 +29,28 @@ public class AnnotatedPortletClass_TestCase {
@Mock
private JavaAnnotation javaAnnotation;

@Before
@BeforeEach
public void setUp() {
annotatedPortletClass = new AnnotatedPortletClass(javaClass, javaAnnotation);
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_javaClass_IsNull() {
new AnnotatedPortletClass(null, javaAnnotation);
assertThrows(NullPointerException.class, () -> {
new AnnotatedPortletClass(null, javaAnnotation);
});
}

@Test
public void shouldReturnSupplied_javaClass() {
assertThat(annotatedPortletClass.getJavaClass(), is(this.javaClass));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_javaAnnotation_IsNull() {
new AnnotatedPortletClass(javaClass, null);
assertThrows(NullPointerException.class, () -> {
new AnnotatedPortletClass(javaClass, null);
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;
import edu.stanford.webprotege.shared.annotations.Portlet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
Expand All @@ -18,7 +18,7 @@
* Stanford Center for Biomedical Informatics Research
* 27 May 16
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class Annotations_TestCase {

@Mock
Expand All @@ -27,7 +27,7 @@ public class Annotations_TestCase {
@Mock
private JavaClass portletAnnotationClass;

@Before
@BeforeEach
public void setUp() throws Exception {
when(annotation.getType()).thenReturn(portletAnnotationClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseException;
import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -20,12 +20,12 @@
* An integration test for the code generator, although
* this is fast enough to run as a unit test.
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class CodeGenerator_TestCase {

private WebProtegeCodeGeneratorVelocityImpl codeGenerator;

@Before
@BeforeEach
public void setUp() throws Exception {
SourceWriter sourceWriter = (packageName, simpleClassName, source) -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.expression.AnnotationValue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 26 May 16
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class PortletTypeDescriptorBuilder_TestCase {

public static final String CANONICAL_CLASS_NAME = "CANONICAL_CLASS_NAME";
Expand All @@ -46,7 +48,7 @@ public class PortletTypeDescriptorBuilder_TestCase {

private PortletTypeDescriptorBuilder builder;

@Before
@BeforeEach
public void setUp() throws Exception {
when(cls.getCanonicalName()).thenReturn(CANONICAL_CLASS_NAME);
when(cls.getPackageName()).thenReturn(PACKAGE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
package edu.stanford.webprotege.maven;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.lang.NullPointerException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertThrows;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class PortletTypeDescriptor_TestCase {

private PortletTypeDescriptor portletTypeDescriptor;
Expand All @@ -24,55 +25,65 @@ public class PortletTypeDescriptor_TestCase {
private String title = "The \\u000Atitle";
private String tooltip = "The \\u000tooltip";

@Before
@BeforeEach
public void setUp()
{
portletTypeDescriptor = new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, id, title, tooltip);
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_canonicalClassName_IsNull() {
new PortletTypeDescriptor(null, simpleName, packageName, id, title, tooltip);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(null, simpleName, packageName, id, title, tooltip);
});
}

@Test
public void shouldReturnSupplied_canonicalClassName() {
assertThat(portletTypeDescriptor.getCanonicalClassName(), is(this.canonicalClassName));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_simpleName_IsNull() {
new PortletTypeDescriptor(canonicalClassName, null, packageName, id, title, tooltip);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(canonicalClassName, null, packageName, id, title, tooltip);
});
}

@Test
public void shouldReturnSupplied_simpleName() {
assertThat(portletTypeDescriptor.getSimpleName(), is(this.simpleName));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_packageName_IsNull() {
new PortletTypeDescriptor(canonicalClassName, simpleName, null, id, title, tooltip);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(canonicalClassName, simpleName, null, id, title, tooltip);
});
}

@Test
public void shouldReturnSupplied_packageName() {
assertThat(portletTypeDescriptor.getPackageName(), is(this.packageName));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_id_IsNull() {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, null, title, tooltip);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, null, title, tooltip);
});
}

@Test
public void shouldReturnSupplied_id() {
assertThat(portletTypeDescriptor.getId(), is(this.id));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_title_IsNull() {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, id, null, tooltip);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, id, null, tooltip);
});
}

@Test
Expand All @@ -84,9 +95,11 @@ public void shouldReturnEscaped_title() {
assertThat(portletTypeDescriptor.getEscapedTitle(), is("The \ntitle"));
}

@Test(expected = NullPointerException.class)
@Test
public void shouldThrowNullPointerExceptionIf_tooltip_IsNull() {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, id, title, null);
assertThrows(NullPointerException.class, () -> {
new PortletTypeDescriptor(canonicalClassName, simpleName, packageName, id, title, null);
});
}

@Test
Expand Down
Loading

0 comments on commit b9b11a7

Please sign in to comment.