Skip to content

Commit

Permalink
migrate from testng to junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
astrapisixtynine committed Jul 3, 2024
1 parent b9d7976 commit 69f2f4a
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 87 deletions.
36 changes: 16 additions & 20 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,27 @@ projectRepositoriesPasswordKey=ossrhPassword
projectRepositoriesReleasesName=Sonatype Nexus Releases
projectRepositoriesSnapshotsName=Sonatype Nexus Snapshots
projectRepositoriesMavenUrl=https://plugins.gradle.org/m2/
###########################
# gradle-plugins versions #
###########################
gradlePluginLombokVersion=8.4
gradlePluginVersionsVersion=0.49.0
licenseGradlePluginVersion=0.16.1
grgitGradlePluginVersion=5.2.1
spotlessGradlePluginVersion=6.22.0
#########################
# dependencies versions #
#########################
lombokVersion=1.18.30
commonsLang3Version=3.13.0
jdkSerializableFunctionalVersion=1.9.0
##############################
# test dependencies versions #
##############################
testObjectVersion=8
hamcrestAllVersion=1.3
testngVersion=7.8.0
##########################
# for deploy on sonatype #
##########################
systemProp.org.gradle.internal.publish.checksums.insecure=true
#############################
# gradle related properties #
#############################
# Enable the Gradle daemon
org.gradle.daemon=true
# Enable the build cache
org.gradle.caching=true
# Enable parallel execution
org.gradle.parallel=true
# Run Gradle in offline mode
org.gradle.offline=false
# Configure console output
org.gradle.console=auto
# Set the warning mode
org.gradle.warning.mode=summary
# Enable Configure on Demand to improve configuration time
org.gradle.configureondemand=true
# Enable VFS watching for better performance
org.gradle.vfs.watch=true

2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {

implementation libs.commons.lang3
implementation libs.jdk.serializable.functional

// Note: use of bundles...
testImplementation libs.bundles.unit.testing
testRuntimeOnly libs.junit.platform.launcher
}
13 changes: 9 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ gradle-plugin-version-catalog-update-version = "0.8.4"
gradle-plugin-versions-version = "0.51.0"
hamcrest-all-version = "1.3"
jdk-serializable-functional-version = "1.9.0"
lombok-version = "1.18.32"
lombok-version = "1.18.34"
test-object-version = "8.2"
testng-version = "7.10.2"
junit-jupiter-params-version = "5.11.0-M2"
junit-jupiter-version = "5.11.0-M2"
junit-platform-launcher-version = "1.11.0-M2"

[libraries]
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3-version" }
hamcrest-all = { module = "org.hamcrest:hamcrest-all", version.ref = "hamcrest-all-version" }
jdk-serializable-functional = { module = "org.danekja:jdk-serializable-functional", version.ref = "jdk-serializable-functional-version" }
lombok = { module = "org.projectlombok:lombok", version.ref = "lombok-version" }
test-object = { module = "io.github.astrapi69:test-object", version.ref = "test-object-version" }
testng = { module = "org.testng:testng", version.ref = "testng-version" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter-version" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter-params-version" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform-launcher-version" }

[bundles]
unit-testing = [
"hamcrest-all",
"test-object",
"testng",
"junit-jupiter",
"junit-jupiter-params",
]

[plugins]
Expand Down
2 changes: 1 addition & 1 deletion gradle/testing.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test {
useTestNG()
useJUnitPlatform()
}

jacocoTestReport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package io.github.astrapi69.model;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.Serial;
import java.io.Serializable;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/github/astrapi69/model/GenericModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.github.astrapi69.model;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;
import io.github.astrapi69.test.object.Employee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.github.astrapi69.model;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;
import io.github.astrapi69.test.object.Company;
Expand Down
16 changes: 9 additions & 7 deletions src/test/java/io/github/astrapi69/model/LambdaModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;
import io.github.astrapi69.model.lambda.Person;
Expand Down Expand Up @@ -120,13 +121,14 @@ public void targetModelPerson()
assertThat(personNameModel.getObject(), is("new name"));
}

