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

Migrate to JUnit Jupiter #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

Expand All @@ -347,6 +347,11 @@
</compilerArguments>
</configuration>
</plugin>
<!-- unit tests -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!-- create JAR and dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -364,7 +369,7 @@
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>junit</excludeArtifactIds>
<excludeArtifactIds>junit-jupiter</excludeArtifactIds>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -542,4 +547,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
20 changes: 10 additions & 10 deletions src/test/java/org/segrada/model/ColorTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.segrada.model;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.segrada.test.PropertyAsserter.assertBasicGetterSetterBehavior;

public class ColorTest {
private static Validator validator;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Expand All @@ -32,28 +32,28 @@ public void testValidColor() throws Exception {
color.setTitle("Example title");
color.setColor(123456);
Set<ConstraintViolation<Color>> constraintViolations = validator.validate(color);
assertTrue("Color not valid", constraintViolations.size() == 0);
assertTrue(constraintViolations.size() == 0, "Color not valid");
}

@Test
public void testTitleEmpty() throws Exception {
Set<ConstraintViolation<Color>> constraintViolations = validator.validateValue(Color.class, "title", null);
assertTrue("Title empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Title empty");
}

@Test
public void testTitleTooShort() throws Exception {
Set<ConstraintViolation<Color>> constraintViolations = validator.validateValue(Color.class, "title", "");
assertTrue("Title too short", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Title too short");
}

@Test
public void testColorEmpty() throws Exception {
Set<ConstraintViolation<Color>> constraintViolations = validator.validateValue(Color.class, "color", null);
assertTrue("Color empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Color empty");

constraintViolations = validator.validateValue(Color.class, "color", 0);
assertTrue("Color can be 0!", constraintViolations.size() == 0);
assertTrue(constraintViolations.size() == 0, "Color can be 0!");
}

@Test
Expand Down Expand Up @@ -159,4 +159,4 @@ public void testGetB() throws Exception {
color.setColorCode("#ffff33");
assertEquals(51, color.getB());
}
}
}
18 changes: 9 additions & 9 deletions src/test/java/org/segrada/model/CommentTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.segrada.model;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.segrada.test.PropertyAsserter.assertBasicGetterSetterBehavior;

public class CommentTest {
private static Validator validator;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Expand All @@ -32,24 +32,24 @@ public void testValidComment() throws Exception {
comment.setText("Example text");
comment.setMarkup("DUMMY");
Set<ConstraintViolation<Comment>> constraintViolations = validator.validate(comment);
assertTrue("Comment not valid", constraintViolations.size() == 0);
assertTrue(constraintViolations.size() == 0, "Comment not valid");
}

@Test
public void testTextEmpty() throws Exception {
Set<ConstraintViolation<Comment>> constraintViolations = validator.validateValue(Comment.class, "text", null);
assertTrue("Text empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Text empty");
}

@Test
public void testTextTooShort() throws Exception {
Set<ConstraintViolation<Comment>> constraintViolations = validator.validateValue(Comment.class, "text", "");
assertTrue("Text too short", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Text too short");
}

@Test
public void testmarkupEmpty() throws Exception {
Set<ConstraintViolation<Comment>> constraintViolations = validator.validateValue(Comment.class, "markup", null);
assertTrue("Markup empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Markup empty");
}
}
}
26 changes: 13 additions & 13 deletions src/test/java/org/segrada/model/FileTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.segrada.model;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.segrada.test.PropertyAsserter.assertBasicGetterSetterBehavior;

public class FileTest {
private static byte[] fileData={0xa,0x2,0xf};

private static Validator validator;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Expand Down Expand Up @@ -52,49 +52,49 @@ public void testValidFile() throws Exception {
file.setData(fileData);
file.setDescriptionMarkup("default");
Set<ConstraintViolation<File>> constraintViolations = validator.validate(file);
assertTrue("File not valid", constraintViolations.size() == 0);
assertTrue(constraintViolations.size() == 0, "File not valid");
}

@Test
public void testFilenameEmpty() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "filename", null);
assertTrue("Filename empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Filename empty");
}

@Test
public void testFilenameTooShort() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "filename", "");
assertTrue("Filename too short", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Filename too short");
}

@Test
public void testMimeTypeEmpty() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "mimeType", null);
assertTrue("MimeType empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "MimeType empty");
}

@Test
public void testMimeTypeTooShort() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "mimeType", "");
assertTrue("MimeType too short", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "MimeType too short");
}

@Test
public void testIndexFullTextEmpty() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "indexFullText", null);
assertTrue("indexFullText empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "indexFullText empty");
}

@Test
public void testContainFileEmpty() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "containFile", null);
assertTrue("containFile empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "containFile empty");
}

@Test
public void testDescriptionMarkupEmpty() throws Exception {
Set<ConstraintViolation<File>> constraintViolations = validator.validateValue(File.class, "descriptionMarkup", null);
assertTrue("Description markup empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Description markup empty");
}

@Test
Expand All @@ -116,4 +116,4 @@ public void testGetMimeType() throws Exception {
file.setFilename("filename.png");
assertEquals("image", file.getFileType());
}
}
}
28 changes: 14 additions & 14 deletions src/test/java/org/segrada/model/LocationTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.segrada.model;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.segrada.test.PropertyAsserter.assertBasicGetterSetterBehavior;

public class LocationTest {
private static Validator validator;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
Expand All @@ -35,51 +35,51 @@ public void testValidLocation() throws Exception {
location.setLongitude(21.0);
location.setComment(null);
Set<ConstraintViolation<Location>> constraintViolations = validator.validate(location);
assertTrue("Location not valid", constraintViolations.size() == 0);
assertTrue(constraintViolations.size() == 0, "Location not valid");
}

@Test
public void testParentEmpty() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "parentId", null);
assertTrue("Parent Id empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Parent Id empty");

constraintViolations = validator.validateValue(Location.class, "parentModel", null);
assertTrue("Parent model empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Parent model empty");
}

@Test
public void testLatitudeEmpty() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "latitude", null);
assertTrue("Latitude empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Latitude empty");
}

@Test
public void testLatitudeTooLow() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "latitude", -500);
assertTrue("Latitude too low", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Latitude too low");
}

@Test
public void testLatitudeTooHigh() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "latitude", 500);
assertTrue("Latitude too high", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Latitude too high");
}

@Test
public void testLongitudeEmpty() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "longitude", null);
assertTrue("Longitude empty", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Longitude empty");
}

@Test
public void testLongitudeTooLow() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "longitude", -500);
assertTrue("Longitude too low", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Longitude too low");
}

@Test
public void testLongitudeTooHigh() throws Exception {
Set<ConstraintViolation<Location>> constraintViolations = validator.validateValue(Location.class, "longitude", 500);
assertTrue("Longitude too high", constraintViolations.size() == 1);
assertTrue(constraintViolations.size() == 1, "Longitude too high");
}
}
}
Loading