This is an automated email from the ASF dual-hosted git repository. joerghoh pushed a commit to branch SLING-12990 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-settings.git
commit 20ca0f6310cf19c74387413fd2fa3dbbf1406b39 Author: Joerg Hoh <[email protected]> AuthorDate: Mon Nov 3 13:12:18 2025 +0100 SLING-12990 update to bundle parent 62 --- pom.xml | 64 ++++++++++------------ .../sling/settings/impl/RunModeImplTest.java | 37 +++++++------ .../impl/SlingSettingsServiceImplTest.java | 50 ++++++++++++----- 3 files changed, 84 insertions(+), 67 deletions(-) diff --git a/pom.xml b/pom.xml index 3aad2a3..a2cb50d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.sling</groupId> <artifactId>sling-bundle-parent</artifactId> - <version>39</version> + <version>62</version> <relativePath /> </parent> @@ -31,45 +31,22 @@ <version>1.4.3-SNAPSHOT</version> <name>Apache Sling Settings</name> - <description> - Settings support including run modes - </description> + <description>Settings support including run modes</description> <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-settings.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-settings.git</developerConnection> - <url>https://github.com/apache/sling-org-apache-sling-settings.git</url> <tag>HEAD</tag> + <url>https://github.com/apache/sling-org-apache-sling-settings.git</url> </scm> <properties> <site.jira.version.id>12315254</site.jira.version.id> <site.javadoc.exclude>**.impl.**</site.javadoc.exclude> <project.build.outputTimestamp>2020-11-07T11:54:03Z</project.build.outputTimestamp> + <sling.java.version>11</sling.java.version> </properties> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-baseline-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <configuration> - <excludePackageNames> - org.apache.sling.settings.impl - </excludePackageNames> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> <dependency> <groupId>org.osgi</groupId> @@ -98,10 +75,6 @@ <artifactId>org.osgi.service.component</artifactId> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.core</artifactId> - </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.service.cm</artifactId> @@ -116,15 +89,18 @@ <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> + <scope>provided</scope> </dependency> <!-- Testing --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>commons-lang</groupId> @@ -134,8 +110,8 @@ </dependency> <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.10.19</version> + <artifactId>mockito-core</artifactId> + <version>5.20.0</version> <scope>test</scope> </dependency> <dependency> @@ -151,4 +127,24 @@ <scope>test</scope> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-baseline-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <excludePackageNames>org.apache.sling.settings.impl</excludePackageNames> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java index 28b521c..489f687 100644 --- a/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java +++ b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java @@ -18,9 +18,6 @@ */ package org.apache.sling.settings.impl; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -31,16 +28,20 @@ import java.util.Set; import org.apache.sling.settings.SlingSettingsService; import org.junit.Assert; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.osgi.framework.BundleContext; import org.osgi.util.converter.Converter; import org.osgi.util.converter.Converters; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + @RunWith(MockitoJUnitRunner.class) public class RunModeImplTest { @@ -67,9 +68,9 @@ public class RunModeImplTest { @Override public File answer(InvocationOnMock invocation) throws Throwable { - String filename = invocation.getArgumentAt(0, String.class); + String filename = invocation.getArgument(0, String.class); File f = files.get(filename); - if ( f == null ) { + if (f == null) { try { f = File.createTempFile(filename, "id"); f.delete(); @@ -81,21 +82,21 @@ public class RunModeImplTest { return f; } }); - + Mockito.when(mockBundleContext.getProperty(Mockito.anyString())).then(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { - String key = invocation.getArgumentAt(0, String.class); - if ( key.equals(SlingSettingsService.RUN_MODES_PROPERTY) ) { + String key = invocation.getArgument(0, String.class); + if (key.equals(SlingSettingsService.RUN_MODES_PROPERTY)) { return runModes; - } else if ( key.equals(SlingSettingsService.RUN_MODE_OPTIONS) ) { + } else if (key.equals(SlingSettingsService.RUN_MODE_OPTIONS)) { return options; - } else if ( key.equals(SlingSettingsService.RUN_MODE_INSTALL_OPTIONS) ) { + } else if (key.equals(SlingSettingsService.RUN_MODE_INSTALL_OPTIONS)) { return installOptions; } return null; } - }); + }); } private void assertParse(String str, String[] expected) { @@ -110,12 +111,12 @@ public class RunModeImplTest { Assert.assertEquals("Parsed runModes match for '" + str + "'", expectedSet, modes); } - @org.junit.Test + @Test public void testParseRunModes() { assertParse(null, new String[0]); assertParse("", new String[0]); - assertParse(" foo \t", new String[] { "foo" }); - assertParse(" foo \t, bar\n", new String[] { "foo", "bar" }); + assertParse(" foo \t", new String[] {"foo"}); + assertParse(" foo \t, bar\n", new String[] {"foo", "bar"}); } private void assertActive(SlingSettingsService s, boolean active, String... modes) { @@ -128,14 +129,14 @@ public class RunModeImplTest { } } - @org.junit.Test + @Test public void testMatchesNotEmpty() { final SlingSettingsService rm = createSlingSettingsService("foo,bar", null, null); assertActive(rm, true, "foo", "bar"); assertActive(rm, false, "wiz", "bah", ""); } - @org.junit.Test + @Test public void testOptions() { final SlingSettingsService rm = createSlingSettingsService("foo,bar", "a,b,c|d,e,f", null); assertActive(rm, true, "foo", "bar", "a", "d"); @@ -225,4 +226,4 @@ public class RunModeImplTest { this.installOptions = installOptions; return new SlingSettingsServiceImpl(configuration, mockBundleContext); } -} \ No newline at end of file +} diff --git a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java index cb6b063..8e99088 100644 --- a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java +++ b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java @@ -18,11 +18,6 @@ */ package org.apache.sling.settings.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -45,6 +40,11 @@ import org.osgi.framework.BundleContext; import org.osgi.util.converter.Converter; import org.osgi.util.converter.Converters; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class SlingSettingsServiceImplTest { private static final String SLING_ID_FILE_NAME = "sling.id.file"; @@ -54,7 +54,7 @@ public class SlingSettingsServiceImplTest { private File slingIdFile = null; private File optionsFile = null; - + private SlingSettingsServiceImpl.Configuration configuration; @Before @@ -121,27 +121,47 @@ public class SlingSettingsServiceImplTest { @Test public void testGetBestRunModeMatchCountFromSpec() { - Assert.assertEquals(0, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4", Collections.singleton("test5"))); - Assert.assertEquals(0, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4", Stream.of("test1", "test3").collect(Collectors.toSet()))); - Assert.assertEquals(0, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4", Stream.of("test2", "test3").collect(Collectors.toSet()))); - Assert.assertEquals(2, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4", Stream.of("test1", "test2").collect(Collectors.toSet()))); - Assert.assertEquals(2, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4", Stream.of("test2", "test4").collect(Collectors.toSet()))); - Assert.assertEquals(3, SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec("test1.test2,-test3.test4,test5.test6.test7", Stream.of("test1", "test2", "test4", "test5", "test6", "test7").collect(Collectors.toSet()))); + Assert.assertEquals( + 0, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4", Collections.singleton("test5"))); + Assert.assertEquals( + 0, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4", Stream.of("test1", "test3").collect(Collectors.toSet()))); + Assert.assertEquals( + 0, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4", Stream.of("test2", "test3").collect(Collectors.toSet()))); + Assert.assertEquals( + 2, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4", Stream.of("test1", "test2").collect(Collectors.toSet()))); + Assert.assertEquals( + 2, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4", Stream.of("test2", "test4").collect(Collectors.toSet()))); + Assert.assertEquals( + 3, + SlingSettingsServiceImpl.getBestRunModeMatchCountFromSpec( + "test1.test2,-test3.test4,test5.test6.test7", + Stream.of("test1", "test2", "test4", "test5", "test6", "test7") + .collect(Collectors.toSet()))); } - private SlingSettingsService createSlingSettingsService(final File slingIdFile, final File optionsFile) throws IOException { + private SlingSettingsService createSlingSettingsService(final File slingIdFile, final File optionsFile) + throws IOException { BundleContext context = mock(BundleContext.class); when(context.getDataFile(SLING_ID_FILE_NAME)).thenReturn(slingIdFile); when(context.getDataFile(OPTIONS_FILE_NAME)).thenReturn(optionsFile); // write options final List<SlingSettingsServiceImpl.Options> options = new ArrayList<SlingSettingsServiceImpl.Options>(); try (FileOutputStream fos = new FileOutputStream(optionsFile); - ObjectOutputStream oos = new ObjectOutputStream(fos)) { + ObjectOutputStream oos = new ObjectOutputStream(fos)) { oos.writeObject(options); } catch (final IOException ioe) { throw new RuntimeException("Unable to write to options data file.", ioe); } return new SlingSettingsServiceImpl(configuration, context); } - }