@Test(expectedExceptions = UnsupportedOperationException.class)
@Test
public void targetReadOnly()
{
final IModel<Person> target = SerializableModel.of(new Person());

final IModel<String> personNameModel = LambdaModel.of(target, Person::getName);
check(personNameModel);
Assertions.assertThrows(UnsupportedOperationException.class, () -> { // ...
final IModel<Person> target = SerializableModel.of(new Person());
final IModel<String> personNameModel = LambdaModel.of(target, Person::getName);
check(personNameModel);
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -26,7 +26,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

/**
* Tests the states of a LoadableDetachableModel
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/github/astrapi69/model/ModelDetachTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package io.github.astrapi69.model;


import static org.testng.AssertJUnit.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.Serial;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IDetachable;
import io.github.astrapi69.model.api.IModel;
Expand Down
54 changes: 34 additions & 20 deletions src/test/java/io/github/astrapi69/model/ModelToStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.github.astrapi69.model;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Properties;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;


/**
Expand All @@ -36,18 +36,21 @@ public void loadableDetachableModel()
{
String actual;
String expected;
final LoadableDetachableModel<String> model = new MyLoadableDetachableModel();
LoadableDetachableModel<String> model;
model = new MyLoadableDetachableModel();
actual = model.toString();
assertTrue(model.toString().contains(":attached=false"));
assertTrue(model.toString().contains(":tempModelObject=[null]"));
assertTrue(actual.contains(":attached=false"));
assertTrue(actual.contains(":tempModelObject=[null]"));

model.getObject();
assertTrue(model.toString().contains(":attached=true"));
assertTrue(model.toString().contains(":tempModelObject=[foo]"));
actual = model.toString();
assertTrue(actual.contains(":attached=true"));
assertTrue(actual.contains(":tempModelObject=[foo]"));

model.detach();
assertTrue(model.toString().contains(":attached=false"));
assertTrue(model.toString().contains(":tempModelObject=[null]"));
actual = model.toString();
assertTrue(actual.contains(":attached=false"));
assertTrue(actual.contains(":tempModelObject=[null]"));
}

/**
Expand All @@ -56,23 +59,34 @@ public void loadableDetachableModel()
@Test
public void propertyModel()
{
final PropertyModel<Void> emptyModel = new PropertyModel<>("", null);
String expected = "IModel:classname=[io.github.astrapi69.model.PropertyModel]:nestedModel=[]:expression=[null]";
assertEquals(expected, emptyModel.toString());
String actual;
String expected;
PropertyModel<Void> emptyModel;
PropertyModel<String> stringProperty;
Properties properties;

final Properties properties = new Properties();
properties.put("name", "foo");
final PropertyModel<String> stringProperty = new PropertyModel<>(properties, "name");
emptyModel = new PropertyModel<>("", null);
actual = emptyModel.toString();
expected = "IModel:classname=[io.github.astrapi69.model.PropertyModel]:nestedModel=[]:expression=[null]";
assertEquals(expected, actual);

properties = new Properties();
properties.put("name", "foo");
stringProperty = new PropertyModel<>(properties, "name");
actual = stringProperty.toString();
expected = "IModel:classname=[io.github.astrapi69.model.PropertyModel]:nestedModel=[{name=foo}]:expression=[name]";
assertEquals(expected, stringProperty.toString());
assertEquals(expected, actual);

stringProperty.getObject();
actual = stringProperty.toString();
expected = "IModel:classname=[io.github.astrapi69.model.PropertyModel]:nestedModel=[{name=foo}]:expression=[name]";
assertEquals(expected, stringProperty.toString());
assertEquals(expected, actual);

InnerPOJO innerPOJO;
PropertyModel<?> pojoProperty;

final InnerPOJO innerPOJO = new InnerPOJO();
final PropertyModel<?> pojoProperty = new PropertyModel<>(innerPOJO, "pojo");
innerPOJO = new InnerPOJO();
pojoProperty = new PropertyModel<>(innerPOJO, "pojo");

expected = "IModel:classname=[io.github.astrapi69.model.PropertyModel]:nestedModel=[pojo]:expression=[pojo]";
assertEquals(expected, pojoProperty.toString());
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/io/github/astrapi69/model/PropertyModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package io.github.astrapi69.model;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;
import io.github.astrapi69.test.object.Employee;
Expand All @@ -32,12 +33,15 @@ public class PropertyModelTest
* abstract class type. This should end in an exception because Wicket can't decide what to
* instantiate on behalf of the program.
*/
@Test(expectedExceptions = RuntimeException.class)
@Test
public void setWithNullPathAbstract()
{
final Person person = new Person();
final PropertyModel<String> model = new PropertyModel<>(person, "abstractAddress.street");
model.setObject("foo");
Assertions.assertThrows(RuntimeException.class, () -> {
final Person person = new Person();
final PropertyModel<String> model = new PropertyModel<>(person,
"abstractAddress.street");
model.setObject("foo");
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.github.astrapi69.model;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

/**
* https://issues.apache.org/jira/browse/WICKET-3929
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.github.astrapi69.model;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import io.github.astrapi69.model.api.IModel;
import io.github.astrapi69.test.object.Person;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.github.astrapi69.model.reflect;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

/**
* Test for {@link CachingMethodResolver}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.github.astrapi69.model.reflect;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

/**
* Test for {@link CachingProxyFactory}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.github.astrapi69.model.reflect;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.lang.reflect.Method;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

/**
* Test for {@link DefaultMethodResolver}.
Expand Down
Loading

0 comments on commit 69f2f4a

Please sign in to comment.