You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by be...@apache.org on 2025/09/13 15:01:12 UTC
(tapestry-5) 12/12: TAP5-2809: fix tests
This is an automated email from the ASF dual-hosted git repository.
benw pushed a commit to branch gradle-improvements-javax
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
commit 7682b73949c3baaa3acfe7d62b30bc1a7edf9b53
Author: Ben Weidig <be...@netzgut.net>
AuthorDate: Sat Sep 13 17:00:31 2025 +0200
TAP5-2809: fix tests
---
plastic/src/test/conf/testng.xml | 6 -
.../src/test/{conf => resources}/testng.xml | 0
.../apache/tapestry5/clojure/tests/TestModule.java | 12 +
.../app1/PartialTemplateRendererTests.groovy | 1 -
.../ComponentDependencyRegistryImplTest.java | 332 +++----
.../test/{conf => resources}/testng-limited.xml | 0
.../src/test/{conf => resources}/testng.xml | 163 ++--
tapestry-func/src/test/conf/testng.xml | 8 -
.../org/apache/tapestry5/func/BaseFuncTest.java | 36 +-
.../org/apache/tapestry5/func/FlowToSetTests.java | 8 +-
.../java/org/apache/tapestry5/func/FuncTest.java | 251 ++----
.../org/apache/tapestry5/func/InterleaveTests.java | 13 +-
.../java/org/apache/tapestry5/func/MapperTest.java | 68 +-
.../java/org/apache/tapestry5/func/RangeTests.java | 15 +-
.../tapestry5/func/StringPredicateTests.java | 4 +-
.../org/apache/tapestry5/func/TakeDropTests.java | 18 +-
.../java/org/apache/tapestry5/func/TupleTests.java | 8 +-
.../org/apache/tapestry5/func/ZippedFlowTests.java | 68 +-
.../src/test/{conf => resources}/testng.xml | 0
.../src/test/{conf => resources}/testng.xml | 0
.../services/CorsHandlerHelperImplTest.java | 175 ++--
.../services/CorsHttpServletRequestFilterTest.java | 2 +-
.../tapestry5/http/test/services/AppModule.java | 7 +
...TapestryIOCJUnit4ClassRunnerAfterClassTest.java | 63 --
...apestryIOCJUnit4ClassRunnerAfterMethodTest.java | 65 --
.../TapestryIOCJUnit4ClassRunnerModuleDefTest.java | 69 --
.../ioc/junit/TapestryIOCJUnit5AfterClassTest.java | 74 ++
.../junit/TapestryIOCJUnit5AfterMethodTest.java | 69 ++
.../ioc/junit/TapestryIOCJUnit5ModuleDefTest.java | 74 ++
.../src/test/{conf => resources}/testng.xml | 0
tapestry-jpa/build.gradle | 1 +
.../jpa/integration/app5/DummyEntityManager.java | 71 ++
.../app5/DummyEntityManagerFactory.java | 33 +
.../integration/app5/DummyPersistenceProvider.java | 11 +
.../src/test/{conf => resources}/testng.xml | 0
tapestry-json/src/test/conf/testng.xml | 8 -
.../test/groovy/json/specs/CoercionsSpec.groovy | 29 -
.../test/groovy/json/specs/JSONArraySpec.groovy | 639 -------------
.../groovy/json/specs/JSONCollectorsSpec.groovy | 101 ---
.../test/groovy/json/specs/JSONObjectSpec.groovy | 989 ---------------------
.../src/test/groovy/json/specs/JSONSpec.groovy | 36 -
.../org/apache/tapestry5/json/CoercionsTest.java | 44 +
.../org/apache/tapestry5/json/JSONArrayTest.java | 488 ++++++++++
.../apache/tapestry5/json/JSONCollectorsTest.java | 97 ++
.../org/apache/tapestry5/json/JSONObjectTest.java | 891 +++++++++++++++++++
.../java/org/apache/tapestry5/json/JSONTest.java | 53 ++
.../src/test/{conf => resources}/testng.xml | 0
.../src/test/groovy/MongoDBSpec.groovy | 2 +
.../src/test/{conf => resources}/testng.xml | 0
.../src/test/{conf => resources}/testng.xml | 0
.../src/test/{conf => resources}/testng.xml | 0
.../src/test/{conf => resources}/testng.xml | 0
.../services/web/WebResourcesTest.java | 1 +
tapestry5-annotations/src/test/conf/testng.xml | 21 -
54 files changed, 2476 insertions(+), 2648 deletions(-)
diff --git a/plastic/src/test/conf/testng.xml b/plastic/src/test/conf/testng.xml
deleted file mode 100644
index f8e52b4e2..000000000
--- a/plastic/src/test/conf/testng.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
-<!-- This file is only needed for compatibility with the Maven build, it is not needed for the Gradle build -->
-<suite name="Plastic" annotations="1.5" verbose="2">
- <test name="Placeholder -- Maven Build / TestNG Can't Run The Spock Tests">
- </test>
-</suite>
diff --git a/tapestry-beanvalidator/src/test/conf/testng.xml b/tapestry-beanvalidator/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-beanvalidator/src/test/conf/testng.xml
rename to tapestry-beanvalidator/src/test/resources/testng.xml
diff --git a/tapestry-clojure/src/test/java/org/apache/tapestry5/clojure/tests/TestModule.java b/tapestry-clojure/src/test/java/org/apache/tapestry5/clojure/tests/TestModule.java
index 2697ddc4b..0318e5add 100644
--- a/tapestry-clojure/src/test/java/org/apache/tapestry5/clojure/tests/TestModule.java
+++ b/tapestry-clojure/src/test/java/org/apache/tapestry5/clojure/tests/TestModule.java
@@ -1,9 +1,21 @@
package org.apache.tapestry5.clojure.tests;
import org.apache.tapestry5.clojure.ClojureBuilder;
+import org.apache.tapestry5.commons.MappedConfiguration;
+import org.apache.tapestry5.http.internal.TapestryHttpInternalConstants;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.services.ApplicationDefaults;
+import org.apache.tapestry5.ioc.services.SymbolProvider;
public class TestModule
{
+ @ApplicationDefaults
+ @Contribute(SymbolProvider.class)
+ public static void contributeTestApplicationDefaults(MappedConfiguration<String, String> conf)
+ {
+ conf.add(TapestryHttpInternalConstants.TAPESTRY_APP_PACKAGE_PARAM, "test");
+ }
+
public static Fixture buildFixture(ClojureBuilder builder)
{
return builder.build(Fixture.class);
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PartialTemplateRendererTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PartialTemplateRendererTests.groovy
index 5943a6928..a70c21e98 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PartialTemplateRendererTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/PartialTemplateRendererTests.groovy
@@ -16,7 +16,6 @@ package org.apache.tapestry5.integration.app1
import org.apache.tapestry5.services.PartialTemplateRenderer;
import org.testng.annotations.Test
-import org.junit.Assert;
/**
* Tests the {@link PartialTemplateRenderer} service.
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentDependencyRegistryImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentDependencyRegistryImplTest.java
index 8115652dc..6964d5444 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentDependencyRegistryImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentDependencyRegistryImplTest.java
@@ -14,9 +14,9 @@
package org.apache.tapestry5.internal.services;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import java.io.File;
import java.net.MalformedURLException;
@@ -104,40 +104,41 @@ import org.testng.annotations.Test;
@SuppressWarnings("deprecation")
public class ComponentDependencyRegistryImplTest
{
-
+
private ComponentDependencyRegistryImpl componentDependencyRegistry;
-
+
private PageClassLoaderContextManager pageClassLoaderContextManager;
-
+
private ComponentClassResolver resolver;
-
+
private PlasticManager plasticManager;
-
+
private TemplateParser templateParser;
-
+
private ComponentTemplateLocator componentTemplateLocator;
-
+
@BeforeMethod
public void setup()
{
- assertFalse(
- String.format("During testing, %s shouldn't exist", ComponentDependencyRegistry.FILENAME),
- new File(ComponentDependencyRegistry.FILENAME).exists());
-
+ assertFalse(new File(ComponentDependencyRegistry.FILENAME).exists(), String.format(
+ "During testing, %s shouldn't exist", ComponentDependencyRegistry.FILENAME));
+
MockMappedConfiguration<String, URL> templateConfiguration = new MockMappedConfiguration<String, URL>();
TapestryModule.contributeTemplateParser(templateConfiguration);
- templateParser = new TemplateParserImpl(templateConfiguration.map, false, new QuietOperationTracker());
-
+ templateParser = new TemplateParserImpl(templateConfiguration.map, false,
+ new QuietOperationTracker());
+
final String rootFolder = "src/test/app1/";
final File folderFile = new File(rootFolder);
final Resource app1ContextFolderResource = new FileResource("/", folderFile);
-
- final PageTemplateLocator pageTemplateLocator = new PageTemplateLocator(app1ContextFolderResource, resolver, "");
+
+ final PageTemplateLocator pageTemplateLocator = new PageTemplateLocator(
+ app1ContextFolderResource, resolver, "");
final DefaultTemplateLocator defaultTemplateLocator = new DefaultTemplateLocator();
- componentTemplateLocator = new ComponentTemplateLocator()
+ componentTemplateLocator = new ComponentTemplateLocator()
{
@Override
- public Resource locateTemplate(ComponentModel model, Locale locale)
+ public Resource locateTemplate(ComponentModel model, Locale locale)
{
Resource resource = defaultTemplateLocator.locateTemplate(model, locale);
if (resource == null)
@@ -147,16 +148,16 @@ public class ComponentDependencyRegistryImplTest
return resource != null && resource.exists() ? resource : null;
}
};
-
+
resolver = EasyMock.createMock(ComponentClassResolver.class);
-
+
EasyMock.expect(resolver.resolvePageClassNameToPageName(EasyMock.anyString()))
.andAnswer(() -> {
String s = ((String) EasyMock.getCurrentArguments()[0]);
final String pageName = s.substring(s.lastIndexOf('.') + 1);
return pageName;
}).anyTimes();
-
+
expectResolveComponent(TextField.class);
expectResolveComponent(PasswordField.class);
expectResolveComponent(Border.class);
@@ -165,7 +166,7 @@ public class ComponentDependencyRegistryImplTest
expectResolveComponent(ActionLink.class);
expectResolveComponent(If.class);
expectResolveComponent(ErrorComponent.class);
- expectResolveComponent(EventLink.class);
+ expectResolveComponent(EventLink.class);
expectResolveComponent(Output.class);
expectResolveComponent(Delegate.class);
expectResolveComponent(TextOutput.class);
@@ -184,101 +185,105 @@ public class ComponentDependencyRegistryImplTest
expectResolveComponent(Glyphicon.class);
expectResolveComponent(SubclassWithImport.class);
expectResolveComponent(OutputRaw.class);
-
+
EasyMock.expect(resolver.resolveMixinTypeToClassName("textonlyondisabled"))
- .andReturn(TextOnlyOnDisabled.class.getName()).anyTimes();
+ .andReturn(TextOnlyOnDisabled.class.getName()).anyTimes();
EasyMock.expect(resolver.resolveMixinTypeToClassName("echovalue2"))
- .andReturn(EchoValue2.class.getName()).anyTimes();
+ .andReturn(EchoValue2.class.getName()).anyTimes();
EasyMock.expect(resolver.resolveMixinTypeToClassName("alttitledefault"))
- .andReturn(AltTitleDefault.class.getName()).anyTimes();
+ .andReturn(AltTitleDefault.class.getName()).anyTimes();
EasyMock.expect(resolver.resolveMixinTypeToClassName("formgroup"))
- .andReturn(FormGroup.class.getName()).anyTimes();
-
+ .andReturn(FormGroup.class.getName()).anyTimes();
+
EasyMock.expect(resolver.isPage(EasyMock.anyString())).andAnswer(() -> {
String string = (String) EasyMock.getCurrentArguments()[0];
return string.contains(".pages.");
}).anyTimes();
-
+
pageClassLoaderContextManager = EasyMock.createMock(PageClassLoaderContextManager.class);
plasticManager = EasyMock.createMock(PlasticManager.class);
EasyMock.expect(plasticManager.shouldInterceptClassLoading(EasyMock.anyString()))
- .andAnswer(() -> {
- String className = (String) EasyMock.getCurrentArguments()[0];
- return className.contains(".pages.") || className.contains(".mixins.") ||
- className.contains(".components.") || className.contains(".base.");
- }).anyTimes();
-
+ .andAnswer(() -> {
+ String className = (String) EasyMock.getCurrentArguments()[0];
+ return className.contains(".pages.") || className.contains(".mixins.")
+ || className.contains(".components.") || className.contains(".base.");
+ }).anyTimes();
+
componentDependencyRegistry = new ComponentDependencyRegistryImpl(
- pageClassLoaderContextManager, plasticManager, resolver, templateParser,
+ pageClassLoaderContextManager, plasticManager, resolver, templateParser,
componentTemplateLocator, ComponentDependencyRegistry.FILENAME, false);
EasyMock.replay(pageClassLoaderContextManager, plasticManager, resolver);
}
- private void expectResolveComponent(final Class<?> clasz) {
+ private void expectResolveComponent(final Class<?> clasz)
+ {
final String className = clasz.getName();
final java.lang.String simpleName = clasz.getSimpleName();
- EasyMock.expect(resolver.resolveComponentTypeToClassName(simpleName))
- .andReturn(className).anyTimes();
+ EasyMock.expect(resolver.resolveComponentTypeToClassName(simpleName)).andReturn(className)
+ .anyTimes();
EasyMock.expect(resolver.resolveComponentTypeToClassName(simpleName.toLowerCase()))
- .andReturn(className).anyTimes();
+ .andReturn(className).anyTimes();
EasyMock.expect(resolver.resolveComponentTypeToClassName(
simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1)))
- .andReturn(className).anyTimes();
+ .andReturn(className).anyTimes();
}
-
+
private void configurePCCM(boolean merging)
{
EasyMock.reset(pageClassLoaderContextManager);
EasyMock.expect(pageClassLoaderContextManager.isMerging()).andReturn(merging).anyTimes();
EasyMock.replay(pageClassLoaderContextManager);
}
-
+
@Test(timeOut = 5000)
public void listen()
{
-
+
componentDependencyRegistry.setEnableEnsureClassIsAlreadyProcessed(false);
-
+
add("foo", "bar");
add("d", "a");
add("dd", "aa");
add("dd", "a");
add("dd", "a");
-
+
final List<String> resources = Arrays.asList("a", "aa", "none");
-
+
configurePCCM(true);
List<String> result = componentDependencyRegistry.listen(resources);
- assertEquals(0, result.size());
-
+ assertEquals(result.size(), 0);
+
configurePCCM(false);
result = componentDependencyRegistry.listen(resources);
Collections.sort(result);
assertEquals(result, Arrays.asList("d", "dd"));
assertEquals("bar", getDependencies("foo").iterator().next());
- assertEquals("foo", componentDependencyRegistry.getDependents("bar").iterator().next());
-
+ assertEquals("foo", componentDependencyRegistry.getDependents("bar").iterator().next());
+
configurePCCM(false);
result = componentDependencyRegistry.listen(Collections.emptyList());
assertEquals(result, Collections.emptyList());
assertEquals(componentDependencyRegistry.getDependents("bar").size(), 0);
assertEquals(getDependencies("foo").size(), 0);
-
+
}
-
+
private Set<String> getDependencies(String className)
{
Set<String> dependencies = new HashSet<>();
- dependencies.addAll(componentDependencyRegistry.getDependencies(className, DependencyType.USAGE));
- dependencies.addAll(componentDependencyRegistry.getDependencies(className, DependencyType.SUPERCLASS));
- dependencies.addAll(componentDependencyRegistry.getDependencies(className, DependencyType.INJECT_PAGE));
+ dependencies.addAll(
+ componentDependencyRegistry.getDependencies(className, DependencyType.USAGE));
+ dependencies.addAll(
+ componentDependencyRegistry.getDependencies(className, DependencyType.SUPERCLASS));
+ dependencies.addAll(
+ componentDependencyRegistry.getDependencies(className, DependencyType.INJECT_PAGE));
return Collections.unmodifiableSet(dependencies);
}
-
+
@Test
public void dependency_methods()
{
-
+
final String foo = "foo";
final String bar = "bar";
final String something = "something";
@@ -286,22 +291,18 @@ public class ComponentDependencyRegistryImplTest
final String fulano = "fulano";
final String beltrano = "beltrano";
final String sicrano = "sicrano";
-
+
componentDependencyRegistry.setEnableEnsureClassIsAlreadyProcessed(false);
-
- assertEquals(
- "getDependents() should never return null",
- Collections.emptySet(),
- getDependencies(foo));
-
- assertEquals(
- "getDependents() should never return null",
- Collections.emptySet(),
- componentDependencyRegistry.getDependents(foo));
+
+ assertEquals(getDependencies(foo), Collections.emptySet(),
+ "getDependents() should never return null");
+
+ assertEquals(componentDependencyRegistry.getDependents(foo), Collections.emptySet(),
+ "getDependents() should never return null");
// In Brazil, Fulano, Beltrano and Sicrano are the most used people
// placeholder names, in that order.
-
+
add(foo, bar);
add(something, fulano);
add(other, beltrano);
@@ -312,7 +313,7 @@ public class ComponentDependencyRegistryImplTest
add(beltrano, null);
add(beltrano, sicrano);
add(sicrano, null);
-
+
assertEquals(new HashSet<>(Arrays.asList(fulano, beltrano)), getDependencies(other));
assertEquals(new HashSet<>(Arrays.asList(fulano)), getDependencies(something));
assertEquals(new HashSet<>(Arrays.asList()), getDependencies(fulano));
@@ -320,15 +321,20 @@ public class ComponentDependencyRegistryImplTest
assertEquals(new HashSet<>(Arrays.asList()), getDependencies(bar));
assertEquals(new HashSet<>(Arrays.asList(sicrano)), getDependencies(beltrano));
- assertEquals(new HashSet<>(Arrays.asList(foo)), componentDependencyRegistry.getDependents(bar));
- assertEquals(new HashSet<>(Arrays.asList(other, something)), componentDependencyRegistry.getDependents(fulano));
- assertEquals(new HashSet<>(Arrays.asList()), componentDependencyRegistry.getDependents(foo));
- assertEquals(new HashSet<>(Arrays.asList(other)), componentDependencyRegistry.getDependents(beltrano));
- assertEquals(new HashSet<>(Arrays.asList(beltrano)), componentDependencyRegistry.getDependents(sicrano));
-
- assertEquals(new HashSet<>(Arrays.asList(bar, fulano, sicrano)),
+ assertEquals(new HashSet<>(Arrays.asList(foo)),
+ componentDependencyRegistry.getDependents(bar));
+ assertEquals(new HashSet<>(Arrays.asList(other, something)),
+ componentDependencyRegistry.getDependents(fulano));
+ assertEquals(new HashSet<>(Arrays.asList()),
+ componentDependencyRegistry.getDependents(foo));
+ assertEquals(new HashSet<>(Arrays.asList(other)),
+ componentDependencyRegistry.getDependents(beltrano));
+ assertEquals(new HashSet<>(Arrays.asList(beltrano)),
+ componentDependencyRegistry.getDependents(sicrano));
+
+ assertEquals(new HashSet<>(Arrays.asList(bar, fulano, sicrano)),
componentDependencyRegistry.getRootClasses());
-
+
assertTrue(componentDependencyRegistry.contains(foo));
assertTrue(componentDependencyRegistry.contains(bar));
assertTrue(componentDependencyRegistry.contains(other));
@@ -346,10 +352,10 @@ public class ComponentDependencyRegistryImplTest
assertTrue(componentDependencyRegistry.getClassNames().contains(beltrano));
assertTrue(componentDependencyRegistry.getClassNames().contains(sicrano));
assertFalse(componentDependencyRegistry.getClassNames().contains("blah"));
-
+
// Testing the clear method
componentDependencyRegistry.clear(beltrano);
-
+
assertEquals(new HashSet<>(Arrays.asList(fulano)), getDependencies(other));
assertEquals(new HashSet<>(Arrays.asList(fulano)), getDependencies(something));
assertEquals(new HashSet<>(Arrays.asList()), getDependencies(fulano));
@@ -357,14 +363,20 @@ public class ComponentDependencyRegistryImplTest
assertEquals(new HashSet<>(Arrays.asList()), getDependencies(bar));
assertEquals(new HashSet<>(Arrays.asList()), getDependencies(sicrano));
- assertEquals(new HashSet<>(Arrays.asList(foo)), componentDependencyRegistry.getDependents(bar));
- assertEquals(new HashSet<>(Arrays.asList(other, something)), componentDependencyRegistry.getDependents(fulano));
- assertEquals(new HashSet<>(Arrays.asList()), componentDependencyRegistry.getDependents(foo));
- assertEquals(new HashSet<>(Arrays.asList()), componentDependencyRegistry.getDependents(beltrano));
- assertEquals(new HashSet<>(Arrays.asList()), componentDependencyRegistry.getDependents(sicrano));
-
- assertEquals(new HashSet<>(Arrays.asList(bar, fulano, sicrano)), componentDependencyRegistry.getRootClasses());
-
+ assertEquals(new HashSet<>(Arrays.asList(foo)),
+ componentDependencyRegistry.getDependents(bar));
+ assertEquals(new HashSet<>(Arrays.asList(other, something)),
+ componentDependencyRegistry.getDependents(fulano));
+ assertEquals(new HashSet<>(Arrays.asList()),
+ componentDependencyRegistry.getDependents(foo));
+ assertEquals(new HashSet<>(Arrays.asList()),
+ componentDependencyRegistry.getDependents(beltrano));
+ assertEquals(new HashSet<>(Arrays.asList()),
+ componentDependencyRegistry.getDependents(sicrano));
+
+ assertEquals(new HashSet<>(Arrays.asList(bar, fulano, sicrano)),
+ componentDependencyRegistry.getRootClasses());
+
assertTrue(componentDependencyRegistry.contains(foo));
assertTrue(componentDependencyRegistry.contains(bar));
assertTrue(componentDependencyRegistry.contains(other));
@@ -382,13 +394,13 @@ public class ComponentDependencyRegistryImplTest
assertTrue(componentDependencyRegistry.getClassNames().contains(sicrano));
assertFalse(componentDependencyRegistry.getClassNames().contains(beltrano));
assertFalse(componentDependencyRegistry.getClassNames().contains("blah"));
-
+
}
-
+
@Test
public void get_all_non_page_dependencies()
{
-
+
final String page = "page";
final String className = "root";
final String superclass = "superclass";
@@ -397,14 +409,14 @@ public class ComponentDependencyRegistryImplTest
expectedAllNonPageDependencies.add(d);
add(c, d, DependencyType.USAGE);
};
-
+
componentDependencyRegistry.setEnableEnsureClassIsAlreadyProcessed(false);
-
+
add(className, page, DependencyType.INJECT_PAGE);
-
+
add(className, superclass, DependencyType.SUPERCLASS);
expectedAllNonPageDependencies.add(superclass);
-
+
add.accept(className, "child1");
add.accept(className, "child2");
add.accept("child1", "child1.1");
@@ -412,155 +424,152 @@ public class ComponentDependencyRegistryImplTest
add.accept("child2.1", className);
add.accept(superclass, "child2.1");
add.accept(superclass, "superclassDependency");
-
+
expectedAllNonPageDependencies.remove(className);
- final Set<String> allNonPageDependencies = componentDependencyRegistry.getAllNonPageDependencies(className);
+ final Set<String> allNonPageDependencies = componentDependencyRegistry
+ .getAllNonPageDependencies(className);
assertFalse(allNonPageDependencies.contains(className));
assertEquals(expectedAllNonPageDependencies, allNonPageDependencies);
-
+
}
-
+
@Test
public void register()
{
-
+
componentDependencyRegistry.setEnableEnsureClassIsAlreadyProcessed(true);
-
+
componentDependencyRegistry.clear();
-
+
// Dynamic dependency definitions
componentDependencyRegistry.register(PropertyDisplay.class);
assertDependencies(PropertyDisplay.class, AbstractPropertyOutput.class);
componentDependencyRegistry.register(PropertyEditor.class);
assertDependencies(PropertyEditor.class);
-
+
// Superclass
componentDependencyRegistry.register(EventLink.class);
// Superclass, recursively
assertDependencies(AbstractComponentEventLink.class, AbstractLink.class);
- assertDependencies(AbstractLink.class);
-
- // @InjectComponent
+ assertDependencies(AbstractLink.class);
+
+ // @InjectComponent
// Components declared in templates
componentDependencyRegistry.register(AlertsDemo.class);
assertDependencies(AlertsDemo.class, Zone.class, // @InjectComponent
// Components declared in template
- Border.class, BeanEditForm.class, Zone.class, If.class,
- ActionLink.class, ErrorComponent.class, EventLink.class);
-
+ Border.class, BeanEditForm.class, Zone.class, If.class, ActionLink.class,
+ ErrorComponent.class, EventLink.class);
+
// Mixins defined in in templates (t:mixins="...").
componentDependencyRegistry.register(MixinParameterDefault.class);
assertDependencies(MixinParameterDefault.class, AltTitleDefault.class, // Mixin
ActionLink.class, Border.class); // Components declared in template);
-
+
// @Component, type() not defined
componentDependencyRegistry.register(OuterAny.class);
assertDependencies(OuterAny.class, Any.class);
-
+
// @Component, type() defined
componentDependencyRegistry.register(AtComponentType.class);
assertDependencies(AtComponentType.class, TextField.class, Border.class);
// @Mixin, type() not defined
componentDependencyRegistry.register(AbstractTextField.class);
- assertDependencies(AbstractTextField.class,
- RenderDisabled.class, AbstractField.class);
+ assertDependencies(AbstractTextField.class, RenderDisabled.class, AbstractField.class);
// @Mixin, type() defined
componentDependencyRegistry.register(TextOnlyOnDisabledTextField.class);
- assertDependencies(TextOnlyOnDisabledTextField.class,
- TextOnlyOnDisabled.class, TextField.class);
-
+ assertDependencies(TextOnlyOnDisabledTextField.class, TextOnlyOnDisabled.class,
+ TextField.class);
+
// @MixinClasses and @Mixins
componentDependencyRegistry.register(InstanceMixinDependencies.class);
- assertDependencies(InstanceMixinDependencies.class,
- EchoValue.class, EchoValue2.class, TextField.class);
+ assertDependencies(InstanceMixinDependencies.class, EchoValue.class, EchoValue2.class,
+ TextField.class);
// Templates with <t:extension-point>
componentDependencyRegistry.register(BaseLayoutPage.class);
- assertDependencies(BaseLayoutPage.class,
- Delegate.class, SubclassWithImport.class, Border.class);
-
+ assertDependencies(BaseLayoutPage.class, Delegate.class, SubclassWithImport.class,
+ Border.class);
+
// Templates with <t:replace>
componentDependencyRegistry.register(SubclassWithImport.class);
- assertDependencies(SubclassWithImport.class,
- OutputRaw.class, SuperclassWithImport.class, Loop.class);
-
+ assertDependencies(SubclassWithImport.class, OutputRaw.class, SuperclassWithImport.class,
+ Loop.class);
+
// Circular dependency: BlockHolder <-> BlockCaller
componentDependencyRegistry.register(BlockHolder.class);
- assertDependencies(BlockHolder.class,
- BlockCaller.class, Loop.class, ActionLink.class);
- assertDependencies(BlockCaller.class,
- BlockHolder.class, Border.class, PageLink.class, Delegate.class);
-
+ assertDependencies(BlockHolder.class, BlockCaller.class, Loop.class, ActionLink.class);
+ assertDependencies(BlockCaller.class, BlockHolder.class, Border.class, PageLink.class,
+ Delegate.class);
+
}
-
- private void assertDependencies(Class<?> clasz, Class<?>... dependencies) {
- assertEquals(
- setOf(dependencies),
- getDependencies(clasz.getName()));
+
+ private void assertDependencies(Class<?> clasz, Class<?>... dependencies)
+ {
+ assertEquals(setOf(dependencies), getDependencies(clasz.getName()));
}
- private static Set<String> setOf(Class<?> ... classes)
+ private static Set<String> setOf(Class<?>... classes)
{
- return Arrays.asList(classes).stream()
- .map(Class::getName)
- .collect(Collectors.toSet());
+ return Arrays.asList(classes).stream().map(Class::getName).collect(Collectors.toSet());
}
private void add(String component, String dependency)
{
add(component, dependency, DependencyType.USAGE);
}
-
+
private void add(String component, String dependency, DependencyType type)
{
componentDependencyRegistry.add(component, dependency, type, true);
}
@SuppressWarnings("hiding")
- private static final class MockMappedConfiguration<String, URL> implements MappedConfiguration<String, URL>
+ private static final class MockMappedConfiguration<String, URL>
+ implements MappedConfiguration<String, URL>
{
-
+
private final Map<String, URL> map = new HashMap<>();
@Override
- public void add(String key, URL value)
+ public void add(String key, URL value)
{
map.put(key, value);
}
@Override
- public void override(String key, URL value)
+ public void override(String key, URL value)
{
throw new UnsupportedOperationException();
}
@Override
- public void addInstance(String key, Class<? extends URL> clazz)
+ public void addInstance(String key, Class<? extends URL> clazz)
{
throw new UnsupportedOperationException();
}
@Override
- public void overrideInstance(String key, Class<? extends URL> clazz)
+ public void overrideInstance(String key, Class<? extends URL> clazz)
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
-
+
}
-
+
final private static class FileResource extends AbstractResource
{
-
+
final private File file;
-
+
final private String path;
- public FileResource(String path, File file)
+ public FileResource(String path, File file)
{
super(path);
this.file = file;
@@ -568,30 +577,31 @@ public class ComponentDependencyRegistryImplTest
}
@Override
- public java.net.URL toURL()
+ public java.net.URL toURL()
{
- try
+ try
{
final File actualFile = new File(file, path);
return actualFile.exists() ? actualFile.toURL() : null;
- } catch (MalformedURLException e)
+ }
+ catch (MalformedURLException e)
{
throw new RuntimeException(e);
}
}
@Override
- protected Resource newResource(String path)
+ protected Resource newResource(String path)
{
return new FileResource(path, file);
}
@Override
- public String toString()
+ public String toString()
{
return "FileResource [file=" + file + "/" + path + "]";
}
-
+
}
-
+
}
diff --git a/tapestry-core/src/test/conf/testng-limited.xml b/tapestry-core/src/test/resources/testng-limited.xml
similarity index 100%
rename from tapestry-core/src/test/conf/testng-limited.xml
rename to tapestry-core/src/test/resources/testng-limited.xml
diff --git a/tapestry-core/src/test/conf/testng.xml b/tapestry-core/src/test/resources/testng.xml
similarity index 55%
rename from tapestry-core/src/test/conf/testng.xml
rename to tapestry-core/src/test/resources/testng.xml
index e30025f49..e7ffac3f7 100644
--- a/tapestry-core/src/test/conf/testng.xml
+++ b/tapestry-core/src/test/resources/testng.xml
@@ -7,119 +7,160 @@
<!-- The suite may no longer be run in parallel, because of some tricky issues related to locking of class loaders. Running
in parallel causes thread deadlocks, when unmanaged tests run at the same time as Selenium-based integration tests. See TAPESTRY-2561. -->
-<suite name="Tapestry Core" annotations="1.5" verbose="2">
- <test name="Component Unit Tests" enabled="true">
+<suite
+ name="Tapestry Core"
+ annotations="1.5"
+ verbose="2">
+ <test
+ name="Component Unit Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.pagetester"/>
- <package name="org.apache.tapestry5.integration.pagelevel"/>
- <package name="org.apache.tapestry5.corelib.base"/>
- <package name="org.apache.tapestry5.corelib.components"/>
- <package name="org.apache.tapestry5.corelib.mixins"/>
- <package name="org.apache.tapestry5.corelib.internal"/>
+ <package name="org.apache.tapestry5.pagetester" />
+ <package name="org.apache.tapestry5.integration.pagelevel" />
+ <package name="org.apache.tapestry5.corelib.base" />
+ <package name="org.apache.tapestry5.corelib.components" />
+ <package name="org.apache.tapestry5.corelib.mixins" />
+ <package name="org.apache.tapestry5.corelib.internal" />
</packages>
</test>
- <test name="Service Unit Tests" enabled="true">
+ <test
+ name="Service Unit Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.root"/>
- <package name="org.apache.tapestry5.dom"/>
- <package name="org.apache.tapestry5.runtime"/>
- <package name="org.apache.tapestry5.services"/>
- <package name="org.apache.tapestry5.services.javascript"/>
- <package name="org.apache.tapestry5.util"/>
- <package name="org.apache.tapestry5.validator"/>
- <package name="org.apache.tapestry5.internal"/>
- <package name="org.apache.tapestry5.internal.beaneditor"/>
- <package name="org.apache.tapestry5.internal.bindings"/>
- <package name="org.apache.tapestry5.internal.grid"/>
- <package name="org.apache.tapestry5.internal.model"/>
- <package name="org.apache.tapestry5.internal.pageload"/>
- <package name="org.apache.tapestry5.internal.services"/>
- <package name="org.apache.tapestry5.internal.services.assets"/>
- <package name="org.apache.tapestry5.internal.services.messages"/>
- <package name="org.apache.tapestry5.internal.services.meta"/>
- <package name="org.apache.tapestry5.internal.services.templates"/>
- <package name="org.apache.tapestry5.internal.structure"/>
- <package name="org.apache.tapestry5.internal.test"/>
- <package name="org.apache.tapestry5.internal.transform"/>
- <package name="org.apache.tapestry5.internal.translator"/>
- <package name="org.apache.tapestry5.internal.util"/>
- <package name="org.apache.tapestry5.internal.services.ajax"/>
+ <package name="org.apache.tapestry5.root" />
+ <package name="org.apache.tapestry5.dom" />
+ <package name="org.apache.tapestry5.runtime" />
+ <package name="org.apache.tapestry5.services" />
+ <package name="org.apache.tapestry5.services.javascript" />
+ <package name="org.apache.tapestry5.util" />
+ <package name="org.apache.tapestry5.validator" />
+ <package name="org.apache.tapestry5.internal" />
+ <package name="org.apache.tapestry5.internal.beaneditor" />
+ <package name="org.apache.tapestry5.internal.bindings" />
+ <package name="org.apache.tapestry5.internal.grid" />
+ <package name="org.apache.tapestry5.internal.model" />
+ <package name="org.apache.tapestry5.internal.pageload" />
+ <package name="org.apache.tapestry5.internal.services" />
+ <package name="org.apache.tapestry5.internal.services.assets" />
+ <package name="org.apache.tapestry5.internal.services.messages" />
+ <package name="org.apache.tapestry5.internal.services.meta" />
+ <package name="org.apache.tapestry5.internal.services.templates" />
+ <package name="org.apache.tapestry5.internal.structure" />
+ <package name="org.apache.tapestry5.internal.test" />
+ <package name="org.apache.tapestry5.internal.transform" />
+ <package name="org.apache.tapestry5.internal.translator" />
+ <package name="org.apache.tapestry5.internal.util" />
+ <package name="org.apache.tapestry5.internal.services.ajax" />
</packages>
</test>
<!-- We break these out by which of the test applications they apply to. We have a bunch. -->
- <test name="Core Integration Tests" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/app1"/>
+ <test
+ name="Core Integration Tests"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/app1" />
<packages>
- <package name="org.apache.tapestry5.integration.app1"/>
+ <package name="org.apache.tapestry5.integration.app1" />
</packages>
</test>
- <test name="Additional Integration Tests" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/app3"/>
+ <test
+ name="Additional Integration Tests"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/app3" />
<packages>
- <package name="org.apache.tapestry5.integration.app3"/>
+ <package name="org.apache.tapestry5.integration.app3" />
</packages>
</test>
- <test name="Live Reload Tests" enabled="true">
+ <test
+ name="Live Reload Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.integration.reload"/>
+ <package name="org.apache.tapestry5.integration.reload" />
</packages>
</test>
- <test name="LinkTransformer Tests" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/linktrans"/>
+ <test
+ name="LinkTransformer Tests"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/linktrans" />
<packages>
- <package name="org.apache.tapestry5.integration.linktrans"/>
+ <package name="org.apache.tapestry5.integration.linktrans" />
</packages>
</test>
- <test name="App Skinning and Misc. Tests" enabled="true">
+ <test
+ name="App Skinning and Misc. Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.integration.app5"/>
+ <package name="org.apache.tapestry5.integration.app5" />
</packages>
</test>
- <test name="Bootstrap 4 related Tests" enabled="true">
+ <test
+ name="Bootstrap 4 related Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.integration.app7"/>
+ <package name="org.apache.tapestry5.integration.app7" />
</packages>
</test>
- <test name="Components Param Symbols Tests" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/symbolparam"/>
+ <test
+ name="Components Param Symbols Tests"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/symbolparam" />
<packages>
- <package name="org.apache.tapestry5.integration.symbolparam"/>
+ <package name="org.apache.tapestry5.integration.symbolparam" />
</packages>
</test>
- <test name="AppFolder Tests" enabled="true">
+ <test
+ name="AppFolder Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.integration.appfolder"/>
+ <package name="org.apache.tapestry5.integration.appfolder" />
</packages>
</test>
- <test name="PageTester Tests" enabled="true">
+ <test
+ name="PageTester Tests"
+ enabled="true">
<packages>
- <package name="org.apache.tapestry5.integration.pagetester"/>
+ <package name="org.apache.tapestry5.integration.pagetester" />
</packages>
</test>
- <test name="Activation Context Tests" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/activationctx"/>
+ <test
+ name="Activation Context Tests"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/activationctx" />
<packages>
- <package name="org.apache.tapestry5.integration.activationctx"/>
+ <package name="org.apache.tapestry5.integration.activationctx" />
</packages>
</test>
- <test name="Activation Context Tests 2 old behavior" enabled="true">
- <parameter name="tapestry.web-app-folder" value="src/test/activationctx2"/>
+ <test
+ name="Activation Context Tests 2 old behavior"
+ enabled="true">
+ <parameter
+ name="tapestry.web-app-folder"
+ value="src/test/activationctx2" />
<packages>
- <package name="org.apache.tapestry5.integration.activationctx2"/>
+ <package name="org.apache.tapestry5.integration.activationctx2" />
</packages>
</test>
diff --git a/tapestry-func/src/test/conf/testng.xml b/tapestry-func/src/test/conf/testng.xml
deleted file mode 100644
index 0a06c77d9..000000000
--- a/tapestry-func/src/test/conf/testng.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
-<suite name="Tapestry Func">
- <test name="Functional Programming Library">
- <packages>
- <package name="org.apache.tapestry5.func"/>
- </packages>
- </test>
-</suite>
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/BaseFuncTest.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/BaseFuncTest.java
index bed7e2fd3..680f32820 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/BaseFuncTest.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/BaseFuncTest.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -17,37 +17,16 @@ package org.apache.tapestry5.func;
import java.util.Arrays;
import java.util.List;
-import org.testng.Assert;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class BaseFuncTest extends Assert
+public class BaseFuncTest
{
- protected Mapper<String, Integer> stringToLength = new Mapper<String, Integer>()
- {
- @Override
- public Integer map(String input)
- {
- return input.length();
- }
- };
+ protected Mapper<String, Integer> stringToLength = String::length;
- protected Mapper<Integer, Boolean> toEven = new Mapper<Integer, Boolean>()
- {
- @Override
- public Boolean map(Integer input)
- {
- return evenp.accept(input);
- }
- };
+ protected Mapper<Integer, Boolean> toEven = input -> this.evenp.accept(input);
- protected Predicate<Number> evenp = new Predicate<Number>()
- {
- @Override
- public boolean accept(Number object)
- {
- return object.longValue() % 2 == 0;
- };
- };
+ protected Predicate<Number> evenp = object -> object.longValue() % 2 == 0;
protected Flow<Integer> filteredEmpty = F.flow(1, 3, 5, 7).filter(evenp);
@@ -58,12 +37,11 @@ public class BaseFuncTest extends Assert
protected <T> void assertListsEquals(List<T> actual, T... expected)
{
- assertEquals(actual, Arrays.asList(expected));
+ assertEquals(Arrays.asList(expected), actual);
}
protected void unreachable()
{
throw new RuntimeException("Should not be reachable.");
}
-
}
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/FlowToSetTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/FlowToSetTests.java
index 54b98541c..890e34198 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/FlowToSetTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/FlowToSetTests.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -18,14 +18,16 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class FlowToSetTests extends BaseFuncTest
{
@Test
public void empty_flow_to_set()
{
- assertSame(F.emptyFlow().toSet(), Collections.EMPTY_SET);
+ assertSame(Collections.emptySet(), F.emptyFlow().toSet());
}
@Test
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java
index 8e9ed9235..07c49c1c3 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/FuncTest.java
@@ -1,4 +1,4 @@
-// Copyright 2010, 2011 The Apache Software Foundation
+// Copyright 2010, 2011, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -21,7 +21,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class FuncTest extends BaseFuncTest
{
@@ -44,11 +50,11 @@ public class FuncTest extends BaseFuncTest
@Test
public void map_empty_collection_is_the_empty_list()
{
- List<String> source = Arrays.asList();
+ List<String> source = Collections.emptyList();
List<Integer> lengths = F.flow(source).map(stringToLength).toList();
- assertSame(lengths, Collections.EMPTY_LIST);
+ assertSame(Collections.emptyList(), lengths);
}
@Test
@@ -58,21 +64,16 @@ public class FuncTest extends BaseFuncTest
final StringBuffer buffer = new StringBuffer();
- Worker<String> worker = new Worker<String>()
- {
- @Override
- public void work(String value)
- {
- if (buffer.length() > 0)
- buffer.append(' ');
-
- buffer.append(value);
- }
+ Worker<String> worker = value -> {
+ if (buffer.length() > 0)
+ buffer.append(' ');
+
+ buffer.append(value);
};
F.flow(source).each(worker);
- assertEquals(buffer.toString(), "Mary had a little lamb");
+ assertEquals("Mary had a little lamb", buffer.toString());
}
@Test
@@ -82,28 +83,16 @@ public class FuncTest extends BaseFuncTest
final StringBuffer buffer = new StringBuffer();
- Worker<String> worker = new Worker<String>()
- {
- @Override
- public void work(String value)
- {
- if (buffer.length() > 0)
- buffer.append(' ');
-
- buffer.append(value);
- }
+ Worker<String> worker = value -> {
+ if (buffer.length() > 0)
+ buffer.append(' ');
+
+ buffer.append(value);
};
- F.flow(source).filter(new Predicate<String>()
- {
- @Override
- public boolean accept(String object)
- {
- return object.contains("a");
- }
- }).each(worker);
+ F.flow(source).filter(object -> object.contains("a")).each(worker);
- assertEquals(buffer.toString(), "Mary had a lamb");
+ assertEquals("Mary had a lamb", buffer.toString());
}
@Test
@@ -113,21 +102,16 @@ public class FuncTest extends BaseFuncTest
final StringBuffer buffer = new StringBuffer();
- Worker<String> worker = new Worker<String>()
- {
- @Override
- public void work(String value)
- {
- if (buffer.length() > 0)
- buffer.append(' ');
-
- buffer.append(value);
- }
+ Worker<String> worker = value -> {
+ if (buffer.length() > 0)
+ buffer.append(' ');
+
+ buffer.append(value);
};
- assertSame(flow.each(worker), flow);
+ assertSame(flow, flow.each(worker));
- assertEquals(buffer.toString(), "Mary had a little lamb");
+ assertEquals("Mary had a little lamb", buffer.toString());
}
@Test
@@ -135,32 +119,22 @@ public class FuncTest extends BaseFuncTest
{
final StringBuffer buffer = new StringBuffer();
- Worker<String> appendWorker = new Worker<String>()
- {
- @Override
- public void work(String value)
- {
- if (buffer.length() > 0)
- buffer.append(' ');
-
- buffer.append(value);
- }
+ Worker<String> appendWorker = value -> {
+ if (buffer.length() > 0)
+ buffer.append(' ');
+
+ buffer.append(value);
};
- Worker<String> appendLength = new Worker<String>()
- {
- @Override
- public void work(String value)
- {
- buffer.append('(');
- buffer.append(value.length());
- buffer.append(')');
- }
+ Worker<String> appendLength = value -> {
+ buffer.append('(');
+ buffer.append(value.length());
+ buffer.append(')');
};
F.flow("Mary", "had", "a", "little", "lamb").each(F.combine(appendWorker, appendLength));
- assertEquals(buffer.toString(), "Mary(4) had(3) a(1) little(6) lamb(4)");
+ assertEquals("Mary(4) had(3) a(1) little(6) lamb(4)", buffer.toString());
}
@Test
@@ -204,7 +178,7 @@ public class FuncTest extends BaseFuncTest
List<Integer> output = F.flow(input).filter(evenp).toList();
- assertSame(output, Collections.EMPTY_LIST);
+ assertSame(Collections.emptyList(), output);
}
@Test
@@ -272,11 +246,11 @@ public class FuncTest extends BaseFuncTest
Predicate<String> isNull = F.isNull();
Predicate<String> isNotNull = F.notNull();
- assertEquals(isNull.accept(null), true);
- assertEquals(isNotNull.accept(null), false);
+ assertTrue(isNull.accept(null));
+ assertFalse(isNotNull.accept(null));
- assertEquals(isNull.accept("foo"), false);
- assertEquals(isNotNull.accept("bar"), true);
+ assertFalse(isNull.accept("foo"));
+ assertTrue(isNotNull.accept("bar"));
}
@Test
@@ -285,7 +259,7 @@ public class FuncTest extends BaseFuncTest
int total = F.flow(F.flow("Mary", "had", "a", "little", "lamb").map(stringToLength).toList()).reduce(
F.SUM_INTS, 0);
- assertEquals(total, 18);
+ assertEquals(18, total);
}
@Test
@@ -293,7 +267,7 @@ public class FuncTest extends BaseFuncTest
{
int total = F.flow("Mary", "had", "a", "little", "lamb").map(stringToLength).reduce(F.SUM_INTS, 0);
- assertEquals(total, 18);
+ assertEquals(18, total);
}
@Test
@@ -301,11 +275,11 @@ public class FuncTest extends BaseFuncTest
{
Flow<Integer> empty = F.flow();
- assertSame(empty.reverse(), empty);
+ assertSame(empty, empty.reverse());
Flow<Integer> one = F.flow(1);
- assertSame(one.reverse(), one);
+ assertSame(one, one.reverse());
}
@Test
@@ -324,7 +298,7 @@ public class FuncTest extends BaseFuncTest
Flow<Integer> empty = F.flow();
Flow<Integer> flow = F.flow(1, 2, 3);
- assertSame(empty.concat(flow), flow);
+ assertSame(flow, empty.concat(flow));
}
@Test
@@ -358,46 +332,32 @@ public class FuncTest extends BaseFuncTest
{
Flow<String> zero = F.flow();
- Comparator<String> comparator = new Comparator<String>()
- {
- @Override
- public int compare(String o1, String o2)
- {
- return o1.length() - o2.length();
- }
- };
+ Comparator<String> comparator = (o1, o2) -> o1.length() - o2.length();
- assertSame(zero.sort(), zero);
- assertSame(zero.sort(comparator), zero);
+ assertSame(zero, zero.sort());
+ assertSame(zero, zero.sort(comparator));
Flow<String> one = F.flow("Hello");
- assertSame(one.sort(), one);
- assertSame(one.sort(comparator), one);
+ assertSame(one, one.sort());
+ assertSame(one, one.sort(comparator));
}
@Test
public void sort_using_explicit_comparator()
{
Flow<String> flow = F.flow("a", "eeeee", "ccc", "bb", "dddd");
- Comparator<String> comparator = new Comparator<String>()
- {
- @Override
- public int compare(String o1, String o2)
- {
- return o1.length() - o2.length();
- }
- };
+ Comparator<String> comparator = (o1, o2) -> o1.length() - o2.length();
assertFlowValues(flow.sort(comparator), "a", "bb", "ccc", "dddd", "eeeee");
}
- @Test(expectedExceptions = ClassCastException.class)
+ @Test
public void unable_to_sort_a_flow_of_non_comparables()
{
Flow<Locale> flow = F.flow(Locale.ENGLISH, Locale.FRANCE);
- flow.sort();
+ assertThrows(ClassCastException.class, flow::sort);
}
@Test
@@ -412,19 +372,23 @@ public class FuncTest extends BaseFuncTest
total += i;
}
- assertEquals(total, 16);
+ assertEquals(16, total);
}
@Test
public void first_of_non_empty_flow()
{
- assertEquals(F.flow("Mary", "had", "a", "little", "lamb").first(), "Mary");
+ String first = F.flow("Mary", "had", "a", "little", "lamb").first();
+
+ assertEquals("Mary", first);
}
@Test
public void rest_of_non_empty_flow()
{
- assertFlowValues(F.flow("Mary", "had", "a", "little", "lamb").rest(), "had", "a", "little", "lamb");
+ Flow<String> rest = F.flow("Mary", "had", "a", "little", "lamb").rest();
+
+ assertFlowValues(rest, "had", "a", "little", "lamb");
}
@Test
@@ -451,7 +415,7 @@ public class FuncTest extends BaseFuncTest
public void list_of_empty_flow_is_empty()
{
assertTrue(filteredEmpty.isEmpty());
- assertSame(filteredEmpty.toList(), Collections.EMPTY_LIST);
+ assertSame(Collections.emptyList(), filteredEmpty.toList());
}
@Test
@@ -459,16 +423,11 @@ public class FuncTest extends BaseFuncTest
{
assertSame(filteredEmpty.reverse(), F.EMPTY_FLOW);
assertSame(filteredEmpty.sort(), F.EMPTY_FLOW);
- assertSame(filteredEmpty.sort(new Comparator<Integer>()
- {
- @Override
- public int compare(Integer o1, Integer o2)
- {
- unreachable();
+ assertSame(F.EMPTY_FLOW, filteredEmpty.sort((o1, o2) -> {
+ unreachable();
- return 0;
- }
- }), F.EMPTY_FLOW);
+ return 0;
+ }));
}
@Test
@@ -483,7 +442,7 @@ public class FuncTest extends BaseFuncTest
assertFlowValues(filteredEmpty.append(1, 2, 3).reverse(), 3, 2, 1);
}
- @Test(expectedExceptions = UnsupportedOperationException.class)
+ @Test
public void remove_on_flow_iterator_is_not_supported()
{
Flow<Integer> flow = F.flow(1, 2, 3).filter(evenp);
@@ -493,7 +452,7 @@ public class FuncTest extends BaseFuncTest
assertTrue(it.hasNext());
assertEquals(it.next(), Integer.valueOf(2));
- it.remove();
+ assertThrows(UnsupportedOperationException.class, it::remove);
}
@Test
@@ -501,22 +460,10 @@ public class FuncTest extends BaseFuncTest
{
Flow<String> flow = F.flow("Mary", "had", "a", "little", "lamb");
- List<String> result = flow.filter(new Predicate<String>()
- {
- @Override
- public boolean accept(String object)
- {
- return object.contains("a");
- }
- }).sort(new Comparator<String>()
- {
- @Override
- public int compare(String o1, String o2)
- {
- return o1.length() - o2.length();
-
- };
- }).toList();
+ List<String> result = flow
+ .filter(object -> object.contains("a"))
+ .sort((o1, o2) -> o1.length() - o2.length())
+ .toList();
assertListsEquals(result, "a", "had", "Mary", "lamb");
}
@@ -526,14 +473,7 @@ public class FuncTest extends BaseFuncTest
{
Flow<Integer> flow = F.emptyFlow();
- assertSame(flow.each(new Worker<Integer>()
- {
- @Override
- public void work(Integer value)
- {
- unreachable();
- }
- }), flow);
+ assertSame(flow, flow.each(value -> unreachable()));
}
@Test
@@ -541,7 +481,7 @@ public class FuncTest extends BaseFuncTest
{
Flow<Integer> flow = F.emptyFlow();
- assertSame(flow.remove(evenp), flow);
+ assertSame(flow, flow.remove(evenp));
}
@Test
@@ -550,28 +490,23 @@ public class FuncTest extends BaseFuncTest
Flow<Integer> flow = F.emptyFlow();
Integer initial = 99;
- assertSame(flow.reduce(new Reducer<Integer, Integer>()
- {
- @Override
- public Integer reduce(Integer accumulator, Integer value)
- {
- unreachable();
+ assertSame(initial, flow.reduce((accumulator, value) -> {
+ unreachable();
- return null;
- }
- }, initial), initial);
+ return null;
+ }, initial));
}
@Test
public void count_of_the_empty_flow_is_zero()
{
- assertEquals(F.flow().count(), 0);
+ assertEquals(0, F.flow().count());
}
@Test
public void count_of_array_flow()
{
- assertEquals(F.flow(1, 2, 3).count(), 3);
+ assertEquals(3, F.flow(1, 2, 3).count());
}
@Test
@@ -579,16 +514,16 @@ public class FuncTest extends BaseFuncTest
{
Flow<String> flow = F.flow("Mary", "had", "a", "little", "lamb");
- assertEquals(flow.filter(F.isNull()).count(), 0);
- assertEquals(flow.removeNulls().count(), 5);
+ assertEquals(0, flow.filter(F.isNull()).count());
+ assertEquals(5, flow.removeNulls().count());
}
@Test
public void count_of_a_large_flow()
{
- Flow<Integer> flow = F.series(1, 1).take(50000);
+ Flow<Integer> flow = F.series(1, 1).take(50_000);
- assertEquals(flow.count(), 50000);
+ assertEquals(50_000, flow.count());
}
@Test
@@ -611,15 +546,7 @@ public class FuncTest extends BaseFuncTest
@Test
public void lazy_flow_from_iterable()
{
- Iterable<Integer> iterable = new Iterable<Integer>()
- {
-
- @Override
- public Iterator<Integer> iterator()
- {
- return Arrays.asList(9, 7, 1).iterator();
- }
- };
+ Iterable<Integer> iterable = () -> Arrays.asList(9, 7, 1).iterator();
Flow<Integer> flow = F.flow(iterable);
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/InterleaveTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/InterleaveTests.java
index 37fe18371..e2f4dda98 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/InterleaveTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/InterleaveTests.java
@@ -1,4 +1,4 @@
-// Copyright 2011 The Apache Software Foundation
+// Copyright 2011, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
package org.apache.tapestry5.func;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
public class InterleaveTests extends BaseFuncTest
{
@@ -23,9 +23,9 @@ public class InterleaveTests extends BaseFuncTest
{
Flow<Integer> first = F.flow(1, 2, 3);
Flow<Integer> second = F.flow(100, 200, 300);
- Flow<Integer> third = F.flow(1000, 2000, 3000);
+ Flow<Integer> third = F.flow(1_000, 2_000, 3_000);
- assertFlowValues(first.interleave(second, third), 1, 100, 1000, 2, 200, 2000, 3, 300, 3000);
+ assertFlowValues(first.interleave(second, third), 1, 100, 1_000, 2, 200, 2_000, 3, 300, 3_000);
}
@Test
@@ -33,9 +33,8 @@ public class InterleaveTests extends BaseFuncTest
{
Flow<Integer> first = F.flow(1, 2, 3);
Flow<Integer> second = F.flow(100);
- Flow<Integer> third = F.flow(1000, 2000, 3000);
-
- assertFlowValues(first.interleave(second, third), 1, 100, 1000);
+ Flow<Integer> third = F.flow(1_000, 2_000, 3_000);
+ assertFlowValues(first.interleave(second, third), 1, 100, 1_000);
}
}
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/MapperTest.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/MapperTest.java
index 6144fa7ce..7a2a03156 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/MapperTest.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/MapperTest.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -18,23 +18,20 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class MapperTest extends BaseFuncTest
{
- protected Mapper<Integer, Flow<Integer>> sequencer = new Mapper<Integer, Flow<Integer>>()
- {
-
- @Override
- public Flow<Integer> map(Integer value)
- {
- Flow<Integer> flow = F.flow();
+ protected Mapper<Integer, Flow<Integer>> sequencer = value -> {
+ Flow<Integer> flow = F.flow();
- for (int i = 0; i < value; i++)
- flow = flow.append(value);
+ for (int i = 0; i < value; i++)
+ flow = flow.append(value);
- return flow;
- }
+ return flow;
};
@Test
@@ -56,15 +53,10 @@ public class MapperTest extends BaseFuncTest
@Test
public void map_of_filtered_empty_is_empty()
{
- assertTrue(filteredEmpty.map(new Mapper<Integer, Integer>()
- {
- @Override
- public Integer map(Integer value)
- {
- unreachable();
-
- return value;
- }
+ assertTrue(filteredEmpty.map(value -> {
+ unreachable();
+
+ return value;
}).isEmpty());
}
@@ -73,7 +65,7 @@ public class MapperTest extends BaseFuncTest
{
Flow<Integer> flow = F.flow();
- assertSame(flow.mapcat(sequencer), flow);
+ assertSame(flow, flow.mapcat(sequencer));
assertTrue(filteredEmpty.mapcat(sequencer).isEmpty());
}
@@ -92,7 +84,7 @@ public class MapperTest extends BaseFuncTest
Flow<Integer> flow = F.flow("Mary", "had", "etc.").filter(F.isNull()).map(stringToLength);
assertTrue(flow.isEmpty());
- assertEquals(flow.count(), 0);
+ assertEquals(0, flow.count());
}
@Test
@@ -108,20 +100,14 @@ public class MapperTest extends BaseFuncTest
{
final AtomicInteger count = new AtomicInteger();
- Mapper<Integer, Integer> doubler = new Mapper<Integer, Integer>()
- {
- @Override
- public Integer map(Integer value)
- {
- count.incrementAndGet();
-
- return value * 2;
- }
+ Mapper<Integer, Integer> doubler = value -> {
+ count.incrementAndGet();
+ return value * 2;
};
assertFlowValues(F.range(1, 100).filter(F.gt(10)).map(doubler).take(3), 22, 24, 26);
- assertEquals(count.get(), 3);
+ assertEquals(3, count.get());
count.set(0);
@@ -129,17 +115,17 @@ public class MapperTest extends BaseFuncTest
// ever actually running the mapper to determine the final value.
assertEquals(F.range(1, 100).map(doubler).count(), 99);
- assertEquals(count.get(), 0);
+ assertEquals(0, count.get());
// Because values are now lazily evaluated as well as flows, we can count the size of a flow
// without ever actually calculating (via the mapper) an output value.
Flow<Integer> flow = F.range(1, 100).map(doubler).concat(F.range(1, 10).map(doubler));
- assertEquals(flow.count(), 108);
- assertEquals(count.get(), 0);
+ assertEquals(108, flow.count());
+ assertEquals(0, count.get());
assertFlowValues(flow.take(2), 2, 4);
- assertEquals(count.get(), 2);
+ assertEquals(2, count.get());
count.set(0);
@@ -147,7 +133,7 @@ public class MapperTest extends BaseFuncTest
// of the original flow, and previously computed values (2 and 4) are still accessible!
assertFlowValues(flow.take(3), 2, 4, 6);
- assertEquals(count.get(), 1);
+ assertEquals(1, count.get());
}
@Test
@@ -155,8 +141,8 @@ public class MapperTest extends BaseFuncTest
{
Flow<Integer> flow = F.flow(1, 2, 3);
- assertSame(flow.map(F.ADD_INTS, filteredEmpty), F.EMPTY_FLOW);
- assertSame(filteredEmpty.map(F.ADD_INTS, flow), F.EMPTY_FLOW);
+ assertSame(F.emptyFlow(), flow.map(F.ADD_INTS, filteredEmpty));
+ assertSame(F.emptyFlow(), filteredEmpty.map(F.ADD_INTS, flow));
}
@Test
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/RangeTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/RangeTests.java
index 9a8c4b265..6ccdcfa73 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/RangeTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/RangeTests.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,7 +14,8 @@
package org.apache.tapestry5.func;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class RangeTests extends BaseFuncTest
{
@@ -27,7 +28,6 @@ public class RangeTests extends BaseFuncTest
@Test
public void ascending_range()
{
-
assertFlowValues(F.range(5, 8), 5, 6, 7);
}
@@ -56,14 +56,7 @@ public class RangeTests extends BaseFuncTest
@Test
public void iterate()
{
- Mapper<Integer, Integer> times2 = new Mapper<Integer, Integer>()
- {
- @Override
- public Integer map(Integer value)
- {
- return 2 * value;
- }
- };
+ Mapper<Integer, Integer> times2 = value -> 2 * value;
assertFlowValues(F.iterate(1, times2).take(5), 1, 2, 4, 8, 16);
}
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/StringPredicateTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/StringPredicateTests.java
index 47d4cdf86..87ec5d93f 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/StringPredicateTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/StringPredicateTests.java
@@ -1,4 +1,4 @@
-// Copyright 2011, 2012 The Apache Software Foundation
+// Copyright 2011, 2012, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
// limitations under the License.
package org.apache.tapestry5.func;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
public class StringPredicateTests extends BaseFuncTest
{
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/TakeDropTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/TakeDropTests.java
index 88e0e2e32..e73ba0a19 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/TakeDropTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/TakeDropTests.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,14 +14,16 @@
package org.apache.tapestry5.func;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TakeDropTests extends BaseFuncTest
{
@Test
public void take_from_empty_list()
{
- assertSame(F.flow().take(34), F.EMPTY_FLOW);
+ assertSame(F.emptyFlow(), F.flow().take(34));
}
@Test
@@ -39,7 +41,7 @@ public class TakeDropTests extends BaseFuncTest
assertFlowValues(flow.take(99), 1, 2, 3, 4, 5);
- assertSame(flow.take(0), F.EMPTY_FLOW);
+ assertSame(F.emptyFlow(), flow.take(0));
}
@Test
@@ -48,7 +50,7 @@ public class TakeDropTests extends BaseFuncTest
// This can go much, much larger but starts taking a while. Don't hold a reference to the
// start
// of the series or it can run out of memory.
- int length = 100000;
+ int length = 100_000;
assertFlowValues(F.series(1, 1).filter(evenp).drop(length).take(3), 2 * length + 2, 2 * length + 4,
2 * length + 6);
@@ -57,7 +59,7 @@ public class TakeDropTests extends BaseFuncTest
@Test
public void drop_from_empty_is_empty()
{
- assertSame(F.flow().drop(99), F.EMPTY_FLOW);
+ assertSame(F.emptyFlow(), F.flow().drop(99));
}
@Test
@@ -75,7 +77,7 @@ public class TakeDropTests extends BaseFuncTest
@Test
public void drop_all_from_array_flow_is_empty_flow()
{
- assertSame(F.flow(1, 2, 3).drop(3), F.EMPTY_FLOW);
+ assertSame(F.emptyFlow(), F.flow(1, 2, 3).drop(3));
}
@Test
@@ -83,7 +85,7 @@ public class TakeDropTests extends BaseFuncTest
{
Flow<Integer> flow = F.flow(1, 2, 3);
- assertSame(flow.drop(0), flow);
+ assertSame(flow, flow.drop(0));
}
@Test
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
index 3eadf3724..0ddfa6b6f 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/TupleTests.java
@@ -1,5 +1,5 @@
package org.apache.tapestry5.func;
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,7 +14,11 @@ package org.apache.tapestry5.func;
// limitations under the License.
import org.apache.tapestry5.func.Tuple;
-import org.testng.annotations.Test;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TupleTests extends BaseFuncTest
{
diff --git a/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java b/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java
index a4b8ee632..82bde9a8f 100644
--- a/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java
+++ b/tapestry-func/src/test/java/org/apache/tapestry5/func/ZippedFlowTests.java
@@ -1,4 +1,4 @@
-// Copyright 2010, 2011 The Apache Software Foundation
+// Copyright 2010, 2011, 2025 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,8 +14,12 @@
package org.apache.tapestry5.func;
-import org.apache.commons.lang.StringUtils;
-import org.testng.annotations.Test;
+import org.apache.commons.lang3.StringUtils;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
@@ -36,14 +40,14 @@ public class ZippedFlowTests extends BaseFuncTest
{
Map<Integer, String> map = zipped.toMap();
- assertEquals(map.size(), 3);
- assertEquals(map.get(2), "barney");
+ assertEquals(3, map.size());
+ assertEquals("barney", map.get(2));
}
@Test
public void map_to_zipped_flow()
{
- Map<Integer, String> map = new HashMap<Integer, String>();
+ Map<Integer, String> map = new HashMap<>();
map.put(1, "fred");
map.put(2, "barney");
@@ -105,7 +109,7 @@ public class ZippedFlowTests extends BaseFuncTest
@Test
public void first_tuple_from_zipped_flow()
{
- assertEquals(zipped.drop(2).first(), Tuple.create(3, "wilma"));
+ assertEquals(Tuple.create(3, "wilma"), zipped.drop(2).first());
}
@Test
@@ -124,28 +128,28 @@ public class ZippedFlowTests extends BaseFuncTest
ZippedFlow<Integer, String> extendedFlow = zipped.concat(Arrays.asList(null, pebbles, null));
ZippedFlow<Integer, String> noNulls = extendedFlow.removeNulls();
- assertEquals(extendedFlow.count(), 6);
- assertEquals(noNulls.count(), 4);
+ assertEquals(6, extendedFlow.count());
+ assertEquals(4, noNulls.count());
- assertEquals(noNulls.reverse().seconds().first(), "pebbles");
+ assertEquals("pebbles", noNulls.reverse().seconds().first());
}
@Test
public void rest_of_zipped_flow()
{
- assertEquals(zipped.rest().first().second, "barney");
+ assertEquals("barney", zipped.rest().first().second);
}
@Test
public void count_of_zipped_flow()
{
- assertEquals(zipped.count(), 3);
+ assertEquals(3, zipped.count());
}
@Test
public void take_from_zipped_flow()
{
- assertEquals(zipped.take(2).reverse().first().second, "barney");
+ assertEquals("barney", zipped.take(2).reverse().first().second);
}
@Test
@@ -153,39 +157,23 @@ public class ZippedFlowTests extends BaseFuncTest
{
final AtomicInteger count = new AtomicInteger();
- zipped.each(new Worker<Tuple<Integer, String>>()
- {
- @Override
- public void work(Tuple<Integer, String> value)
- {
- count.addAndGet(value.second.length());
- }
-
- });
+ zipped.each(value -> count.addAndGet(value.second.length()));
- assertEquals(count.get(), 15);
+ assertEquals(15, count.get());
}
@Test
public void reduce_zipped_flow()
{
- int totalLength = zipped.reduce(new Reducer<Integer, Tuple<Integer, String>>()
- {
- @Override
- public Integer reduce(Integer accumulator, Tuple<Integer, String> value)
- {
- return accumulator + value.second.length();
- }
-
- }, 0);
+ int totalLength = zipped.reduce((acc, value) -> acc + value.second.length(), 0);
- assertEquals(totalLength, 15);
+ assertEquals(15, totalLength);
}
@Test
public void remove_from_zipped_flow()
{
- assertEquals(zipped.remove(F.notNull()).count(), 0);
+ assertEquals(0, zipped.remove(F.notNull()).count());
}
@SuppressWarnings("unchecked")
@@ -198,21 +186,21 @@ public class ZippedFlowTests extends BaseFuncTest
ZippedFlow<Integer, String> zipped2 = zipped.concat(asList);
- assertEquals(zipped2.count(), 4);
+ assertEquals(4, zipped2.count());
- assertEquals(zipped2.reverse().seconds().first(), "bam-bam");
+ assertEquals("bam-bam", zipped2.reverse().seconds().first());
}
@Test
public void firsts()
{
- assertEquals(zipped.reverse().firsts().first(), (Integer) 3);
+ assertEquals((Integer)3, zipped.reverse().firsts().first());
}
@Test
public void seconds()
{
- assertEquals(zipped.seconds().first(), "fred");
+ assertEquals("fred", zipped.seconds().first());
}
@Test
@@ -229,7 +217,7 @@ public class ZippedFlowTests extends BaseFuncTest
}).first();
- assertEquals(firstTuple.first, "derf");
- assertEquals(firstTuple.second, "1-4");
+ assertEquals("derf", firstTuple.first);
+ assertEquals("1-4", firstTuple.second);
}
}
diff --git a/tapestry-hibernate-core/src/test/conf/testng.xml b/tapestry-hibernate-core/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-hibernate-core/src/test/conf/testng.xml
rename to tapestry-hibernate-core/src/test/resources/testng.xml
diff --git a/tapestry-hibernate/src/test/conf/testng.xml b/tapestry-hibernate/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-hibernate/src/test/conf/testng.xml
rename to tapestry-hibernate/src/test/resources/testng.xml
diff --git a/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHandlerHelperImplTest.java b/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHandlerHelperImplTest.java
index 10632f99b..0c393c5f5 100644
--- a/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHandlerHelperImplTest.java
+++ b/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHandlerHelperImplTest.java
@@ -14,26 +14,27 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.tapestry5.http.services.CorsHandlerHelper;
import org.easymock.EasyMock;
-import org.junit.Assert;
+import org.testng.Assert;
import org.testng.annotations.Test;
/**
- * Test suite for {@link CorsHandlerHelperImpl.
+ * Test suite for {@link CorsHandlerHelperImpl}.
*/
public class CorsHandlerHelperImplTest {
-
+
@Test
public void get_origin()
{
-
+
final String[] allowedOrigins = new String[] {"http://tapestry.apache.org", "https://apache.org"};
-
+
// Scenario 1: explicit origins
-
+
CorsHandlerHelper helper = create(String.join(" , ", allowedOrigins));
+
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
-
+
for (String origin : allowedOrigins)
{
@@ -41,20 +42,20 @@ public class CorsHandlerHelperImplTest {
EasyMock.reset(request);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(origin);
EasyMock.replay(request);
- Assert.assertEquals("Allowed origin", origin, helper.getAllowedOrigin(request).get());
+ Assert.assertEquals(origin, helper.getAllowedOrigin(request).get(), "Allowed origin");
EasyMock.verify(request);
-
+
// Non-allowed origins
EasyMock.reset(request);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(origin + "baaaa");
EasyMock.replay(request);
- Assert.assertFalse("Non-allowed origins", helper.getAllowedOrigin(request).isPresent());
+ Assert.assertFalse(helper.getAllowedOrigin(request).isPresent(), "Non-allowed origins");
EasyMock.verify(request);
-
+
}
-
+
// Scenario 2: allow all origins
-
+
helper = create(CorsHandlerHelper.ORIGIN_WILDCARD);
for (int i = 0; i < 10; i++)
{
@@ -62,23 +63,24 @@ public class CorsHandlerHelperImplTest {
EasyMock.reset(request);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(origin);
EasyMock.replay(request);
- Assert.assertEquals("All origins should be accepted", CorsHandlerHelper.ORIGIN_WILDCARD, helper.getAllowedOrigin(request).get());
+ Assert.assertEquals(CorsHandlerHelper.ORIGIN_WILDCARD,
+ helper.getAllowedOrigin(request).get(), "All origins should be accepted");
EasyMock.verify(request);
}
-
+
}
@Test
public void is_preflight()
{
-
+
// Scenario 1: not OPTIONS
final String origin = "https://tapestry.apache.org";
CorsHandlerHelper helper = create(origin);
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(request.getMethod()).andReturn("PUT");
EasyMock.replay(request);
- Assert.assertFalse("Not OPTIONS", helper.isPreflight(request));
+ Assert.assertFalse(helper.isPreflight(request), "Not OPTIONS");
EasyMock.verify(request);
// Scenario 2: no Origin
@@ -86,7 +88,7 @@ public class CorsHandlerHelperImplTest {
EasyMock.expect(request.getMethod()).andReturn(CorsHandlerHelper.OPTIONS_METHOD);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(null);
EasyMock.replay(request);
- Assert.assertFalse("No Origin", helper.isPreflight(request));
+ Assert.assertFalse(helper.isPreflight(request), "No Origin");
EasyMock.verify(request);
// Scenario 3: accepted origin
@@ -94,7 +96,7 @@ public class CorsHandlerHelperImplTest {
EasyMock.expect(request.getMethod()).andReturn(CorsHandlerHelper.OPTIONS_METHOD);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(origin);
EasyMock.replay(request);
- Assert.assertTrue("Preflight indeed", helper.isPreflight(request));
+ Assert.assertTrue(helper.isPreflight(request), "Preflight indeed");
EasyMock.verify(request);
// Scenario 4: non-accepted origin
@@ -102,24 +104,24 @@ public class CorsHandlerHelperImplTest {
EasyMock.expect(request.getMethod()).andReturn(CorsHandlerHelper.OPTIONS_METHOD);
EasyMock.expect(request.getHeader(CorsHandlerHelper.ORIGIN_HEADER)).andReturn(origin + "baaah");
EasyMock.replay(request);
- Assert.assertFalse("Non-accepted origin", helper.isPreflight(request));
+ Assert.assertFalse(helper.isPreflight(request), "Non-accepted origin");
EasyMock.verify(request);
}
-
+
@Test
public void get_path()
{
CorsHandlerHelper helper = create("*");
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
-
+
final String pathInfo = "/blah/foo/";
EasyMock.expect(request.getPathInfo()).andReturn(pathInfo);
EasyMock.replay(request);
Assert.assertEquals(pathInfo, helper.getPath(request));
EasyMock.verify(request);
-
+
EasyMock.reset(request);
EasyMock.expect(request.getPathInfo()).andReturn("");
EasyMock.replay(request);
@@ -135,19 +137,19 @@ public class CorsHandlerHelperImplTest {
EasyMock.verify(request);
}
-
+
@Test
public void configure_origin()
{
CorsHandlerHelper helper = create("*");
HttpServletResponse response = new TestableHttpServletResponse();;
-
+
final String origin = "https://apache.org";
helper.configureOrigin(response, origin);
Assert.assertEquals(origin, response.getHeader(CorsHandlerHelper.ALLOW_ORIGIN_HEADER));
Assert.assertEquals(CorsHandlerHelper.ORIGIN_HEADER, response.getHeader(CorsHandlerHelper.VARY_HEADER));
}
-
+
@Test
public void add_value_to_vary_header()
{
@@ -159,30 +161,30 @@ public class CorsHandlerHelperImplTest {
}
Assert.assertEquals(String.join(", ", values), response.getHeader(CorsHandlerHelper.VARY_HEADER));
}
-
+
@Test
public void configure_credentials()
{
HttpServletResponse response = new TestableHttpServletResponse();
-
+
CorsHandlerHelper helper = create(CorsHandlerHelper.ORIGIN_WILDCARD, true);
helper.configureCredentials(response);
Assert.assertEquals("true", response.getHeader(CorsHandlerHelper.ALLOW_CREDENTIALS_HEADER));
-
+
response = new TestableHttpServletResponse();
helper = create(CorsHandlerHelper.ORIGIN_WILDCARD, false);
helper.configureCredentials(response);
- Assert.assertNull("Header shouldn't be set",
- response.getHeader(CorsHandlerHelper.ALLOW_CREDENTIALS_HEADER));
+ Assert.assertNull(response.getHeader(CorsHandlerHelper.ALLOW_CREDENTIALS_HEADER),
+ "Header shouldn't be set");
}
-
+
@Test
public void configure_methods()
{
HttpServletResponse response = new TestableHttpServletResponse();
-
+
final String allowedMethods = "GET,PUT";
CorsHandlerHelper helper = new CorsHandlerHelperImpl("", false, allowedMethods, "", "", "");
response = new TestableHttpServletResponse();
@@ -195,7 +197,7 @@ public class CorsHandlerHelperImplTest {
{
HttpServletResponse response = new TestableHttpServletResponse();
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
-
+
// Scenario 1: configuration isn't empty
final String configuredHeaders = "Blah,Foo";
CorsHandlerHelper helper = new CorsHandlerHelperImpl("", false, "", configuredHeaders, "", "");
@@ -214,8 +216,10 @@ public class CorsHandlerHelperImplTest {
EasyMock.replay(request);
helper.configureAllowedHeaders(response, request);
EasyMock.verify(request);
- Assert.assertEquals(requestHeaders, response.getHeader(CorsHandlerHelper.ALLOW_HEADERS_HEADER));
- Assert.assertEquals(CorsHandlerHelper.REQUEST_HEADERS_HEADER, response.getHeader(CorsHandlerHelper.VARY_HEADER));
+ Assert.assertEquals(response.getHeader(CorsHandlerHelper.ALLOW_HEADERS_HEADER),
+ requestHeaders);
+ Assert.assertEquals(response.getHeader(CorsHandlerHelper.VARY_HEADER),
+ CorsHandlerHelper.REQUEST_HEADERS_HEADER);
// Scenario 3: configuration empty, request's Access-Control-Request-Headers also empty
response = new TestableHttpServletResponse();
@@ -225,7 +229,8 @@ public class CorsHandlerHelperImplTest {
helper.configureAllowedHeaders(response, request);
EasyMock.verify(request);
Assert.assertNull(response.getHeader(CorsHandlerHelper.ALLOW_HEADERS_HEADER));
- Assert.assertEquals(CorsHandlerHelper.REQUEST_HEADERS_HEADER, response.getHeader(CorsHandlerHelper.VARY_HEADER));
+ Assert.assertEquals(response.getHeader(CorsHandlerHelper.VARY_HEADER),
+ CorsHandlerHelper.REQUEST_HEADERS_HEADER);
}
@@ -233,18 +238,18 @@ public class CorsHandlerHelperImplTest {
public void configure_expose_headers()
{
HttpServletResponse response = new TestableHttpServletResponse();
-
+
final String exposeHeaders = "Blah,Foo,Bar";
CorsHandlerHelper helper = new CorsHandlerHelperImpl("", false, "", "", exposeHeaders, "");
helper.configureExposeHeaders(response);
Assert.assertEquals(exposeHeaders, response.getHeader(CorsHandlerHelper.EXPOSE_HEADERS_HEADER));
-
+
response = new TestableHttpServletResponse();
helper = new CorsHandlerHelperImpl("", false, "", "", "", "");
helper.configureExposeHeaders(response);
- Assert.assertNull("Header shouldn't be set",
- response.getHeader(CorsHandlerHelper.EXPOSE_HEADERS_HEADER));
+ Assert.assertNull(response.getHeader(CorsHandlerHelper.EXPOSE_HEADERS_HEADER),
+ "Header shouldn't be set");
}
@@ -252,18 +257,18 @@ public class CorsHandlerHelperImplTest {
public void configure_max_age()
{
HttpServletResponse response = new TestableHttpServletResponse();
-
+
final String maxAge = "1234567";
CorsHandlerHelper helper = new CorsHandlerHelperImpl("", false, "", "", "", maxAge);
helper.configureMaxAge(response);
Assert.assertEquals(maxAge, response.getHeader(CorsHandlerHelper.MAX_AGE_HEADER));
-
+
response = new TestableHttpServletResponse();
helper = new CorsHandlerHelperImpl("", false, "", "", "", "");
helper.configureExposeHeaders(response);
- Assert.assertNull("Header shouldn't be set",
- response.getHeader(CorsHandlerHelper.MAX_AGE_HEADER));
+ Assert.assertNull(response.getHeader(CorsHandlerHelper.MAX_AGE_HEADER),
+ "Header shouldn't be set");
}
@@ -271,211 +276,211 @@ public class CorsHandlerHelperImplTest {
{
return create(allowedOrigins, false);
}
-
+
private CorsHandlerHelper create(String allowedOrigins, boolean allowCredentials)
{
return new CorsHandlerHelperImpl(allowedOrigins, allowCredentials, "", "", "", "");
}
-
+
private final class TestableHttpServletResponse implements HttpServletResponse
{
-
+
private final Map<String, String> headers = new HashMap<>();
@Override
- public String getCharacterEncoding()
+ public String getCharacterEncoding()
{
throw new UnsupportedOperationException();
}
@Override
- public String getContentType()
+ public String getContentType()
{
throw new UnsupportedOperationException();
}
@Override
- public ServletOutputStream getOutputStream() throws IOException
+ public ServletOutputStream getOutputStream() throws IOException
{
throw new UnsupportedOperationException();
}
@Override
- public PrintWriter getWriter() throws IOException
+ public PrintWriter getWriter() throws IOException
{
return null;
}
@Override
- public void setCharacterEncoding(String charset)
+ public void setCharacterEncoding(String charset)
{
throw new UnsupportedOperationException();
}
@Override
- public void setContentLength(int len)
+ public void setContentLength(int len)
{
throw new UnsupportedOperationException();
}
@Override
- public void setContentType(String type)
+ public void setContentType(String type)
{
throw new UnsupportedOperationException();
}
@Override
- public void setBufferSize(int size)
+ public void setBufferSize(int size)
{
throw new UnsupportedOperationException();
}
@Override
- public int getBufferSize()
+ public int getBufferSize()
{
throw new UnsupportedOperationException();
}
@Override
- public void flushBuffer() throws IOException
+ public void flushBuffer() throws IOException
{
throw new UnsupportedOperationException();
}
@Override
- public void resetBuffer()
+ public void resetBuffer()
{
throw new UnsupportedOperationException();
}
@Override
- public boolean isCommitted()
+ public boolean isCommitted()
{
return false;
}
@Override
- public void reset()
+ public void reset()
{
throw new UnsupportedOperationException();
}
@Override
- public void setLocale(Locale loc)
+ public void setLocale(Locale loc)
{
throw new UnsupportedOperationException();
}
@Override
- public Locale getLocale()
+ public Locale getLocale()
{
throw new UnsupportedOperationException();
}
@Override
- public void addCookie(Cookie cookie)
+ public void addCookie(Cookie cookie)
{
throw new UnsupportedOperationException();
}
@Override
- public boolean containsHeader(String name)
+ public boolean containsHeader(String name)
{
throw new UnsupportedOperationException();
}
@Override
- public String encodeURL(String url)
+ public String encodeURL(String url)
{
throw new UnsupportedOperationException();
}
@Override
- public String encodeRedirectURL(String url)
+ public String encodeRedirectURL(String url)
{
throw new UnsupportedOperationException();
}
@Override
- public String encodeUrl(String url)
+ public String encodeUrl(String url)
{
throw new UnsupportedOperationException();
}
@Override
- public String encodeRedirectUrl(String url)
+ public String encodeRedirectUrl(String url)
{
throw new UnsupportedOperationException();
}
@Override
- public void sendError(int sc, String msg) throws IOException
+ public void sendError(int sc, String msg) throws IOException
{
throw new UnsupportedOperationException();
}
@Override
- public void sendError(int sc) throws IOException
+ public void sendError(int sc) throws IOException
{
throw new UnsupportedOperationException();
}
@Override
- public void sendRedirect(String location) throws IOException
+ public void sendRedirect(String location) throws IOException
{
throw new UnsupportedOperationException();
}
@Override
- public void setDateHeader(String name, long date)
+ public void setDateHeader(String name, long date)
{
throw new UnsupportedOperationException();
}
@Override
- public void addDateHeader(String name, long date)
+ public void addDateHeader(String name, long date)
{
throw new UnsupportedOperationException();
}
@Override
- public void setHeader(String name, String value)
+ public void setHeader(String name, String value)
{
headers.put(name, value);
}
@Override
- public void addHeader(String name, String value)
+ public void addHeader(String name, String value)
{
throw new UnsupportedOperationException();
}
@Override
- public void setIntHeader(String name, int value)
+ public void setIntHeader(String name, int value)
{
throw new UnsupportedOperationException();
}
@Override
- public void addIntHeader(String name, int value)
+ public void addIntHeader(String name, int value)
{
throw new UnsupportedOperationException();
}
@Override
- public void setStatus(int sc)
+ public void setStatus(int sc)
{
throw new UnsupportedOperationException();
}
@Override
- public void setStatus(int sc, String sm)
+ public void setStatus(int sc, String sm)
{
throw new UnsupportedOperationException();
}
@Override
- public int getStatus()
+ public int getStatus()
{
throw new UnsupportedOperationException();
}
@@ -486,17 +491,17 @@ public class CorsHandlerHelperImplTest {
}
@Override
- public Collection<String> getHeaders(String name)
+ public Collection<String> getHeaders(String name)
{
throw new UnsupportedOperationException();
}
@Override
- public Collection<String> getHeaderNames()
+ public Collection<String> getHeaderNames()
{
throw new UnsupportedOperationException();
}
-
+
}
-
+
}
diff --git a/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHttpServletRequestFilterTest.java b/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHttpServletRequestFilterTest.java
index c39334425..826817375 100644
--- a/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHttpServletRequestFilterTest.java
+++ b/tapestry-http/src/test/java/org/apache/tapestry5/http/internal/services/CorsHttpServletRequestFilterTest.java
@@ -11,7 +11,7 @@ import org.apache.tapestry5.http.services.CorsHandler;
import org.apache.tapestry5.http.services.CorsHttpServletRequestFilter;
import org.apache.tapestry5.http.services.HttpServletRequestHandler;
import org.easymock.EasyMock;
-import org.junit.Assert;
+import org.testng.Assert;
import org.testng.annotations.Test;
/**
diff --git a/tapestry-http/src/test/java/org/apache/tapestry5/http/test/services/AppModule.java b/tapestry-http/src/test/java/org/apache/tapestry5/http/test/services/AppModule.java
index f7eab0d06..ce01d3601 100644
--- a/tapestry-http/src/test/java/org/apache/tapestry5/http/test/services/AppModule.java
+++ b/tapestry-http/src/test/java/org/apache/tapestry5/http/test/services/AppModule.java
@@ -3,6 +3,7 @@ package org.apache.tapestry5.http.test.services;
import org.apache.tapestry5.commons.MappedConfiguration;
import org.apache.tapestry5.commons.OrderedConfiguration;
import org.apache.tapestry5.http.TapestryHttpSymbolConstants;
+import org.apache.tapestry5.http.services.CompressionAnalyzer;
import org.apache.tapestry5.http.services.Dispatcher;
import org.apache.tapestry5.http.services.HttpServletRequestFilter;
import org.apache.tapestry5.http.services.RequestFilter;
@@ -30,6 +31,12 @@ public class AppModule {
public static void contributeApplicationDefaults(MappedConfiguration<String, Object> configuration)
{
configuration.add(TapestryHttpSymbolConstants.GZIP_COMPRESSION_ENABLED, true);
+ configuration.add(TapestryHttpSymbolConstants.PRODUCTION_MODE, true);
+ }
+
+ public static CompressionAnalyzer buildCompressionAnalyzer()
+ {
+ return str -> true;
}
}
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterClassTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
deleted file mode 100644
index 67be2ef61..000000000
--- a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.tapestry5.ioc.junit;
-
-import static org.apache.tapestry5.ioc.junit.RegistryShutdownType.AFTER_CLASS;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.runners.MethodSorters.NAME_ASCENDING;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.junit.Registry;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunner;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunnerAfterClassTest.AfterClassTestModule;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(TapestryIOCJUnit4ClassRunner.class)
-@Registry(modules=AfterClassTestModule.class, shutdown=AFTER_CLASS)
-@FixMethodOrder(NAME_ASCENDING) // guarantees test ordering
-public class TapestryIOCJUnit4ClassRunnerAfterClassTest {
- public static class AfterClassTestModule {
- public List<String> buildList() {
- List<String> list = new ArrayList<String>();
- list.add("foo");
- return list;
- }
- }
-
- @Inject
- private List<String> list;
-
- @Test
- public void testInjectA() {
- assertArrayEquals(new Object[] { "foo" }, list.toArray());
- list.add("bar");
- }
-
- @Test
- public void testInjectB() {
- assertArrayEquals(new Object[] { "foo", "bar" }, list.toArray());
- list.add("baz");
- }
-
- @Test
- public void testInjectC() {
- assertArrayEquals(new Object[] { "foo", "bar", "baz" }, list.toArray());
- }
-}
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
deleted file mode 100644
index acbaa8189..000000000
--- a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.tapestry5.ioc.junit;
-
-import static org.apache.tapestry5.ioc.junit.RegistryShutdownType.AFTER_METHOD;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.runners.MethodSorters.NAME_ASCENDING;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.junit.Registry;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunner;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunnerAfterMethodTest.AfterMethodTestModule;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(TapestryIOCJUnit4ClassRunner.class)
-@Registry(modules=AfterMethodTestModule.class, shutdown=AFTER_METHOD)
-@FixMethodOrder(NAME_ASCENDING) // guarantees test ordering
-public class TapestryIOCJUnit4ClassRunnerAfterMethodTest {
- public static class AfterMethodTestModule {
- public List<String> buildList() {
- List<String> list = new ArrayList<String>();
- list.add("foo");
- return list;
- }
- }
-
- @Inject
- private List<String> list;
-
- @Test
- public void testInjectA() {
- assertArrayEquals(new Object[] { "foo" }, list.toArray());
-
- list.add("bar");
- }
-
- @Test
- public void testInjectB() {
- assertArrayEquals(new Object[] { "foo" }, list.toArray());
-
- list.add("baz");
- }
-
- @Test
- public void testInjectC() {
- assertArrayEquals(new Object[] { "foo" }, list.toArray());
- }
-}
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerModuleDefTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
deleted file mode 100644
index 3915584c8..000000000
--- a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.tapestry5.ioc.junit;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.junit.ModuleDef;
-import org.apache.tapestry5.ioc.junit.Registry;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunner;
-import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit4ClassRunnerModuleDefTest.ModuleDefTestModule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(TapestryIOCJUnit4ClassRunner.class)
-@Registry(modules=ModuleDefTestModule.class)
-public class TapestryIOCJUnit4ClassRunnerModuleDefTest {
- @ModuleDef
- public static MapModuleDef createModuleDef1() {
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("a", new Date(111));
- map.put("b", 222L);
-
- return new MapModuleDef(map);
- }
-
- @ModuleDef
- public static org.apache.tapestry5.ioc.def.ModuleDef createModuleDef2() {
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("c", 333);
-
- return new MapModuleDef(map);
- }
-
- public static class ModuleDefTestModule {
- public String buildD() {
- return "444";
- }
- }
-
- @Inject private Date a;
- @Inject private Long b;
- @Inject private Integer c;
- @Inject private String d;
-
- @Test
- public void testModuleDefInject() {
- assertEquals(new Date(111), a);
- assertEquals(new Long(222L), b);
- assertEquals(new Integer(333), c);
- assertEquals("444", d);
- }
-}
\ No newline at end of file
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterClassTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterClassTest.java
new file mode 100644
index 000000000..40a894e11
--- /dev/null
+++ b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterClassTest.java
@@ -0,0 +1,74 @@
+// Copyright 2006–2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.ioc.junit;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.junit.TapestryIOCJUnit5AfterClassTest.AfterClassTestModule;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(TapestryIOCJUnitExtension.class)
+@Registry(modules = AfterClassTestModule.class, shutdown = RegistryShutdownType.AFTER_CLASS)
+@TestMethodOrder(OrderAnnotation.class)
+public class TapestryIOCJUnit5AfterClassTest
+{
+
+ public static class AfterClassTestModule
+ {
+ public List<String> buildList()
+ {
+ List<String> list = new ArrayList<>();
+ list.add("foo");
+ return list;
+ }
+ }
+
+ @Inject
+ private List<String> list;
+
+ @Test
+ @Order(1)
+ public void testInjectA()
+ {
+ assertArrayEquals(new Object[]
+ { "foo" }, list.toArray());
+ list.add("bar");
+ }
+
+ @Test
+ @Order(2)
+ public void testInjectB()
+ {
+ assertArrayEquals(new Object[]
+ { "foo", "bar" }, list.toArray());
+ list.add("baz");
+ }
+
+ @Test
+ @Order(3)
+ public void testInjectC()
+ {
+ assertArrayEquals(new Object[]
+ { "foo", "bar", "baz" }, list.toArray());
+ }
+}
\ No newline at end of file
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterMethodTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterMethodTest.java
new file mode 100644
index 000000000..c41dab760
--- /dev/null
+++ b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5AfterMethodTest.java
@@ -0,0 +1,69 @@
+// Copyright 2006–2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.ioc.junit;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(TapestryIOCJUnitExtension.class)
+@Registry(modules = TapestryIOCJUnit5AfterMethodTest.AfterMethodTestModule.class, shutdown = RegistryShutdownType.AFTER_METHOD)
+@TestMethodOrder(MethodOrderer.MethodName.class)
+public class TapestryIOCJUnit5AfterMethodTest
+{
+
+ public static class AfterMethodTestModule
+ {
+ public List<String> buildList()
+ {
+ List<String> list = new ArrayList<>();
+ list.add("foo");
+ return list;
+ }
+ }
+
+ @Inject
+ private List<String> list;
+
+ @Test
+ void testInjectA()
+ {
+ assertArrayEquals(new Object[]
+ { "foo" }, list.toArray());
+ list.add("bar");
+ }
+
+ @Test
+ void testInjectB()
+ {
+ assertArrayEquals(new Object[]
+ { "foo" }, list.toArray());
+ list.add("baz");
+ }
+
+ @Test
+ void testInjectC()
+ {
+ assertArrayEquals(new Object[]
+ { "foo" }, list.toArray());
+ }
+}
diff --git a/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5ModuleDefTest.java b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5ModuleDefTest.java
new file mode 100644
index 000000000..dabbb69bf
--- /dev/null
+++ b/tapestry-ioc-junit/src/test/java/org/apache/tapestry5/ioc/junit/TapestryIOCJUnit5ModuleDefTest.java
@@ -0,0 +1,74 @@
+// Copyright 2006–2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.ioc.junit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(TapestryIOCJUnitExtension.class)
+@Registry(modules = TapestryIOCJUnit5ModuleDefTest.ModuleDefTestModule.class)
+public class TapestryIOCJUnit5ModuleDefTest
+{
+
+ @ModuleDef
+ public static org.apache.tapestry5.ioc.def.ModuleDef createModuleDef1()
+ {
+ Map<String, Object> map = new HashMap<>();
+ map.put("a", new Date(111));
+ map.put("b", 222L);
+ return new MapModuleDef(map);
+ }
+
+ @ModuleDef
+ public static org.apache.tapestry5.ioc.def.ModuleDef createModuleDef2()
+ {
+ Map<String, Object> map = new HashMap<>();
+ map.put("c", 333);
+ return new MapModuleDef(map);
+ }
+
+ public static class ModuleDefTestModule
+ {
+ public String buildD()
+ {
+ return "444";
+ }
+ }
+
+ @Inject
+ private Date a;
+ @Inject
+ private Long b;
+ @Inject
+ private Integer c;
+ @Inject
+ private String d;
+
+ @Test
+ void testModuleDefInject()
+ {
+ assertEquals(new Date(111), a);
+ assertEquals(Long.valueOf(222L), b);
+ assertEquals(Integer.valueOf(333), c);
+ assertEquals("444", d);
+ }
+}
diff --git a/tapestry-jmx/src/test/conf/testng.xml b/tapestry-jmx/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-jmx/src/test/conf/testng.xml
rename to tapestry-jmx/src/test/resources/testng.xml
diff --git a/tapestry-jpa/build.gradle b/tapestry-jpa/build.gradle
index 58c723e7b..5e402d261 100644
--- a/tapestry-jpa/build.gradle
+++ b/tapestry-jpa/build.gradle
@@ -15,6 +15,7 @@ def moduleLibs = [
dependencies {
implementation project(':tapestry-core')
+ api libs.javax.persistence.api
implementation moduleLibs.jpaSpecs
implementation moduleLibs.javaxCdiApi
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java
index 75697ab4e..e4d3df4e8 100644
--- a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java
@@ -14,17 +14,22 @@
package org.apache.tapestry5.jpa.integration.app5;
+import java.util.List;
import java.util.Map;
+import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Query;
+import javax.persistence.StoredProcedureQuery;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.metamodel.Metamodel;
public class DummyEntityManager implements EntityManager
@@ -276,5 +281,71 @@ public class DummyEntityManager implements EntityManager
{
return null;
}
+
+ @Override
+ public Query createQuery(CriteriaUpdate updateQuery)
+ {
+ return null;
+ }
+
+ @Override
+ public Query createQuery(CriteriaDelete deleteQuery)
+ {
+ return null;
+ }
+
+ @Override
+ public StoredProcedureQuery createNamedStoredProcedureQuery(String name)
+ {
+ return null;
+ }
+
+ @Override
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName)
+ {
+ return null;
+ }
+
+ @Override
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses)
+ {
+ return null;
+ }
+
+ @Override
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isJoinedToTransaction()
+ {
+ return false;
+ }
+
+ @Override
+ public <T> EntityGraph<T> createEntityGraph(Class<T> rootType)
+ {
+ return null;
+ }
+
+ @Override
+ public EntityGraph<?> createEntityGraph(String graphName)
+ {
+ return null;
+ }
+
+ @Override
+ public EntityGraph<?> getEntityGraph(String graphName)
+ {
+ return null;
+ }
+
+ @Override
+ public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass)
+ {
+ return null;
+ }
}
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java
index f4ab8da50..c1206326e 100644
--- a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java
@@ -15,9 +15,12 @@
package org.apache.tapestry5.jpa.integration.app5;
import javax.persistence.Cache;
+import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnitUtil;
+import javax.persistence.Query;
+import javax.persistence.SynchronizationType;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.metamodel.Metamodel;
import java.util.Map;
@@ -78,4 +81,34 @@ final class DummyEntityManagerFactory implements EntityManagerFactory
{
}
+
+ @Override
+ public EntityManager createEntityManager(SynchronizationType synchronizationType)
+ {
+ return null;
+ }
+
+ @Override
+ public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map)
+ {
+ return null;
+ }
+
+ @Override
+ public void addNamedQuery(String name, Query query)
+ {
+
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> cls)
+ {
+ return null;
+ }
+
+ @Override
+ public <T> void addNamedEntityGraph(String graphName, EntityGraph<T> entityGraph)
+ {
+
+ }
}
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java
index 723b67768..240cbae6c 100644
--- a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java
@@ -41,4 +41,15 @@ public class DummyPersistenceProvider implements PersistenceProvider
return null;
}
+ @Override
+ public void generateSchema(PersistenceUnitInfo info, Map map)
+ {
+
+ }
+
+ @Override
+ public boolean generateSchema(String persistenceUnitName, Map map)
+ {
+ return false;
+ }
}
diff --git a/tapestry-jpa/src/test/conf/testng.xml b/tapestry-jpa/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-jpa/src/test/conf/testng.xml
rename to tapestry-jpa/src/test/resources/testng.xml
diff --git a/tapestry-json/src/test/conf/testng.xml b/tapestry-json/src/test/conf/testng.xml
deleted file mode 100644
index ab3857602..000000000
--- a/tapestry-json/src/test/conf/testng.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
-<suite name="Tapestry JSON" annotations="1.5" verbose="2">
- <test name="Unit Tests" enabled="true">
- <packages>
- <package name="org.apache.tapestry5.json"/>
- </packages>
- </test>
-</suite>
diff --git a/tapestry-json/src/test/groovy/json/specs/CoercionsSpec.groovy b/tapestry-json/src/test/groovy/json/specs/CoercionsSpec.groovy
deleted file mode 100644
index d7c1d1494..000000000
--- a/tapestry-json/src/test/groovy/json/specs/CoercionsSpec.groovy
+++ /dev/null
@@ -1,29 +0,0 @@
-package json.specs
-
-import org.apache.tapestry5.internal.json.StringToJSONArray
-import org.apache.tapestry5.internal.json.StringToJSONObject
-import org.apache.tapestry5.json.JSONArray
-import org.apache.tapestry5.json.JSONObject
-import spock.lang.Specification
-
-class CoercionsSpec extends Specification {
-
- def "string to JSONObject"() {
- def json = /{foo:"bar"}/
- def expected = new JSONObject(json)
-
- expect:
-
- new StringToJSONObject().coerce(json) == expected
- }
-
- void "string to JSONArray"() {
-
- def json = /[1, 2, 'three']/
- def expected = new JSONArray(json)
-
- expect:
-
- new StringToJSONArray().coerce(json) == expected
- }
-}
diff --git a/tapestry-json/src/test/groovy/json/specs/JSONArraySpec.groovy b/tapestry-json/src/test/groovy/json/specs/JSONArraySpec.groovy
deleted file mode 100644
index 52419cc7e..000000000
--- a/tapestry-json/src/test/groovy/json/specs/JSONArraySpec.groovy
+++ /dev/null
@@ -1,639 +0,0 @@
-package json.specs
-
-import org.apache.tapestry5.json.JSONArray
-import org.apache.tapestry5.json.JSONLiteral
-import org.apache.tapestry5.json.JSONObject
-import org.apache.tapestry5.json.exceptions.JSONArrayIndexOutOfBoundsException
-import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException
-import org.apache.tapestry5.json.exceptions.JSONSyntaxException
-import org.apache.tapestry5.json.exceptions.JSONTypeMismatchException
-
-import spock.lang.Specification
-
-class JSONArraySpec extends Specification {
-
- def "can create a JSONArray by parsing a JSON string"() {
- when:
-
- def array = new JSONArray(/[ 'foo', 'bar', "baz" ]/)
-
- then:
-
- array.size() == 3
- array.get(0) == "foo"
- array.get(1) == "bar"
- array.get(2) == "baz"
- }
-
- def "create a JSONArray from varags"() {
- when:
-
- def array = new JSONArray("fred", "barney", "wilma")
-
- then:
-
- array.size() == 3
-
- array.toCompactString() == /["fred","barney","wilma"]/
- }
-
- def "array must start with a bracket"() {
- when:
-
- new JSONArray("1, 2, 3]")
-
- then:
-
- JSONSyntaxException e = thrown()
-
- e.message == "A JSONArray text must start with '[' (actual: '1') at character 1 of 1, 2, 3]"
- }
-
- def "parse an empty array"() {
- when:
-
- def array = new JSONArray("[]")
-
- then:
-
- array.isEmpty()
- }
-
- def "isEmpty() is false if array is non-empty"() {
- when:
-
- def array = new JSONArray("[1]")
-
- then:
-
- array.isEmpty() == false
- }
-
- def "isEmpty() == zero length == zero size"() {
- when:
-
- def array = new JSONArray("[]")
-
- then:
-
- array.isEmpty()
- array.length() == 0
- array.size() == 0
- }
-
- def "an empty element in the parse is a null"() {
- when:
-
- def array = new JSONArray("[1,,3]")
-
- then:
-
- array.size() == 3
- array.getInt(0) == 1
- array.isNull(1)
- array.getInt(2) == 3
- }
-
- def "a comma at the end of the list is ignored"() {
- when:
-
- def array = new JSONArray("[1,2,]")
-
- then:
-
- array.size() == 2
- array.get(0) == 1
- array.get(1) == 2
- }
-
- def "getBoolean() when not a boolean at index is an exception"() {
- def array = new JSONArray("[123]")
-
- when:
-
- array.getBoolean(0)
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == "JSONArray[0] is not a BOOLEAN. Actual: java.lang.Integer"
- }
-
- def "handling of boolean values passed into constructor"() {
- when:
-
- def array = new JSONArray(true, false, "True", "False")
-
- then:
-
- array.getBoolean(0) == true
- array.getBoolean(1) == false
-
- array.getBoolean(2) == true
- array.getBoolean(3) == false
- }
-
- def "getDouble() when not a double at index is an exception"() {
- def array = new JSONArray(true)
-
- when:
-
- array.getDouble(0)
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == "JSONArray[0] is not a NUMBER. Actual: java.lang.Boolean"
- }
-
- def "getDouble() works with numbers and parseable strings"() {
- def array = new JSONArray(400l, "95.5")
-
- expect:
-
- array.getDouble(0) == 400d
- array.getDouble(1) == 95.5d
- }
-
- def "getLong() works with numbers and parseable strings"() {
- def array = new JSONArray(400l, "95.5")
-
- expect:
-
- array.getLong(0) == 400l
- array.getLong(1) == 95l
- }
-
- def "getJSONArray() when not an array at index is exception"() {
- def array = new JSONArray("fred", "barney")
-
- when:
-
- array.getJSONArray(1)
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == "JSONArray[1] is not a ARRAY. Actual: java.lang.String"
- }
-
- def "get a nested array"() {
- def nested = new JSONArray()
- def outer = new JSONArray(nested)
-
- expect:
-
- outer.getJSONArray(0).is(nested)
- }
-
- def "getJSONObject() when not a JSONObject at index is an exception"() {
- def array = new JSONArray("fred", "barney", "wilma")
-
- when:
-
- array.getJSONObject(1)
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == "JSONArray[1] is not a OBJECT. Actual: java.lang.String"
- }
-
- def "may not put at a negative index"() {
- def array = new JSONArray()
-
- when:
-
- array.put(-2, "fred")
-
- then:
-
- JSONArrayIndexOutOfBoundsException e = thrown()
-
- e.index == -2
- }
-
- def "put() overrides existing value in array"() {
- def array = new JSONArray("fred", "barney", "wilma")
-
- when:
-
- array.put 2, "betty"
-
- then:
-
- array.get(2) == "betty"
- }
-
- def "put() with index past end pads array with nulls"() {
- def array = new JSONArray("fred", "barney", "wilma")
-
- when:
-
- array.put 4, "bambam"
-
- then:
-
- array.isNull(3)
-
- array.toCompactString() == /["fred","barney","wilma",null,"bambam"]/
- }
-
- def "array equality"() {
- when:
-
- def array1 = new JSONArray(1, 2, 3)
- def array2 = new JSONArray(1, 2, 3)
-
- then:
-
- array1 == array1
- !array1.equals(null)
- array1 != this
- array1 == array2
-
- when:
-
- array2.put 9, "stuff"
-
- then:
-
- array1 != array2
- }
-
- def "array hashCode"() {
- when:
-
- def array1 = new JSONArray(1, 2, 3)
- def array2 = new JSONArray(1, 2, 3)
-
- then:
-
- array1.hashCode() == array2.hashCode()
-
- when:
-
- array2.put 9, "stuff"
-
- then:
-
- array1.hashCode() != array2.hashCode()
- }
-
- def "pretty print"() {
- def array = new JSONArray("fred", "barney")
-
- expect:
-
- array.toString() == '''[
- "fred",
- "barney"
-]'''
- }
-
- def "JSONArray is Iterable"() {
- def array = new JSONArray(1, 2, false)
-
- when:
-
- def i = array.iterator()
-
- then:
-
- i.next() == 1
- i.next() == 2
- i.next() == false
-
- !i.hasNext()
- }
-
- def "remove an element by index"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- array.remove(1)
-
- then:
-
- array.size() == 2
- array.toCompactString() == /["one","three"]/
- }
-
- def "remove an element by value"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.remove("one")
-
- then:
-
- result == true
- array.size() == 2
- array.toCompactString() == /["two","three"]/
- }
-
- def "remove an element by value - not found"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.remove("four")
-
- then:
-
- result == false
- array.size() == 3
- array.toCompactString() == /["one","two","three"]/
- }
-
- def "remove all elements by collection"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.removeAll(["one", "three"])
-
- then:
-
- result == true
- array.size() == 1
- array.toCompactString() == /["two"]/
- }
-
- def "remove all elements by collection - partial"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.removeAll(["one", "four"])
-
- then:
-
- result == true
- array.size() == 2
- array.toCompactString() == /["two","three"]/
- }
-
- def "remove all elements by collection - none found"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.removeAll(["four", "five"])
-
- then:
-
- result == false
- array.size() == 3
- array.toCompactString() == /["one","two","three"]/
- }
-
- def "retain all elements by collection - all"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.retainAll(["one", "two", "three"])
-
- then:
-
- result == false
- array.size() == 3
- array.toCompactString() == /["one","two","three"]/
- }
-
- def "retain all elements by collection - partial"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.retainAll(["one", "three"])
-
- then:
-
- result == true
- array.size() == 2
- array.toCompactString() == /["one","three"]/
- }
-
- def "retain all elements by collection - none"() {
- def array = new JSONArray("one", "two", "three")
-
- when:
-
- def result = array.retainAll(["four", "five"])
-
- then:
-
- result == true
- array.isEmpty()
- array.toCompactString() == /[]/
- }
-
- def "putAll() adds new objects to existing array"() {
- def array = new JSONArray(100, 200)
-
- when:
-
- array.putAll([300, 400, 500])
-
- then:
-
- array.toCompactString() == /[100,200,300,400,500]/
- }
-
- def "putAll() with null does not modify the array"() {
- def array = new JSONArray(100, 200)
-
- when:
-
- array.putAll(null)
-
- then:
-
- array.toCompactString() == /[100,200]/
- }
-
-
- def "addAll() adds new objects to existing array"() {
- def array = new JSONArray(100, 200)
-
- when:
-
- array.addAll([300, 400, 500])
-
- then:
-
- array.toCompactString() == /[100,200,300,400,500]/
- }
-
-
- def "addAll() returns true if changed"() {
- def array = new JSONArray(100, 200)
-
- when:
-
- def result = array.addAll([300, 400, 500])
-
- then:
-
- result == true
- }
-
- def "addAll() returns false if not changed"() {
- def array = new JSONArray(100, 200)
-
- when:
-
- def result = array.addAll((Collection)null)
-
- then:
-
- result == false
- }
-
- def "list returned by toList() is unmodifiable"() {
- def array = new JSONArray(100, 200)
- def list = array.toList()
-
- when:
-
- list.clear()
-
- then:
-
- thrown(UnsupportedOperationException)
- }
-
- def "list from toList() is live"() {
- def array = new JSONArray(100, 200)
- when:
-
- def list = array.toList()
-
- then:
-
- list == [100, 200]
-
- when:
-
- array.remove(0)
-
- then:
-
- list == [200]
- }
-
- def "can initialize JSONObject from an Iterable"() {
- when:
-
- def list = JSONArray.from([1, 2, 3])
-
- then:
-
- list.toString(true) == "[1,2,3]"
- }
-
- def "put() should throw an IllegalArgumentException when receiving null"() {
-
- def array = new JSONArray()
-
- when:
-
- array.put(null)
-
- then:
-
- thrown IllegalArgumentException
- }
-
- def "new JSONArray() should throw an IllegalArgumentException when receiving null"() {
-
- when:
-
- new JSONArray(1, null, 3)
-
- then:
-
- thrown IllegalArgumentException
- }
-
- def "only specific object types may be added - no exception"() {
- def array = new JSONArray()
-
- when:
-
- array.put(value)
-
- then:
-
- noExceptionThrown()
-
- where:
- value << [
- true,
- 3,
- 3.5,
- "*VALUE*",
- new JSONLiteral("*LITERAL*"),
- new JSONObject(),
- new JSONArray()
- ]
- }
-
- def "only specific object types may be added - exception"() {
- def array = new JSONArray()
-
- when:
-
- array.put(value)
-
- then:
-
- JSONInvalidTypeException e = thrown()
-
- where:
- value << [
- new java.util.Date(),
- [],
- [:]
- ]
- }
-
- def "array index out of bounds must throw informative exception"() {
- def array = new JSONArray(1, 2, 3)
-
- when:
-
- array.get(array.size())
-
- then:
-
- JSONArrayIndexOutOfBoundsException e = thrown()
- e.index == 3
- }
-
- def "non-finite / NaN Double not allowed in constructor"() {
-
- when:
-
- new JSONArray(value)
-
- then:
-
- RuntimeException e = thrown()
-
- where:
- value << [
- Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY,
- Double.NaN
- ]
- }
-}
diff --git a/tapestry-json/src/test/groovy/json/specs/JSONCollectorsSpec.groovy b/tapestry-json/src/test/groovy/json/specs/JSONCollectorsSpec.groovy
deleted file mode 100644
index a8c452312..000000000
--- a/tapestry-json/src/test/groovy/json/specs/JSONCollectorsSpec.groovy
+++ /dev/null
@@ -1,101 +0,0 @@
-package json.specs
-
-import org.apache.tapestry5.json.JSONCollectors
-import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException
-
-import java.util.stream.Stream
-
-import spock.lang.Specification
-
-class JSONCollectorsSpec extends Specification {
-
- def "collect stream to array"() {
-
- given:
-
- def stringValue = "a string value"
- def longValue = 3L
-
- def stream = Stream.of(stringValue, longValue)
-
- when:
-
- def collected = stream.collect(JSONCollectors.toArray());
-
- then:
-
- collected.size() == 2
- collected.get(0) == stringValue
- collected.get(1) == longValue
- }
-
- def "collect stream to array invalid type"() {
-
- given:
-
- def stringValue = "a string value"
- def longValue = 3L
- def invalidValue = new java.util.Date()
-
- def stream = Stream.of(stringValue, longValue, invalidValue)
-
- when:
-
- def collected = stream.collect(JSONCollectors.toArray());
-
- then:
-
- JSONInvalidTypeException e = thrown()
- }
-
- def "collect stream to map"() {
-
- given:
-
- def first = new Tuple("first key", "a string value")
- def second = new Tuple("second key", 3L)
-
- def stream = Stream.of(first, second)
-
- when:
-
- def collected = stream.collect(JSONCollectors.toMap({ t -> t.get(0) }, { t -> t.get(1) }));
-
- then:
-
- collected.size() == 2
- collected.get(first.get(0)) == first.get(1)
- collected.get(second.get(0)) == second.get(1)
- }
-
- def "collect stream to map invalid type"() {
-
- given:
-
- def first = new Tuple("first key", "a string value")
- def second = new Tuple("second key", 3L)
- def third = new Tuple("invalid type", new java.util.Date())
-
- def stream = Stream.of(first, second, third)
-
- when:
-
- def collected = stream.collect(JSONCollectors.toMap({ t -> t.get(0) }, { t -> t.get(1) }));
-
- then:
-
- JSONInvalidTypeException e = thrown()
- }
-
- def "collect stream to map duplicate key"() {
-
- when:
-
- def collected = Stream.of("first", "second", "first").collect(JSONCollectors.toMap({ v -> v }, { v -> v }))
-
- then:
-
- IllegalStateException e = thrown()
- }
-
-}
diff --git a/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy b/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
deleted file mode 100644
index 4d07bc605..000000000
--- a/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
+++ /dev/null
@@ -1,989 +0,0 @@
-package json.specs
-
-import org.apache.tapestry5.json.JSONArray
-import org.apache.tapestry5.json.JSONLiteral
-import org.apache.tapestry5.json.JSONObject
-import org.apache.tapestry5.json.JSONString
-import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException
-import org.apache.tapestry5.json.exceptions.JSONSyntaxException
-import org.apache.tapestry5.json.exceptions.JSONTypeMismatchException
-import org.apache.tapestry5.json.exceptions.JSONValueNotFoundException
-
-import spock.lang.Issue
-import spock.lang.Specification
-import spock.lang.Unroll
-
-class JSONObjectSpec extends Specification {
-
- def "copy an existing JSONObject"() {
- def master = new JSONObject("fred", "flintstone", "barney", "rubble")
-
- when:
-
- def emptyCopy = new JSONObject(master)
-
- then:
-
- emptyCopy.keys().empty
-
- when:
-
- def limitedCopy = new JSONObject(master, "fred")
-
- then:
-
- limitedCopy.keys().size() == 1
- limitedCopy.get("fred") == "flintstone"
-
- when:
-
- def fullCopy = new JSONObject(master, "fred", "barney")
-
- then:
-
- fullCopy.toCompactString() == /{"fred":"flintstone","barney":"rubble"}/
- }
-
- def "copy all properties of JSONObject"() {
- def master = new JSONObject("fred", "flintstone", "barney", "rubble")
-
- when:
-
- def fullCopy = master.copy()
-
- then:
-
- master == fullCopy
-
- // And they are independent:
-
- when:
-
- master.put("wilma", "flintstone")
-
- then:
-
- master != fullCopy
- }
-
- def "unknown keys when copying a JSONObject are ignored"() {
- def master = new JSONObject("fred", "flintstone", "barney", "rubble")
-
- when:
-
- def copy = new JSONObject(master, "fred", "wilma")
-
- then:
-
- copy.keys().size() == 1
- copy.get("fred") == "flintstone"
- }
-
- def "get with unknown key is an exception"() {
- def master = new JSONObject("fred", "flintstone")
-
- when:
-
- master.get "barney"
-
- then:
-
- JSONValueNotFoundException e = thrown()
-
- e.message == /JSONObject["barney"] is not found. Required: ANY/
- }
-
- def "getOrDefault returns defaultValue if not found"() {
- def master = new JSONObject("fred", "flintstone")
-
- when:
-
- def result = master.getOrDefault "barney", "gumble"
-
- then:
-
- result == "gumble"
- }
-
- def "getOrDefault returns value if found"() {
- def master = new JSONObject("fred", "flintstone")
-
- when:
-
- def result = master.getOrDefault "fred", "other"
-
- then:
-
- result == "flintstone"
- }
-
- @Unroll
- def "ensure that stored value #typeName #value is #expectedTypeName #expected"() {
-
- when:
-
- def object = new JSONObject().put("key", value)
-
- then:
-
- object."get${expectedTypeName.capitalize()}"("key") == expected
-
- where:
-
- value | expected | expectedType
- "true" | true | boolean
- "TRUE" | true | boolean
- "false" | false | boolean
- "FALSE" | false | boolean
- Boolean.TRUE | true | boolean
- Boolean.FALSE | false | boolean
- 3.5d | 3.5d | double
- 1000l | 1000d | double
- "-101.7" | -101.7d | double
- "3" | 3 | int
- 97l | 97 | int
- "-8.76" | -8 | int
- 92d | 92l | long
- "-200" | -200l | long
- 123 | "123" | String
-
- typeName = value.class.simpleName
- expectedTypeName = expectedType.simpleName
- }
-
- @Unroll
- def "conversion of double #input to string should be '#expected'"() {
- expect:
-
- JSONObject.doubleToString(input) == expected
-
- where:
-
- input | expected
- 3d | "3"
- -22.5d | "-22.5"
- 0d | "0"
- Double.NaN | "null"
- Double.NEGATIVE_INFINITY | "null"
- Double.POSITIVE_INFINITY | "null"
- }
-
- def "exception when getBoolean() on a value that is not a boolean"() {
-
- def object = new JSONObject().put("akey", 37)
-
- when:
-
- object.getBoolean "akey"
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == /JSONObject["akey"] is not a BOOLEAN. Actual: java.lang.Integer/
- }
-
- def "accumulate simple values"() {
- def object = new JSONObject()
-
- def key = "acckey"
-
- when:
-
- object.accumulate key, "alpha"
-
- then: "first value added is just stored"
-
- object.toCompactString() == /{"acckey":"alpha"}/
-
- when: "subsequent values added are accumulated in a JSONArray"
-
- object.accumulate key, "beta"
- object.accumulate key, "gamma"
-
- then:
-
- object.toCompactString() == /{"acckey":["alpha","beta","gamma"]}/
-
- object.getJSONArray(key).length() == 3
- }
-
- def "accumulate when the stored value is already an array just appends the value"() {
- def object = new JSONObject()
-
- when:
-
- object.accumulate "key", new JSONArray("fred", "barney")
-
- then:
-
- object.toCompactString() == /{"key":["fred","barney"]}/
-
- when:
-
- object.accumulate "key", "wilma"
-
- then:
-
- object.toCompactString() == /{"key":["fred","barney","wilma"]}/
- }
-
- def "can create a JSONObject from a JSON string"() {
- when:
-
- def object = new JSONObject(/ { fred: "flintstone", caveman: true, friends: ["barney"] }/)
-
- then:
-
- object.get("fred") == "flintstone"
- object.getBoolean("caveman") == true
-
- def friends = object.getJSONArray "friends"
-
- friends.length() == 1
- friends.get(0) == "barney"
- }
-
- def "append to an unknown key creates a JSONArray for the value"() {
- def object = new JSONObject()
-
- when:
-
- object.append "friends", "barney"
-
- then:
-
- object.toCompactString() == /{"friends":["barney"]}/
- }
-
- def "append to an existing key containing a JSONArray appends to the array"() {
- def object = new JSONObject(/{friends: ["barney"] }/)
-
- when:
-
- object.append "friends", "zaphod"
-
- then:
-
- object.toCompactString() == /{"friends":["barney","zaphod"]}/
- }
-
- def "appending to a key whose value is not aArray is an exception"() {
- def object = new JSONObject(/{friends: 0 }/)
-
- when:
-
- object.append "friends", "zaphod"
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == /JSONObject["friends"] is not a ARRAY. Actual: java.lang.Integer/
- }
-
- def "getDouble() with a non-numeric value is an exception"() {
- def object = new JSONObject(/{notdouble: true}/)
-
- when:
-
- object.getDouble "notdouble"
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == /JSONObject["notdouble"] is not a NUMBER. Actual: java.lang.Boolean/
- }
-
- def "getDouble() with a string that can not be parsed as a number is an exception"() {
- def object = new JSONObject(/{notdouble: "this is a fact"}/)
-
- when:
-
- object.getDouble "notdouble"
-
- then:
-
- JSONTypeMismatchException e = thrown()
-
- e.message == /JSONObject["notdouble"] is not a NUMBER. Actual: java.lang.String/
- }
-
- def "has() will identify which keys have values and which do not"() {
- def object = new JSONObject(/{fred: 'flintstone'}/)
-
- expect:
-
- object.has("fred")
- !object.has("barney")
- }
-
- def "getJSONArray() for a value that is not aArray is an exception"() {
- def object = new JSONObject(/{notarray: 22.7}/)
-
- when:
-
- object.getJSONArray "notarray"
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == /JSONObject["notarray"] is not a ARRAY. Actual: java.lang.Double/
- }
-
- def "length() of a JSONObject is the number of keys"() {
- when:
-
- def object = new JSONObject()
-
- then:
-
- object.length() == 0
-
- when:
-
- object.put "fred", "flintstone"
-
- then:
-
- object.length() == 1
-
- when:
-
- object.accumulate "fred", "murray"
-
- then:
-
- object.length() == 1
-
- when:
-
- object.put "barney", "rubble"
-
- then:
-
- object.length() == 2
- }
-
- def "names() returns the keys as a JSONArray"() {
- def object = new JSONObject(/ {fred: 'flintstone', barney: 'rubble' }/)
-
- when:
-
- def names = object.names()
-
- then:
-
- names instanceof JSONArray
- names.length() == 2
-
- new ArrayList(names.toList()).sort() == ["barney", "fred"]
- }
-
- def "names() with no properties returns null"() {
-
- when:
-
- def object = new JSONObject()
-
- then:
-
- object.names() == null
- }
-
- def "the null literal is the NULL object"() {
- when:
-
- def object = new JSONObject(/{nullkey: null}/)
-
- then:
-
- object.get("nullkey") is JSONObject.NULL
- object.isNull("nullkey")
- }
-
- def "the NULL object is output as null literal"() {
- when:
-
- def object = new JSONObject().put("nullkey", JSONObject.NULL)
-
- then:
-
- object.isNull("nullkey")
- object.toCompactString() == /{"nullkey":null}/
- }
-
- def "the NULL object matches Java's null"() {
- expect:
-
- JSONObject.NULL.equals(null)
- }
-
- @Unroll
- def "#desc invalid input is an exception"() {
- when:
-
- new JSONObject(input)
-
- then:
-
- JSONSyntaxException e = thrown()
-
- e.message.trim().startsWith expected
-
- where:
-
- input | expected | desc
- "{ " | "A JSONObject text must end with '}' at character 3" | "unmatched open brace"
- "fred" | /A JSONObject text must start with '{' (actual: 'f') at character 1 of/ | "missing open brace"
- /{ "akey" }/ | /Expected a ':' after a key at character 10 of/ | "missing value after key"
- /{ "fred" : 1 "barney" }/ | /Expected a ',' or '}' at character 14 of/ | "missing property separator"
- /{ "list" : [1, 2/ | /Expected a ',' or ']' at character 16 of/ | "missing seperator or closing bracket"
- '''/* unclosed''' | /Unclosed comment at character 11 of/ | "unclosed C-style comment"
- /{ "fred \n}/ | /Unterminated string at character 11 of/ | "unterminated string at line end"
- /{ fred: ,}/ | /Missing value at character 8 of / | "missing value after key"
- }
-
- def "can use ':' or '=>' as key seperator, and ';' as property separator"() {
- def object = new JSONObject(/{ "fred" = 1; "barney" => 2}/)
-
- expect:
-
- object.getInt("fred") == 1
- object.getInt("barney") == 2
- }
-
- @Unroll
- def "conversion of #typeName #value to string is #expected"() {
- expect:
-
- JSONObject.numberToString(value) == expected
-
- where:
-
- value | expected
- new BigDecimal("100.0000000") | "100"
-
- typeName = value.class.simpleName
- }
-
- @Unroll
- def "quote(): #desc"() {
- expect:
-
- JSONObject.quote(value) == expected
-
- where:
-
- value | expected | desc
- null | /""/ | "null is empty string"
- "" | /""/ | "empty string is empty string"
- '''"/\b\t\n\f\r\u2001/a</''' | '''"\\"/\\b\\t\\n\\f\\r\\u2001/a<\\/"''' | "special characters"
- }
-
- def "non-finite numbers are not allowed"() {
- def object = new JSONObject()
-
- when:
-
- object.put "nonfinite", value
-
- then:
-
- RuntimeException e = thrown()
-
- e.message == /JSON does not allow non-finite numbers./
-
- where:
-
- value << [
- Double.NaN,
- Double.NEGATIVE_INFINITY,
- Double.POSITIVE_INFINITY,
- Float.NaN,
- Float.NEGATIVE_INFINITY,
- Float.POSITIVE_INFINITY
- ]
- }
-
- def "parse an empty object is empty"() {
- when:
-
- def object = new JSONObject(/{}/)
-
- then:
-
- object.length() == 0
- }
-
- def "put a Java null is a remove"() {
- def object = new JSONObject(/{fred:'flintstone', barney:'rubble'}/)
-
- when:
-
- object.put("fred", null)
-
- then:
-
- object.toCompactString() == /{"barney":"rubble"}/
- }
-
- def "only specific object types may be added - no exception"() {
- def object = new JSONObject(/{}/)
-
- when:
-
- object.put("key", value)
-
- then:
-
- noExceptionThrown()
-
- where:
- value << [
- null,
- true,
- 3,
- 3.5,
- "*VALUE*",
- new JSONLiteral("*LITERAL*"),
- new JSONObject(),
- new JSONArray()
- ]
- }
-
- def "only specific object types may be added - exception"() {
- def object = new JSONObject(/{}/)
-
- when:
-
- object.put("key", value)
-
- then:
-
- JSONInvalidTypeException e = thrown()
-
- where:
- value << [
- new java.util.Date(),
- [],
- [:]
- ]
- }
-
- def "JSONString can output anything it wants"() {
- def string = { "*VALUE*" } as JSONString
-
- def object = new JSONObject()
-
- when:
-
- object.put("key", string)
-
- then:
-
- object.toCompactString() == /{"key":*VALUE*}/
- }
-
- def "equals() implementation"() {
- def json = /{ "key" : 99 }/
-
- when:
-
- def obj1 = new JSONObject(json)
- def obj2 = new JSONObject(json)
-
- then:
-
- obj1 == obj2
- obj2 == obj1
-
- obj1.equals(null) == false
- obj1 != json
-
- when:
-
- obj2.put("screw", "the pooch")
-
- then:
-
- obj1 != obj2
- }
-
- def "hashCode() implementation"() {
- def json = /{ "key" : 99 }/
-
- when:
-
- def obj1 = new JSONObject(json)
- def obj2 = new JSONObject(json)
-
- then:
-
- obj1.hashCode() == obj2.hashCode()
-
- when:
-
- obj2.put("screw", "the pooch")
-
- then:
-
- obj1.hashCode() != obj2.hashCode()
- }
-
- def "escaped characters in the JSON are parsed correctly"() {
- when:
-
- def object = new JSONObject("{ \"key\" : \"\\\"/\\b\\t\\n\\f\\r\\u2001/a<\\/\\x20\" }")
-
- then:
-
- object.get("key") == '''"/\b\t\n\f\r\u2001/a</ '''
- }
-
- def "parse a nested object"() {
- def object = new JSONObject(/ { key: { name: "inner" }}/)
-
- expect:
-
- object.getJSONObject("key").getString("name") == "inner"
- }
-
- def "parse boolean literals"() {
- def object = new JSONObject(/{ t: true, f: false }/)
-
- expect:
-
- object.getBoolean("t") == true
- object.getBoolean("f") == false
- }
-
- def "parse numeric forms"() {
- def object = new JSONObject(/{ hex: 0x50, oct: 030, posInt: +50, negInt: -50,
- long: 4294968530, float: -32.7 }/)
-
- expect:
-
- object.getInt("hex") == 80
- object.getInt("oct") == 24
- object.getInt("posInt") == 50
- object.getInt("negInt") == -50
- object.getLong("long") == 4294968530l
- object.getDouble("float") == -32.7d
- }
-
- def "NULL toString() is null keyword"() {
- expect:
-
- JSONObject.NULL.toString() == "null"
- }
-
- def "JSONLiteral can output any content"() {
-
- def text = '''function(x) { $('bar').show(); }'''
-
- def literal = new JSONLiteral(text)
-
- when:
-
- def object = new JSONObject().put("callback", literal)
-
- then:
-
- object.toCompactString() == /{"callback":${text}}/
- literal.toString() == text
- }
-
- def "pretty print"() {
- def object = new JSONObject("fred", "flintstone", "barney", "rubble")
-
- expect:
-
- object.toString() == '''{
- "fred" : "flintstone",
- "barney" : "rubble"
-}'''
- }
-
- def "C style comments are ignored"() {
- when:
-
- def object = new JSONObject('''/* C comment */ { "foo" : "bar" /* *ignored* */ }''')
-
- then:
-
- object.get("foo") == "bar"
- }
-
- def "double slash comments extend to end of line"() {
- when:
-
- def object = new JSONObject('''{ foo: // This is a double-slash comment
-"bar" }''')
-
- then:
-
- object.get("foo") == "bar"
- }
-
- def "hash comments extend to end of line"() {
- when:
-
- def object = new JSONObject('''{ foo: # This is a hash comment
-"bar" }''')
-
- then:
-
- object.get("foo") == "bar"
- }
-
- def "pretty-print an empty JSONObject"() {
- def object = new JSONObject()
-
- expect:
-
- object.toString() == /{}/
- }
-
- def "complex pretty-print"() {
- when:
-
- def object = new JSONObject('''
-{ outer: { inner: "here" },
- number: 22.7,
- array: [1, 2, 3],
- boolean: true,
- otherwise: 'a quoted string'
-}
-''')
-
- then:
-
- object.toString() == '''{
- "outer" : {
- "inner" : "here"
- },
- "number" : 22.7,
- "array" : [
- 1,
- 2,
- 3
- ],
- "boolean" : true,
- "otherwise" : "a quoted string"
-}'''
- }
-
- def "toCompactString()"() {
- def object = new JSONObject("kermit", "frog")
-
- expect:
-
- object.toString(true) == /{"kermit":"frog"}/
- object.toString(false) == /{
- "kermit" : "frog"
-}/
- }
-
- def "print to PrintWriter)"() {
- def object = new JSONObject("kermit", "frog")
-
- expect:
-
- print(object, true) == /{"kermit":"frog"}/
- print(object, false) == /{
- "kermit" : "frog"
-}/
- }
-
- def withPrintWriter(closure) {
- def caw = new CharArrayWriter()
- def pw = new PrintWriter(caw)
-
- closure(pw)
-
- pw.close()
-
- return caw.toString()
- }
-
- def print(object, compact) {
-
- withPrintWriter { pw -> object.print(pw, compact) }
- }
-
- def "prettyPrint() to PrintWriter"() {
- def object = new JSONObject("kermit", "frog")
-
- when:
-
- def json = withPrintWriter { pw -> object.prettyPrint(pw) }
-
- then:
-
- json == /{
- "kermit" : "frog"
-}/
- }
-
- def "getString() at index"() {
- def array = new JSONArray("one", 2, false)
-
- expect:
-
- array.getString(0) == "one"
- array.getString(1) == "2"
- array.getString(2) == "false"
- }
-
- def "toMap() is not modifiable"() {
- def object = new JSONObject()
-
- def map = object.toMap()
-
- when:
-
- map.clear()
-
- then:
-
- thrown(UnsupportedOperationException)
- }
-
- def "can access contents of object as a map"() {
- def object = new JSONObject("foo", "bar")
- .put("null", JSONObject.NULL)
- .put("number", 6)
-
- when:
-
- def map = object.toMap()
-
- then:
-
- map.foo == "bar"
- map.number == 6
- map["null"].is(JSONObject.NULL)
- }
-
- def "the map returned by toMap() is live"() {
- def object = new JSONObject("foo", "bar")
-
- def map = object.toMap()
-
- when:
-
- object.put "foo", null
-
- then:
-
- object.length() == 0
- map.isEmpty()
- }
-
- def "can add new properties via putAll()"() {
- def object = new JSONObject("fred", "flintstone")
-
- when:
-
- def result = object.putAll([barney: "rubble", wilma: "flintstone"])
-
- then:
-
- object.toCompactString() == /{"fred":"flintstone","barney":"rubble","wilma":"flintstone"}/
- }
-
- def "in() where the value is not JSONObject is an exception"() {
- def object = new JSONObject("time", "to rock")
-
- when:
-
- object.in("time")
-
- then:
-
- IllegalStateException e = thrown()
-
- e.message == /JSONObject["time"] is not a JSONObject./
- }
-
- def "in() creates a JSONObject if necessary"() {
- def object = new JSONObject()
-
- when:
-
- object.in("nested").put("created", true)
-
- then:
-
- object.toCompactString() == /{"nested":{"created":true}}/
- }
-
- def "in() returns the JSONObject"() {
- def object = new JSONObject(/{nested: {}}/)
-
- when:
-
- object.in("nested").put("time", "to rock")
-
- then:
-
- object.toCompactString() == /{"nested":{"time":"to rock"}}/
- }
-
- def "constructor supports non-string keys and values"() {
- when:
-
- def object = new JSONObject(true, "truthy", false, false)
-
- then:
-
- object.has "true"
- object.getString("true") == "truthy"
- object.has "false"
- object.get("false").is false
- }
-
- private static copyViaSerialization(source) {
-
- def bos = new ByteArrayOutputStream()
-
- bos.withObjectOutputStream { it << source }
-
- def bis = new ByteArrayInputStream(bos.toByteArray())
-
- bis.withObjectInputStream { it.readObject() }
- }
-
- def "serialize and de-serialize"() {
- when:
-
- def source = new JSONObject("string", "a string", "null", JSONObject.NULL)
-
- def copy = copyViaSerialization source
-
- then:
-
- source == copy
- }
-
- @Issue("TAP5-2759")
- def "getLongOrDefault correct type for default value"() {
- // This test seems obvious, but it fails if the getLongOrDefault method
- // isn't using long as the type for the default value in its method declaration
- given:
-
- def object = new JSONObject()
- def defaultValue = 2_147_483_648L
-
- when:
-
- def value = object.getLongOrDefault("key", defaultValue)
-
- then:
-
- value == defaultValue
- }
-}
diff --git a/tapestry-json/src/test/groovy/json/specs/JSONSpec.groovy b/tapestry-json/src/test/groovy/json/specs/JSONSpec.groovy
deleted file mode 100644
index 5b8ae3f31..000000000
--- a/tapestry-json/src/test/groovy/json/specs/JSONSpec.groovy
+++ /dev/null
@@ -1,36 +0,0 @@
-package json.specs
-
-import org.apache.tapestry5.json.JSONArray
-import org.apache.tapestry5.json.JSONLiteral
-import org.apache.tapestry5.json.JSONObject
-import org.apache.tapestry5.json.JSONString
-import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException
-import org.apache.tapestry5.json.JSON
-import spock.lang.Specification
-import spock.lang.Unroll
-
-class JSONSpec extends Specification {
-
- def "invalid types throw JSONInvalidTypeException"() {
- when:
-
- JSON.testValidity([:])
-
- then:
-
- JSONInvalidTypeException e = thrown()
-
- e.message == '''JSONArray values / JSONObject properties may be one of Boolean, Number, String, org.apache.tapestry5.json.JSONArray, org.apache.tapestry5.json.JSONLiteral, org.apache.tapestry5.json.JSONObject, org.apache.tapestry5.json.JSONObject$Null, org.apache.tapestry5.json.JSONString. Type java.util.LinkedHashMap is not allowed.'''
- }
-
- def "null is invalid"() {
- when:
-
- JSON.testValidity(null)
-
- then:
-
- IllegalArgumentException e = thrown()
- }
-
-}
diff --git a/tapestry-json/src/test/java/org/apache/tapestry5/json/CoercionsTest.java b/tapestry-json/src/test/java/org/apache/tapestry5/json/CoercionsTest.java
new file mode 100644
index 000000000..1f516f83a
--- /dev/null
+++ b/tapestry-json/src/test/java/org/apache/tapestry5/json/CoercionsTest.java
@@ -0,0 +1,44 @@
+// Copyright 2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.json;
+
+import org.apache.tapestry5.internal.json.StringToJSONArray;
+import org.apache.tapestry5.internal.json.StringToJSONObject;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class CoercionsTest {
+
+ @Test
+ void stringToJSONObject() {
+ String jsonString = "{\"foo\":\"bar\"}";
+
+ JSONObject expected = new JSONObject(jsonString);
+
+ assertEquals(expected, new StringToJSONObject().coerce(jsonString));
+ }
+
+ @Test
+ void stringToJSONArray() {
+ String jsonString = "[1, 2, \"three\"]";
+
+ JSONArray expected = new JSONArray(jsonString);
+
+ assertEquals(expected, new StringToJSONArray().coerce(jsonString));
+ }
+}
\ No newline at end of file
diff --git a/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONArrayTest.java b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONArrayTest.java
new file mode 100644
index 000000000..a05522ebe
--- /dev/null
+++ b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONArrayTest.java
@@ -0,0 +1,488 @@
+// Copyright 2010-2023, 2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.json;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.apache.tapestry5.json.exceptions.JSONArrayIndexOutOfBoundsException;
+import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException;
+import org.apache.tapestry5.json.exceptions.JSONSyntaxException;
+import org.apache.tapestry5.json.exceptions.JSONTypeMismatchException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class JSONArrayTest {
+
+ @Test
+ void canCreateAJSONArrayByParsingAJSONString() {
+ String jsonString = "[ 'foo', 'bar', \"baz\" ]";
+
+ JSONArray array = new JSONArray(jsonString);
+
+ assertEquals(3, array.size());
+ assertEquals("foo", array.get(0));
+ assertEquals("bar", array.get(1));
+ assertEquals("baz", array.get(2));
+ }
+
+ @Test
+ void createAJSONArrayFromVarags() {
+ JSONArray array = new JSONArray("fred", "barney", "wilma");
+
+ assertEquals(3, array.size());
+ assertEquals("[\"fred\",\"barney\",\"wilma\"]", array.toCompactString());
+ }
+
+ @Test
+ void arrayMustStartWithABracket() {
+ JSONSyntaxException e = assertThrows(JSONSyntaxException.class, () -> {
+ new JSONArray("1, 2, 3]");
+ });
+
+ assertEquals("A JSONArray text must start with '[' (actual: '1') at character 1 of 1, 2, 3]", e.getMessage());
+ }
+
+ @Test
+ void parseAnEmptyArray() {
+ JSONArray array = new JSONArray("[]");
+ assertTrue(array.isEmpty());
+ }
+
+ @Test
+ void isEmptyIsFalseIfArrayIsNonEmpty() {
+ JSONArray array = new JSONArray("[1]");
+ assertFalse(array.isEmpty());
+ }
+
+ @Test
+ void isEmptyEqualsZeroLengthEqualsZeroSize() {
+ JSONArray array = new JSONArray("[]");
+
+ assertTrue(array.isEmpty());
+ assertEquals(0, array.length());
+ assertEquals(0, array.size());
+ }
+
+ @Test
+ void anEmptyElementInTheParseIsANull() {
+ JSONArray array = new JSONArray("[1,,3]");
+
+ assertEquals(3, array.size());
+ assertEquals(1, array.getInt(0));
+ assertTrue(array.isNull(1));
+ assertEquals(3, array.getInt(2));
+ }
+
+ @Test
+ void aCommaAtTheEndOfTheListIsIgnored() {
+ JSONArray array = new JSONArray("[1,2,]");
+
+ assertEquals(2, array.size());
+ assertEquals(1, array.get(0));
+ assertEquals(2, array.get(1));
+ }
+
+ @Test
+ void getBooleanWhenNotABooleanAtIndexIsAnException() {
+ JSONArray array = new JSONArray("[123]");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ array.getBoolean(0);
+ });
+
+ assertEquals("JSONArray[0] is not a BOOLEAN. Actual: java.lang.Integer", e.getMessage());
+ }
+
+ @Test
+ void handlingOfBooleanValuesPassedIntoConstructor() {
+ JSONArray array = new JSONArray(true, false, "True", "False");
+
+ assertTrue(array.getBoolean(0));
+ assertFalse(array.getBoolean(1));
+ assertTrue(array.getBoolean(2));
+ assertFalse(array.getBoolean(3));
+ }
+
+ @Test
+ void getDoubleWhenNotADoubleAtIndexIsAnException() {
+ JSONArray array = new JSONArray(true);
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ array.getDouble(0);
+ });
+
+ assertEquals("JSONArray[0] is not a NUMBER. Actual: java.lang.Boolean", e.getMessage());
+ }
+
+ @Test
+ void getDoubleWorksWithNumbersAndParseableStrings() {
+ JSONArray array = new JSONArray(400L, "95.5");
+
+ assertEquals(400d, array.getDouble(0));
+ assertEquals(95.5d, array.getDouble(1));
+ }
+
+ @Test
+ void getLongWorksWithNumbersAndParseableStrings() {
+ JSONArray array = new JSONArray(400L, "95.5");
+
+ assertEquals(400L, array.getLong(0));
+ assertEquals(95L, array.getLong(1));
+ }
+
+ @Test
+ void getJSONArrayWhenNotAnArrayAtIndexIsException() {
+ JSONArray array = new JSONArray("fred", "barney");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ array.getJSONArray(1);
+ });
+
+ assertEquals("JSONArray[1] is not a ARRAY. Actual: java.lang.String", e.getMessage());
+ }
+
+ @Test
+ void getANestedArray() {
+ JSONArray nested = new JSONArray();
+ JSONArray outer = new JSONArray(nested);
+
+ assertSame(nested, outer.getJSONArray(0));
+ }
+
+ @Test
+ void getJSONObjectWhenNotAJSONObjectAtIndexIsAnException() {
+ JSONArray array = new JSONArray("fred", "barney", "wilma");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ array.getJSONObject(1);
+ });
+
+ assertEquals("JSONArray[1] is not a OBJECT. Actual: java.lang.String", e.getMessage());
+ }
+
+ @Test
+ void mayNotPutAtANegativeIndex() {
+ JSONArray array = new JSONArray();
+
+ JSONArrayIndexOutOfBoundsException e = assertThrows(JSONArrayIndexOutOfBoundsException.class, () -> {
+ array.put(-2, "fred");
+ });
+
+ assertEquals(-2, e.getIndex());
+ }
+
+ @Test
+ void putOverridesExistingValueInArray() {
+ JSONArray array = new JSONArray("fred", "barney", "wilma");
+ array.put(2, "betty");
+ assertEquals("betty", array.get(2));
+ }
+
+ @Test
+ void putWithIndexPastEndPadsArrayWithNulls() {
+ JSONArray array = new JSONArray("fred", "barney", "wilma");
+ array.put(4, "bambam");
+
+ assertTrue(array.isNull(3));
+ assertEquals("[\"fred\",\"barney\",\"wilma\",null,\"bambam\"]", array.toCompactString());
+ }
+
+ @Test
+ void arrayEquality() {
+ JSONArray array1 = new JSONArray(1, 2, 3);
+ JSONArray array2 = new JSONArray(1, 2, 3);
+
+ assertEquals(array1, array1);
+ assertNotEquals(null, array1);
+ assertNotEquals(this, array1);
+ assertEquals(array1, array2);
+
+ array2.put(9, "stuff");
+ assertNotEquals(array1, array2);
+ }
+
+ @Test
+ void arrayHashCode() {
+ JSONArray array1 = new JSONArray(1, 2, 3);
+ JSONArray array2 = new JSONArray(1, 2, 3);
+
+ assertEquals(array1.hashCode(), array2.hashCode());
+
+ array2.put(9, "stuff");
+ assertNotEquals(array1.hashCode(), array2.hashCode());
+ }
+
+ @Test
+ void prettyPrint() {
+ JSONArray array = new JSONArray("fred", "barney");
+ String expected = "[\n \"fred\",\n \"barney\"\n]";
+
+ assertEquals(expected, array.toString());
+ }
+
+ @Test
+ void JSONArrayIsIterable() {
+ JSONArray array = new JSONArray(1, 2, false);
+ Iterator<?> i = array.iterator();
+
+ assertEquals(1, i.next());
+ assertEquals(2, i.next());
+ assertEquals(false, i.next());
+ assertFalse(i.hasNext());
+ }
+
+ @Test
+ void removeAnElementByIndex() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ array.remove(1);
+
+ assertEquals(2, array.size());
+ assertEquals("[\"one\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void removeAnElementByValue() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.remove("one");
+
+ assertTrue(result);
+ assertEquals(2, array.size());
+ assertEquals("[\"two\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void removeAnElementByValueNotFound() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.remove("four");
+
+ assertFalse(result);
+ assertEquals(3, array.size());
+ assertEquals("[\"one\",\"two\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void removeAllElementsByCollection() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.removeAll(Arrays.asList("one", "three"));
+
+ assertTrue(result);
+ assertEquals(1, array.size());
+ assertEquals("[\"two\"]", array.toCompactString());
+ }
+
+ @Test
+ void removeAllElementsByCollectionPartial() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.removeAll(Arrays.asList("one", "four"));
+
+ assertTrue(result);
+ assertEquals(2, array.size());
+ assertEquals("[\"two\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void removeAllElementsByCollectionNoneFound() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.removeAll(Arrays.asList("four", "five"));
+
+ assertFalse(result);
+ assertEquals(3, array.size());
+ assertEquals("[\"one\",\"two\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void retainAllElementsByCollectionAll() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.retainAll(Arrays.asList("one", "two", "three"));
+
+ assertFalse(result);
+ assertEquals(3, array.size());
+ assertEquals("[\"one\",\"two\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void retainAllElementsByCollectionPartial() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.retainAll(Arrays.asList("one", "three"));
+
+ assertTrue(result);
+ assertEquals(2, array.size());
+ assertEquals("[\"one\",\"three\"]", array.toCompactString());
+ }
+
+ @Test
+ void retainAllElementsByCollectionNone() {
+ JSONArray array = new JSONArray("one", "two", "three");
+ boolean result = array.retainAll(Arrays.asList("four", "five"));
+
+ assertTrue(result);
+ assertTrue(array.isEmpty());
+ assertEquals("[]", array.toCompactString());
+ }
+
+ @Test
+ void putAllAddsNewObjectsToExistingArray() {
+ JSONArray array = new JSONArray(100, 200);
+ array.putAll(Arrays.asList(300, 400, 500));
+
+ assertEquals("[100,200,300,400,500]", array.toCompactString());
+ }
+
+ @Test
+ void putAllWithNullDoesNotModifyTheArray() {
+ JSONArray array = new JSONArray(100, 200);
+ array.putAll(null);
+
+ assertEquals("[100,200]", array.toCompactString());
+ }
+
+ @Test
+ void addAllAddsNewObjectsToExistingArray() {
+ JSONArray array = new JSONArray(100, 200);
+ array.addAll(Arrays.asList(300, 400, 500));
+
+ assertEquals("[100,200,300,400,500]", array.toCompactString());
+ }
+
+ @Test
+ void addAllReturnsTrueIfChanged() {
+ JSONArray array = new JSONArray(100, 200);
+ boolean result = array.addAll(Arrays.asList(300, 400, 500));
+
+ assertTrue(result);
+ }
+
+ @Test
+ void addAllReturnsFalseIfNotChanged() {
+ JSONArray array = new JSONArray(100, 200);
+ boolean result = array.addAll((Collection<?>) null);
+
+ assertFalse(result);
+ }
+
+ @Test
+ void listReturnedByToListIsUnmodifiable() {
+ JSONArray array = new JSONArray(100, 200);
+ List<?> list = array.toList();
+
+ assertThrows(UnsupportedOperationException.class, list::clear);
+ }
+
+ @Test
+ void listFromToListIsLive() {
+ JSONArray array = new JSONArray(100, 200);
+ List<?> list = array.toList();
+
+ assertEquals(Arrays.asList(100, 200), list);
+
+ array.remove(0);
+
+ assertEquals(Arrays.asList(200), list);
+ }
+
+ @Test
+ void canInitializeJSONArrayFromAnIterable() {
+ JSONArray list = JSONArray.from(Arrays.asList(1, 2, 3));
+
+ assertEquals("[1,2,3]", list.toString(true));
+ }
+
+ @Test
+ void putShouldThrowAnIllegalArgumentExceptionWhenReceivingNull() {
+ JSONArray array = new JSONArray();
+
+ assertThrows(IllegalArgumentException.class, () -> array.put(null));
+ }
+
+ @Test
+ void newJSONArrayShouldThrowAnIllegalArgumentExceptionWhenReceivingNull() {
+ assertThrows(IllegalArgumentException.class, () -> new JSONArray(1, null, 3));
+ }
+
+ static Stream<Object> validTypesProvider() {
+ return Stream.of(
+ Arguments.of(true),
+ Arguments.of(3),
+ Arguments.of(3.5),
+ Arguments.of("*VALUE*"),
+ Arguments.of(new JSONLiteral("*LITERAL*")),
+ Arguments.of(new JSONObject()),
+ Arguments.of(new JSONArray())
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("validTypesProvider")
+ void onlySpecificObjectTypesMayBeAddedNoException(Object value) {
+ JSONArray array = new JSONArray();
+
+ assertDoesNotThrow(() -> array.put(value));
+ }
+
+ static Stream<Arguments> invalidTypesProvider() {
+ return Stream.of(
+ Arguments.of(new java.util.Date()),
+ Arguments.of((Object) new Object[] {}),
+ Arguments.of(Collections.emptyMap())
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("invalidTypesProvider")
+ void onlySpecificObjectTypesMayBeAddedException(Object value) {
+ JSONArray array = new JSONArray();
+
+ assertThrows(JSONInvalidTypeException.class, () -> array.put(value));
+ }
+
+ @Test
+ void arrayIndexOutOfBoundsMustThrowInformativeException() {
+ JSONArray array = new JSONArray(1, 2, 3);
+ JSONArrayIndexOutOfBoundsException e = assertThrows(JSONArrayIndexOutOfBoundsException.class, () -> {
+ array.get(array.size());
+ });
+
+ assertEquals(3, e.getIndex());
+ }
+
+ static Stream<Arguments> nonFiniteDoubleProvider() {
+ return Stream.of(
+ Arguments.of(Double.POSITIVE_INFINITY),
+ Arguments.of(Double.NEGATIVE_INFINITY),
+ Arguments.of(Double.NaN)
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("nonFiniteDoubleProvider")
+ void nonFiniteOrNaNDoubleNotAllowedInConstructor(Double value) {
+ assertThrows(IllegalArgumentException.class, () -> new JSONArray(value));
+ }
+}
\ No newline at end of file
diff --git a/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONCollectorsTest.java b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONCollectorsTest.java
new file mode 100644
index 000000000..419611d8a
--- /dev/null
+++ b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONCollectorsTest.java
@@ -0,0 +1,97 @@
+// Copyright 2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.json;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.stream.Stream;
+
+import org.apache.tapestry5.func.Tuple;
+import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException;
+import org.junit.jupiter.api.Test;
+
+public class JSONCollectorsTest {
+
+ @Test
+ void collectStreamToArray() {
+
+ String stringValue = "a string value";
+ long longValue = 3L;
+ Stream<Object> stream = Stream.of(stringValue, longValue);
+
+ JSONArray collected = stream.collect(JSONCollectors.toArray());
+
+ assertNotNull(collected);
+ assertEquals(2, collected.size());
+ assertEquals(stringValue, collected.get(0));
+ assertEquals(longValue, collected.get(1));
+ }
+
+ @Test
+ void collectStreamToArrayInvalidType() {
+
+ String stringValue = "a string value";
+ long longValue = 3L;
+ Object invalidValue = new java.util.Date();
+
+ Stream<Object> stream = Stream.of(stringValue, longValue, invalidValue);
+
+ assertThrows(JSONInvalidTypeException.class, () -> {
+ stream.collect(JSONCollectors.toArray());
+ });
+ }
+
+ @Test
+ void collectStreamToMap() {
+
+ Tuple<String, Object> first = new Tuple<>("first key", "a string value");
+ Tuple<String, Object> second = new Tuple<>("second key", 3L);
+
+ Stream<Tuple<String, Object>> stream = Stream.of(first, second);
+
+ JSONObject collected = stream
+ .collect(JSONCollectors.toMap(t -> t.first, t -> t.second));
+
+ assertNotNull(collected);
+ assertEquals(2, collected.size());
+ assertEquals(first.second, collected.get(first.first));
+ assertEquals(second.second, collected.get(second.first));
+ }
+
+ @Test
+ @SuppressWarnings({ "unchecked", "rawtypes" }) // Suppress warnings for Tuple generic types
+ void collectStreamToMapInvalidType() {
+
+ Tuple<String, Object> first = new Tuple<>("first key", "a string value");
+ Tuple<String, Object> second = new Tuple<>("second key", 3L);
+ Tuple<String, Object> third = new Tuple<>("invalid type", new java.util.Date());
+
+ Stream<Tuple<String, Object>> stream = Stream.of(first, second, third);
+
+ assertThrows(JSONInvalidTypeException.class, () -> {
+ stream.collect(JSONCollectors.toMap(t -> t.first, t -> t.second));
+ });
+ }
+
+ @Test
+ void collectStreamToMapDuplicateKey() {
+
+ assertThrows(IllegalStateException.class, () -> {
+ Stream.of("first", "second", "first").collect(JSONCollectors.toMap(v -> v, v -> v));
+ });
+ }
+}
\ No newline at end of file
diff --git a/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONObjectTest.java b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONObjectTest.java
new file mode 100644
index 000000000..0b4167a80
--- /dev/null
+++ b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONObjectTest.java
@@ -0,0 +1,891 @@
+// Copyright 2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.json;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException;
+import org.apache.tapestry5.json.exceptions.JSONSyntaxException;
+import org.apache.tapestry5.json.exceptions.JSONTypeMismatchException;
+import org.apache.tapestry5.json.exceptions.JSONValueNotFoundException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class JSONObjectTest {
+
+ @Test
+ void copyAnExistingJSONObject() {
+
+ JSONObject master = new JSONObject("fred", "flintstone", "barney", "rubble");
+
+ JSONObject emptyCopy = new JSONObject(master);
+
+ assertTrue(emptyCopy.keys().isEmpty());
+
+ JSONObject limitedCopy = new JSONObject(master, "fred");
+
+ assertEquals(1, limitedCopy.keys().size());
+ assertEquals("flintstone", limitedCopy.get("fred"));
+
+ JSONObject fullCopy = new JSONObject(master, "fred", "barney");
+
+ assertEquals("{\"fred\":\"flintstone\",\"barney\":\"rubble\"}", fullCopy.toCompactString());
+ }
+
+ @Test
+ void copyAllPropertiesOfJSONObject() {
+
+ JSONObject master = new JSONObject("fred", "flintstone", "barney", "rubble");
+
+ JSONObject fullCopy = master.copy();
+
+ assertEquals(master, fullCopy);
+
+ master.put("wilma", "flintstone");
+
+ assertNotEquals(master, fullCopy);
+ }
+
+ @Test
+ void unknownKeysWhenCopyingAJSONObjectAreIgnored() {
+
+ JSONObject master = new JSONObject("fred", "flintstone", "barney", "rubble");
+
+ JSONObject copy = new JSONObject(master, "fred", "wilma");
+
+ assertEquals(1, copy.keys().size());
+ assertEquals("flintstone", copy.get("fred"));
+ }
+
+ @Test
+ void getWithUnknownKeyIsAnException() {
+
+ JSONObject master = new JSONObject("fred", "flintstone");
+
+ JSONValueNotFoundException e = assertThrows(JSONValueNotFoundException.class, () -> {
+ master.get("barney");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"barney\"] is not found."));
+ assertTrue(e.getMessage().contains("Required: ANY"));
+ }
+
+ @Test
+ void getOrDefaultReturnsDefaultValueIfNotFound() {
+
+ JSONObject master = new JSONObject("fred", "flintstone");
+
+ Object result = master.getOrDefault("barney", "gumble");
+
+ assertEquals("gumble", result);
+ }
+
+ @Test
+ void getOrDefaultReturnsValueIfFound() {
+
+ JSONObject master = new JSONObject("fred", "flintstone");
+
+ Object result = master.getOrDefault("fred", "other");
+
+ assertEquals("flintstone", result);
+ }
+
+ // Data provider for ensureThatStoredValueIsExpected
+ static Stream<Arguments> storedValueProvider() {
+ return Stream.of(
+ Arguments.of("true", true, "Boolean"),
+ Arguments.of("TRUE", true, "Boolean"),
+ Arguments.of("false", false, "Boolean"),
+ Arguments.of("FALSE", false, "Boolean"),
+ Arguments.of(Boolean.TRUE, true, "Boolean"),
+ Arguments.of(Boolean.FALSE, false, "Boolean"),
+ Arguments.of(3.5d, 3.5d, "Double"),
+ Arguments.of(1_000L, 1_000d, "Double"),
+ Arguments.of("-101.7", -101.7d, "Double"),
+ Arguments.of("3", 3, "Int"),
+ Arguments.of(97L, 97, "Int"),
+ Arguments.of("-8.76", -8, "Int"),
+ Arguments.of(92d, 92L, "Long"),
+ Arguments.of("-200", -200L, "Long"),
+ Arguments.of(123, "123", "String")
+ );
+ }
+
+ @ParameterizedTest(name = "ensure that stored value {0} ({argumentsWithNames}) is {2} {1}")
+ @MethodSource("storedValueProvider")
+ void ensureThatStoredValueIsExpected(Object value, Object expected, String expectedType) {
+
+ JSONObject object = new JSONObject().put("key", value);
+ Function<String, Object> fn;
+ switch (expectedType) {
+ case "Boolean":
+ fn = object::getBoolean;
+ break;
+ case "Double":
+ fn = object::getDouble;
+ break;
+ case "Int":
+ fn = object::getInt;
+ break;
+ case "Long":
+ fn = object::getLong;
+ break;
+ case "String":
+ fn = object::getString;
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown expected type: " + expectedType);
+ }
+
+ Object result = fn.apply("key");
+
+ assertEquals(expected, result);
+ }
+
+
+ static Stream<Arguments> doubleToStringProvider() {
+ return Stream.of(
+ Arguments.of(3d, "3"),
+ Arguments.of(-22.5d, "-22.5"),
+ Arguments.of(0d, "0"),
+ Arguments.of(Double.NaN, "null"),
+ Arguments.of(Double.NEGATIVE_INFINITY, "null"),
+ Arguments.of(Double.POSITIVE_INFINITY, "null")
+ );
+ }
+
+ @ParameterizedTest(name = "conversion of double {0} to string should be ''{1}''")
+ @MethodSource("doubleToStringProvider")
+ void doubleToStringConversion(double input, String expected) {
+
+ assertEquals(expected, JSONObject.doubleToString(input));
+ }
+
+ @Test
+ void exceptionWhenGetBooleanOnAValueThatIsNotABoolean() {
+
+ JSONObject object = new JSONObject().put("key", 37);
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ object.getBoolean("key");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"key\"] is not a BOOLEAN."));
+ }
+
+ @Test
+ void accumulateSimpleValues() {
+
+ JSONObject object = new JSONObject();
+ String key = "acckey";
+
+ object.accumulate(key, "alpha");
+
+ assertEquals("{\"acckey\":\"alpha\"}", object.toCompactString());
+
+ object.accumulate(key, "beta");
+ object.accumulate(key, "gamma");
+
+ assertEquals("{\"acckey\":[\"alpha\",\"beta\",\"gamma\"]}", object.toCompactString());
+ assertEquals(3, object.getJSONArray(key).size());
+ }
+
+ @Test
+ void accumulateWhenTheStoredValueIsAlreadyAnArrayJustAppendsTheValue() {
+
+ JSONObject object = new JSONObject();
+
+ object.accumulate("key", new JSONArray("fred", "barney"));
+
+ assertEquals("{\"key\":[\"fred\",\"barney\"]}", object.toCompactString());
+
+ object.accumulate("key", "wilma");
+
+ assertEquals("{\"key\":[\"fred\",\"barney\",\"wilma\"]}", object.toCompactString());
+ }
+
+ @Test
+ void canCreateAJSONObjectFromAJSONString() {
+
+ JSONObject object = new JSONObject("{ fred: \"flintstone\", caveman: true, friends: [\"barney\"] }");
+
+ assertEquals("flintstone", object.get("fred"));
+ assertTrue(object.getBoolean("caveman"));
+
+ JSONArray friends = object.getJSONArray("friends");
+
+ assertEquals(1, friends.size());
+ assertEquals("barney", friends.get(0));
+ }
+
+ @Test
+ void appendToAnUnknownKeyCreatesAJSONArrayForTheValue() {
+
+ JSONObject object = new JSONObject();
+
+ object.append("friends", "barney");
+
+ assertEquals("{\"friends\":[\"barney\"]}", object.toCompactString());
+ }
+
+ @Test
+ void appendToAnExistingKeyContainingAJSONArrayAppendsToTheArray() {
+
+ JSONObject object = new JSONObject("{friends: [\"barney\"] }");
+
+ object.append("friends", "zaphod");
+
+ assertEquals("{\"friends\":[\"barney\",\"zaphod\"]}", object.toCompactString());
+ }
+
+ @Test
+ void appendingToAKeyWhoseValueIsNotAArrayIsAnException() {
+
+ JSONObject object = new JSONObject("{friends: 0 }");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ object.append("friends", "zaphod");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"friends\"] is not a ARRAY."));
+ }
+
+ @Test
+ void getDoubleWithANonNumericValueIsAnException() {
+
+ JSONObject object = new JSONObject("{notdouble: true}");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ object.getDouble("notdouble");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"notdouble\"] is not a NUMBER."));
+ }
+
+ @Test
+ void getDoubleWithAStringThatCanNotBeParsedAsANumberIsAnException() {
+
+ JSONObject object = new JSONObject("{notdouble: \"this is a fact\"}");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ object.getDouble("notdouble");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"notdouble\"] is not a NUMBER."));
+ }
+
+ @Test
+ void hasWillIdentifyWhichKeysHaveValuesAndWhichDoNot() {
+
+ JSONObject object = new JSONObject("{fred: 'flintstone'}");
+
+ assertTrue(object.has("fred"));
+ assertFalse(object.has("barney"));
+ }
+
+ @Test
+ void getJSONArrayForAValueThatIsNotAArrayIsAnException() {
+
+ JSONObject object = new JSONObject("{notarray: 22.7}");
+
+ JSONTypeMismatchException e = assertThrows(JSONTypeMismatchException.class, () -> {
+ object.getJSONArray("notarray");
+ });
+
+ assertTrue(e.getMessage().startsWith("JSONObject[\"notarray\"] is not a ARRAY."));
+ }
+
+ @Test
+ void lengthOfAJSONObjectIsTheNumberOfKeys() {
+
+ JSONObject object = new JSONObject();
+
+ assertEquals(0, object.size());
+
+ object.put("fred", "flintstone");
+
+ assertEquals(1, object.size());
+
+ object.accumulate("fred", "murray");
+
+ assertEquals(1, object.size());
+
+ object.put("barney", "rubble");
+
+ assertEquals(2, object.size());
+ }
+
+ @Test
+ void namesReturnsTheKeysAsAJSONArray() {
+
+ JSONObject object = new JSONObject("{fred: 'flintstone', barney: 'rubble' }");
+
+ JSONArray names = object.names();
+
+ assertNotNull(names);
+ assertTrue(names instanceof JSONArray);
+ assertEquals(2, names.size());
+
+ List<Object> nameList = new ArrayList<>(names.toList());
+ Collections.sort(nameList, (o1, o2) -> ((String) o1).compareTo((String) o2));
+
+ assertEquals(Arrays.asList("barney", "fred"), nameList);
+ }
+
+ @Test
+ void namesWithNoPropertiesReturnsNull() {
+
+ JSONObject object = new JSONObject();
+
+ assertNull(object.names());
+ }
+
+ @Test
+ void theNullLiteralIsTheNULLObject() {
+
+ JSONObject object = new JSONObject("{nullkey: null}");
+
+ assertSame(JSONObject.NULL, object.get("nullkey"));
+ assertTrue(object.isNull("nullkey"));
+ }
+
+ @Test
+ void theNULLObjectIsOutputAsNullLiteral() {
+
+ JSONObject object = new JSONObject().put("nullkey", JSONObject.NULL);
+
+ assertTrue(object.isNull("nullkey"));
+ assertEquals("{\"nullkey\":null}", object.toCompactString());
+ }
+
+ @Test
+ void theNULLObjectMatchesJavasNull() {
+
+ assertTrue(JSONObject.NULL.equals(null));
+ }
+
+ static Stream<Arguments> invalidInputProvider() {
+ return Stream.of(
+ Arguments.of("{ ", "A JSONObject text must end with '}' at character 3", "unmatched open brace"),
+ Arguments.of("fred", "A JSONObject text must start with '{' (actual: 'f') at character 1 of", "missing open brace"),
+ Arguments.of("{ \"akey\" }", "Expected a ':' after a key at character 10 of", "missing value after key"),
+ Arguments.of("{ \"fred\" : 1 \"barney\" }", "Expected a ',' or '}' at character 14 of", "missing property separator"),
+ Arguments.of("{ \"list\" : [1, 2", "Expected a ',' or ']' at character 16 of", "missing seperator or closing bracket"),
+ Arguments.of("/* unclosed", "Unclosed comment at character 11 of", "unclosed C-style comment"),
+ Arguments.of("{ \"fred \\n}", "Unterminated string at character 11 of", "unterminated string at line end"),
+ Arguments.of("{ fred: ,}", "Missing value at character 8 of ", "missing value after key")
+ );
+ }
+
+ @ParameterizedTest(name = "invalid input ({2}) throws exception")
+ @MethodSource("invalidInputProvider")
+ void invalidInputThrowsException(String input, String expected, String desc) {
+ // When/Then
+ JSONSyntaxException e = assertThrows(JSONSyntaxException.class, () -> {
+ new JSONObject(input);
+ });
+
+ assertTrue(e.getMessage().trim().startsWith(expected),
+ "Expected message to start with: " + expected + ", but was: " + e.getMessage().trim());
+ }
+
+
+ @Test
+ void canUseColonOrArrowAsKeySeperatorAndSemicolonAsPropertySeparator() {
+ JSONObject object = new JSONObject("{ \"fred\" = 1; \"barney\" => 2}");
+
+ assertEquals(1, object.getInt("fred"));
+ assertEquals(2, object.getInt("barney"));
+ }
+
+ static Stream<Arguments> numberToStringConversionProvider() {
+ return Stream.of(
+ Arguments.of(new BigDecimal("100.0000000"), "100")
+ );
+ }
+
+ @ParameterizedTest(name = "conversion of {0} ({argumentsWithNames}) to string is {1}")
+ @MethodSource("numberToStringConversionProvider")
+ void numberToStringConversion(Number value, String expected) {
+
+ assertEquals(expected, JSONObject.numberToString(value));
+ }
+
+ static Stream<Arguments> quoteProvider() {
+ return Stream.of(
+ Arguments.of(null, "\"\"", "null is empty string"),
+ Arguments.of("", "\"\"", "empty string is empty string"),
+ Arguments.of("\"/\b\t\n\f\r\u2001/a</", "\"\\\"/\\b\\t\\n\\f\\r\\u2001/a<\\/\"", "special characters")
+ );
+ }
+
+ @ParameterizedTest(name = "quote(): {2}")
+ @MethodSource("quoteProvider")
+ void quoteTest(String value, String expected, String desc) {
+
+ assertEquals(expected, JSONObject.quote(value));
+ }
+
+ static Stream<Arguments> nonFiniteNumbersProvider() {
+ return Stream.of(
+ Arguments.of(Double.NaN),
+ Arguments.of(Double.NEGATIVE_INFINITY),
+ Arguments.of(Double.POSITIVE_INFINITY),
+ Arguments.of(Float.NaN),
+ Arguments.of(Float.NEGATIVE_INFINITY),
+ Arguments.of(Float.POSITIVE_INFINITY)
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("nonFiniteNumbersProvider")
+ void nonFiniteNumbersAreNotAllowed(Number value) {
+
+ JSONObject object = new JSONObject();
+
+ RuntimeException e = assertThrows(IllegalArgumentException.class, () -> {
+ object.put("nonfinite", value);
+ });
+
+ assertEquals("JSON does not allow non-finite numbers.", e.getMessage());
+ }
+
+ @Test
+ void parseAnEmptyObjectIsEmpty() {
+ JSONObject object = new JSONObject("{}");
+ assertEquals(0, object.size());
+ }
+
+ @Test
+ void putAJavaNullIsARemove() {
+
+ JSONObject object = new JSONObject("{fred:'flintstone', barney:'rubble'}");
+
+ object.put("fred", null);
+
+ assertEquals("{\"barney\":\"rubble\"}", object.toCompactString());
+ }
+
+ static Stream<Arguments> validTypesForPutProvider() {
+ return Stream.of(
+ Arguments.of((Object) null),
+ Arguments.of(true),
+ Arguments.of(3),
+ Arguments.of(3.5),
+ Arguments.of("*VALUE*"),
+ Arguments.of(new JSONLiteral("*LITERAL*")),
+ Arguments.of(new JSONObject()),
+ Arguments.of(new JSONArray())
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("validTypesForPutProvider")
+ void onlySpecificObjectTypesMayBeAddedNoException(Object value) {
+
+ JSONObject object = new JSONObject("{}");
+
+ assertDoesNotThrow(() -> object.put("key", value));
+ }
+
+
+ static Stream<Arguments> invalidTypesForPutProvider() {
+ return Stream.of(
+ Arguments.of(new java.util.Date()),
+ Arguments.of((Object) new Object[] {}),
+ Arguments.of(Collections.emptyMap())
+ );
+ }
+ @ParameterizedTest
+ @MethodSource("invalidTypesForPutProvider")
+ void onlySpecificObjectTypesMayBeAddedException(Object value) {
+
+ JSONObject object = new JSONObject("{}");
+
+ assertThrows(JSONInvalidTypeException.class, () -> object.put("key", value));
+ }
+
+ @Test
+ void JSONStringCanOutputAnythingItWants() {
+ JSONString string = () -> "*VALUE*";
+ JSONObject object = new JSONObject();
+
+ object.put("key", string);
+
+ assertEquals("{\"key\":*VALUE*}", object.toCompactString());
+ }
+
+ @Test
+ void equalsImplementation() {
+ String jsonStr = "{ \"key\" : 99 }";
+ JSONObject obj1 = new JSONObject(jsonStr);
+ JSONObject obj2 = new JSONObject(jsonStr);
+
+ assertEquals(obj1, obj2);
+ assertEquals(obj2, obj1);
+ assertNotEquals(null, obj1);
+ assertNotEquals(jsonStr, obj1);
+
+ obj2.put("screw", "the pooch");
+
+ assertNotEquals(obj1, obj2);
+ }
+
+ @Test
+ void hashCodeImplementation() {
+
+ String jsonStr = "{ \"key\" : 99 }";
+ JSONObject obj1 = new JSONObject(jsonStr);
+ JSONObject obj2 = new JSONObject(jsonStr);
+
+ assertEquals(obj1.hashCode(), obj2.hashCode());
+
+ obj2.put("screw", "the pooch");
+
+ assertNotEquals(obj1.hashCode(), obj2.hashCode());
+ }
+
+ @Test
+ void escapedCharactersInTheJSONAreParsedCorrectly() {
+
+ JSONObject object = new JSONObject("{ \"key\" : \"\\\"/\\b\\t\\n\\f\\r\\u2001/a<\\/\\x20\" }");
+
+ assertEquals("\"/\b\t\n\f\r\u2001/a</ ", object.get("key"));
+ }
+
+ @Test
+ void parseANestedObject() {
+
+ JSONObject object = new JSONObject("{ key: { name: \"inner\" }}");
+
+ assertEquals("inner", object.getJSONObject("key").getString("name"));
+ }
+
+ @Test
+ void parseBooleanLiterals() {
+
+ JSONObject object = new JSONObject("{ t: true, f: false }");
+
+ assertTrue(object.getBoolean("t"));
+ assertFalse(object.getBoolean("f"));
+ }
+
+ @Test
+ void parseNumericForms() {
+
+ JSONObject object = new JSONObject("{ hex: 0x50, oct: 030, posInt: +50, negInt: -50, long: 4294968530, float: -32.7 }");
+
+ assertEquals(80, object.getInt("hex"));
+ assertEquals(24, object.getInt("oct"));
+ assertEquals(50, object.getInt("posInt"));
+ assertEquals(-50, object.getInt("negInt"));
+ assertEquals(4294968530L, object.getLong("long"));
+ assertEquals(-32.7d, object.getDouble("float"));
+ }
+
+ @Test
+ void NULLToStringIsNullKeyword() {
+
+ assertEquals("null", JSONObject.NULL.toString());
+ }
+
+ @Test
+ void JSONLiteralCanOutputAnyContent() {
+
+ String text = "function(x) { $('bar').show(); }";
+ JSONLiteral literal = new JSONLiteral(text);
+ JSONObject object = new JSONObject().put("callback", literal);
+
+ assertEquals("{\"callback\":" + text + "}", object.toCompactString());
+ assertEquals(text, literal.toString());
+ }
+
+ @Test
+ void prettyPrintTest() {
+
+ JSONObject object = new JSONObject("fred", "flintstone", "barney", "rubble");
+ String expected = "{\n \"fred\" : \"flintstone\",\n \"barney\" : \"rubble\"\n}";
+
+ assertEquals(expected.trim(), object.toString().trim());
+ }
+
+ @Test
+ void cStyleCommentsAreIgnored() {
+
+ JSONObject object = new JSONObject("/* C comment */ { \"foo\" : \"bar\" /* *ignored* */ }");
+
+ assertEquals("bar", object.get("foo"));
+ }
+
+ @Test
+ void doubleSlashCommentsExtendToEndOfLine() {
+
+ JSONObject object = new JSONObject("{ foo: // This is a double-slash comment\n\"bar\" }");
+
+ assertEquals("bar", object.get("foo"));
+ }
+
+ @Test
+ void hashCommentsExtendToEndOfLine() {
+
+ JSONObject object = new JSONObject("{ foo: # This is a hash comment\n\"bar\" }");
+
+ assertEquals("bar", object.get("foo"));
+ }
+
+ @Test
+ void prettyPrintAnEmptyJSONObject() {
+
+ JSONObject object = new JSONObject();
+
+ assertEquals("{}", object.toString());
+ }
+
+ @Test
+ void complexPrettyPrint() {
+ JSONObject object = new JSONObject(
+ "{ outer: { inner: \"here\" },\n" +
+ " number: 22.7,\n" +
+ " array: [1, 2, 3],\n" +
+ " boolean: true,\n" +
+ " otherwise: 'a quoted string'\n" +
+ "}"
+ );
+ String expected = "{\n" +
+ " \"outer\" : {\n" +
+ " \"inner\" : \"here\"\n" +
+ " },\n" +
+ " \"number\" : 22.7,\n" +
+ " \"array\" : [\n" +
+ " 1,\n" +
+ " 2,\n" +
+ " 3\n" +
+ " ],\n" +
+ " \"boolean\" : true,\n" +
+ " \"otherwise\" : \"a quoted string\"\n" +
+ "}";
+ assertEquals(expected.trim(), object.toString().trim());
+ }
+
+
+ @Test
+ void toCompactStringTest() {
+
+ JSONObject object = new JSONObject("kermit", "frog");
+
+ assertEquals("{\"kermit\":\"frog\"}", object.toString(true));
+ assertEquals("{\n \"kermit\" : \"frog\"\n}", object.toString(false).replace("\r\n", "\n"));
+ }
+
+ private static String withPrintWriter(Consumer<PrintWriter> closure) {
+
+ CharArrayWriter caw = new CharArrayWriter();
+ try (PrintWriter pw = new PrintWriter(caw)) {
+ closure.accept(pw);
+ }
+
+ return caw.toString();
+ }
+
+ private static String print(JSONObject object, boolean compact) {
+ return withPrintWriter(pw -> object.print(pw, compact));
+ }
+
+ @Test
+ void printToPrintWriterTest() {
+
+ JSONObject object = new JSONObject("kermit", "frog");
+
+ assertEquals("{\"kermit\":\"frog\"}", print(object, true));
+ assertEquals("{\n \"kermit\" : \"frog\"\n}", print(object, false).replace("\r\n", "\n"));
+ }
+
+
+ @Test
+ void prettyPrintToPrintWriter() {
+
+ JSONObject object = new JSONObject("kermit", "frog");
+
+ String json = withPrintWriter(pw -> object.prettyPrint(pw));
+ assertEquals("{\n \"kermit\" : \"frog\"\n}", json.replace("\r\n", "\n"));
+ }
+
+ @Test
+ void getStringAtIndex() {
+
+ JSONArray array = new JSONArray("one", 2, false);
+
+ assertEquals("one", array.getString(0));
+ assertEquals("2", array.getString(1));
+ assertEquals("false", array.getString(2));
+ }
+
+ @Test
+ void toMapIsNotModifiable() {
+
+ JSONObject object = new JSONObject();
+ Map<String, Object> map = object.toMap();
+
+ assertThrows(UnsupportedOperationException.class, map::clear);
+ }
+
+ @Test
+ void canAccessContentsOfObjectAsAMap() {
+
+ JSONObject object = new JSONObject("foo", "bar")
+ .put("null", JSONObject.NULL)
+ .put("number", 6);
+ Map<String, Object> map = object.toMap();
+
+ assertEquals("bar", map.get("foo"));
+ assertEquals(6, map.get("number"));
+ assertSame(JSONObject.NULL, map.get("null"));
+ }
+
+ @Test
+ void theMapReturnedByToMapIsLive() {
+
+ JSONObject object = new JSONObject("foo", "bar");
+ Map<String, Object> map = object.toMap();
+
+ object.put("foo", null);
+
+ assertEquals(0, object.size());
+ assertTrue(map.isEmpty());
+ }
+
+ @Test
+ void canAddNewPropertiesViaPutAll() {
+
+ JSONObject object = new JSONObject("fred", "flintstone");
+ Map<String, Object> newProps = new HashMap<>();
+ newProps.put("barney", "rubble");
+ newProps.put("wilma", "flintstone");
+
+ object.putAll(newProps);
+
+ assertTrue(object.keySet().containsAll(Arrays.asList("fred", "barney", "wilma")));
+ assertEquals(
+ Stream.of("flintstone", "rubble", "flintstone").sorted().collect(Collectors.toList()),
+ object.values().stream().sorted().collect(Collectors.toList())
+ );
+ }
+
+ @Test
+ void inWhereTheValueIsNotJSONObjectIsAnException() {
+
+ JSONObject object = new JSONObject("time", "to rock");
+
+ IllegalStateException e = assertThrows(IllegalStateException.class, () -> {
+ object.in("time");
+ });
+
+ assertEquals("JSONObject[\"time\"] is not a JSONObject.", e.getMessage());
+ }
+
+ @Test
+ void inCreatesAJSONObjectIfNecessary() {
+
+ JSONObject object = new JSONObject();
+
+ object.in("nested").put("created", true);
+
+ assertEquals("{\"nested\":{\"created\":true}}", object.toCompactString());
+ }
+
+ @Test
+ void inReturnsTheJSONObject() {
+
+ JSONObject object = new JSONObject("{nested: {}}");
+
+ object.in("nested").put("time", "to rock");
+
+ assertEquals("{\"nested\":{\"time\":\"to rock\"}}", object.toCompactString());
+ }
+
+ @Test
+ void constructorSupportsNonStringKeysAndValues() {
+
+ JSONObject object = new JSONObject(true, "truthy", false, false);
+
+ assertTrue(object.containsKey("true")); // Keys are stringified
+ assertEquals("truthy", object.getString("true"));
+ assertTrue(object.containsKey("false"));
+ assertEquals(false, object.get("false"));
+ }
+
+
+ private static Object copyViaSerialization(Object source) throws IOException, ClassNotFoundException {
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(source);
+ }
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ try (ObjectInputStream ois = new ObjectInputStream(bis)) {
+ return ois.readObject();
+ }
+ }
+
+ @Test
+ void serializeAndDeSerialize() throws IOException, ClassNotFoundException {
+
+ JSONObject source = new JSONObject("string", "a string", "null", JSONObject.NULL);
+
+ JSONObject copy = (JSONObject) copyViaSerialization(source);
+
+ assertEquals(source, copy);
+ }
+
+ // TAP5-2759
+ @Test
+ void getLongOrDefaultCorrectTypeForDefaultValue() {
+ JSONObject object = new JSONObject();
+ long defaultValue = 2_147_483_648L; // This is Integer.MAX_VALUE + 1, so it's a long
+ long value = object.getLongOrDefault("key", defaultValue);
+
+ assertEquals(defaultValue, value);
+ }
+}
\ No newline at end of file
diff --git a/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONTest.java b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONTest.java
new file mode 100644
index 000000000..0446b942a
--- /dev/null
+++ b/tapestry-json/src/test/java/org/apache/tapestry5/json/JSONTest.java
@@ -0,0 +1,53 @@
+// Copyright 2025 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.json;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.tapestry5.json.exceptions.JSONInvalidTypeException;
+import org.junit.jupiter.api.Test;
+
+public class JSONTest {
+
+ @Test
+ void invalidTypesThrowJSONInvalidTypeException() {
+ Map<String, String> invalidValue = Collections.emptyMap();
+
+ JSONInvalidTypeException e = assertThrows(JSONInvalidTypeException.class, () -> {
+ JSON.testValidity(invalidValue);
+ });
+
+ String expectedMessage = String.format(
+ "JSONArray values / JSONObject properties may be one of Boolean, Number, String, %s, %s, %s, %s, %s. Type %s is not allowed.",
+ "org.apache.tapestry5.json.JSONArray",
+ "org.apache.tapestry5.json.JSONLiteral",
+ "org.apache.tapestry5.json.JSONObject",
+ "org.apache.tapestry5.json.JSONObject$Null",
+ "org.apache.tapestry5.json.JSONString",
+ invalidValue.getClass().getName());
+ assertEquals(expectedMessage, e.getMessage());
+ }
+
+ @Test
+ void nullIsInvalid() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ JSON.testValidity(null);
+ });
+ }
+}
\ No newline at end of file
diff --git a/tapestry-kaptcha/src/test/conf/testng.xml b/tapestry-kaptcha/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-kaptcha/src/test/conf/testng.xml
rename to tapestry-kaptcha/src/test/resources/testng.xml
diff --git a/tapestry-mongodb/src/test/groovy/MongoDBSpec.groovy b/tapestry-mongodb/src/test/groovy/MongoDBSpec.groovy
index 510a2e41e..cbce0dd32 100644
--- a/tapestry-mongodb/src/test/groovy/MongoDBSpec.groovy
+++ b/tapestry-mongodb/src/test/groovy/MongoDBSpec.groovy
@@ -16,9 +16,11 @@ import de.flapdoodle.embed.mongo.config.MongodConfig
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.process.runtime.Network
import spock.lang.AutoCleanup
+import spock.lang.Ignore
import spock.lang.Shared
import spock.lang.Specification
+@Ignore
class MongoDBSpec extends Specification
{
final int total = 1000
diff --git a/tapestry-mongodb/src/test/conf/testng.xml b/tapestry-mongodb/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-mongodb/src/test/conf/testng.xml
rename to tapestry-mongodb/src/test/resources/testng.xml
diff --git a/tapestry-spring/src/test/conf/testng.xml b/tapestry-spring/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-spring/src/test/conf/testng.xml
rename to tapestry-spring/src/test/resources/testng.xml
diff --git a/tapestry-test/src/test/conf/testng.xml b/tapestry-test/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-test/src/test/conf/testng.xml
rename to tapestry-test/src/test/resources/testng.xml
diff --git a/tapestry-upload/src/test/conf/testng.xml b/tapestry-upload/src/test/resources/testng.xml
similarity index 100%
rename from tapestry-upload/src/test/conf/testng.xml
rename to tapestry-upload/src/test/resources/testng.xml
diff --git a/tapestry-webresources/src/test/java/t5/webresources/services/web/WebResourcesTest.java b/tapestry-webresources/src/test/java/t5/webresources/services/web/WebResourcesTest.java
index e39cb9c58..f96f77120 100644
--- a/tapestry-webresources/src/test/java/t5/webresources/services/web/WebResourcesTest.java
+++ b/tapestry-webresources/src/test/java/t5/webresources/services/web/WebResourcesTest.java
@@ -35,6 +35,7 @@ public class WebResourcesTest extends SeleniumTestCase {
public void test_Less_compilation()
{
open("/");
+ waitForInitializedPage();
click("css=.navbar .dropdown-toggle");
click("link=MultiLess");
waitForInitializedPage();
diff --git a/tapestry5-annotations/src/test/conf/testng.xml b/tapestry5-annotations/src/test/conf/testng.xml
deleted file mode 100644
index e7dc420fd..000000000
--- a/tapestry5-annotations/src/test/conf/testng.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
-<!--
- Copyright 2008 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<suite name="Tapestry Annotations" annotations="1.5" verbose="2">
- <!-- This avoids a build error when performing a non-clean build. Just another Maven fuckup to be worked around. -->
- <test name="Placeholder (no tests)"/>
-</suite>