Skip to content

Commit

Permalink
cosmetic: eliminate code warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 16, 2024
1 parent d0dfeb4 commit 5329558
Show file tree
Hide file tree
Showing 24 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/io/wcm/testing/mock/aem/MockDesign.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Style getStyle(Cell cell) {
@Override
public Style getStyle(Resource resource) {
ContentPolicyManager contentPolicyManager = resource.getResourceResolver().adaptTo(ContentPolicyManager.class);
if (contentPolicyManager != null && (contentPolicyManager instanceof MockContentPolicyManager)) {
if (contentPolicyManager instanceof MockContentPolicyManager) {
// unwrap resource to make sure the correct resource type is used when using resource-type forcing wrappers
Resource unwrappedResource = ResourceUtil.unwrap(resource);
ContentPolicy policy = ((MockContentPolicyManager)contentPolicyManager).getPolicy(unwrappedResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private String getLanguageRootPath(Resource res, boolean respectContent) {
path = path.substring(0, idx);
}
Resource hr = res.getResourceResolver().getResource(path);
while (hr != null && !hr.getPath().equals("/")) {
while (hr != null && !StringUtils.equals(hr.getPath(), "/")) {
ValueMap props = hr.getValueMap();
if (props.get("jcr:content/cq:isLanguageRoot", Boolean.FALSE)) {
String iso = props.get("jcr:content/jcr:language", "");
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/io/wcm/testing/mock/aem/MockTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.day.cq.commons.LanguageUtil;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.tagging.Tag;
import com.day.cq.tagging.TagConstants;
import com.day.cq.tagging.TagManager;
import com.day.cq.wcm.api.NameConstants;

Expand Down Expand Up @@ -326,7 +325,7 @@ public String getXPathSearchExpression(String property) {
final String propertyName = extractPathPart(property, StringUtils::substringAfterLast, property);
final String propertyPath = extractPathPart(property, StringUtils::substringBeforeLast, StringUtils.EMPTY);
final String xpathProperty = (StringUtils.isEmpty(propertyPath) ? "" : ISO9075.encodePath(propertyPath) + '/') + '@' + ISO9075.encode(propertyName);
final String xpathNamespace = TagConstants.DEFAULT_NAMESPACE.equals(ns) ? relPath : ns + ":" + relPath;
final String xpathNamespace = DEFAULT_NAMESPACE.equals(ns) ? relPath : ns + ":" + relPath;
return "(" + xpathProperty + "='" + xpathNamespace + "' "
+ "or " + xpathProperty + "='" + tagRoot + "/" + ns + "/" + relPath + "' "
+ "or jcr:like(" + xpathProperty + ", '" + xpathNamespace + "/%') or "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private ContextResourceResolverFactory() {
// static methods only
}

@SuppressWarnings({ "PMD.ExceptionAsFlowControl", "java:S2139", "java:S112" }) // ignore exception handling
public static @NotNull ResourceResolverFactory get(@NotNull final ResourceResolverType resourceResolverType,
@NotNull final BundleContext bundleContext) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.Map;

import javax.jcr.Binary;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -189,18 +188,16 @@ public Revision createRevision(Asset asset, String s, String s1) throws Exceptio
}

@Override
public String assignAssetID(Asset asset) throws PathNotFoundException, RepositoryException {
public String assignAssetID(Asset asset) throws RepositoryException {
throw new UnsupportedOperationException();
}

// AEM 6.5
@SuppressWarnings("unused")
@Override
public Asset createOrUpdateAsset(String arg0, Binary arg1, String arg2, boolean arg3) {
throw new UnsupportedOperationException();
}

// AEM 6.5.5
@SuppressWarnings("unused")
@Override
public Revision createRevision(Asset arg0, String arg1, String arg2, User arg3) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class MockPageManagerTest {
private ResourceResolver resourceResolver;

@Before
public void setUp() throws Exception {
public void setUp() {
this.resourceResolver = this.context.resourceResolver();

context.load().json("/json-import-samples/content.json", "/content/sample/en");
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/io/wcm/testing/mock/aem/MockPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MockPageTest {
private Page page;

@Before
public void setUp() throws Exception {
public void setUp() {
context.load().json("/json-import-samples/content.json", "/content/sample/en");

Resource resource = this.context.resourceResolver().getResource("/content/sample/en");
Expand Down Expand Up @@ -289,7 +289,7 @@ public void testGetLanguage() {
}

@Test
public void testEquals() throws Exception {
public void testEquals() {
Page page1 = context.pageManager().getPage("/content/sample/en");
Page page2 = context.pageManager().getPage("/content/sample/en");
Page page3 = context.pageManager().getPage("/content/sample/en/toolbar/profiles");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MockTemplateTest {
private Template template;

@Before
public void setUp() throws Exception {
public void setUp() {
context.load().json("/json-import-samples/application.json", "/apps/sample");

Resource resource = this.context.resourceResolver().getResource("/apps/sample/templates/homepage");
Expand All @@ -66,7 +66,7 @@ public void testProperties() {
}

@Test
public void testEquals() throws Exception {
public void testEquals() {
Template template1 = this.context.resourceResolver().getResource("/apps/sample/templates/homepage").adaptTo(Template.class);
Template template2 = this.context.resourceResolver().getResource("/apps/sample/templates/homepage").adaptTo(Template.class);
Template template3 = this.context.resourceResolver().getResource("/apps/sample/templates/contentpage").adaptTo(Template.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void testAssetFromByteArray() throws Exception {
}

@Test
public void testAssetFromWidthHeight_Jpeg() throws Exception {
public void testAssetFromWidthHeight_Jpeg() {
Asset asset = context.create().asset(damRoot + "/sample1.jpg", 100, 50, "image/jpeg");
assertNotNull(asset);

Expand All @@ -234,7 +234,7 @@ public void testAssetFromWidthHeight_Jpeg() throws Exception {
}

@Test
public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio1() throws Exception {
public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio1() {
Asset asset = context.create().asset(damRoot + "/sample1.jpg", 2000, 1000, "image/jpeg");
assertNotNull(asset);

Expand All @@ -248,7 +248,7 @@ public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio1() throws Ex
}

@Test
public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio2() throws Exception {
public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio2() {
Asset asset = context.create().asset(damRoot + "/sample1.jpg", 1000, 2000, "image/jpeg");
assertNotNull(asset);

Expand All @@ -262,7 +262,7 @@ public void testAssetFromWidthHeight_Jpeg_BigImage_WebEnabled_Ratio2() throws Ex
}

@Test
public void testAssetFromWidthHeight_Gif() throws Exception {
public void testAssetFromWidthHeight_Gif() {
Asset asset = context.create().asset(damRoot + "/sample1.gif", 100, 50, "image/gif");
assertNotNull(asset);

Expand All @@ -279,7 +279,7 @@ public void testAssetFromWidthHeight_Gif() throws Exception {
}

@Test
public void testAssetFromWidthHeight_Tiff() throws Exception {
public void testAssetFromWidthHeight_Tiff() {
Asset asset = context.create().asset(damRoot + "/sample1.tif", 100, 50, "image/tiff");
assertNotNull(asset);

Expand All @@ -296,7 +296,7 @@ public void testAssetFromWidthHeight_Tiff() throws Exception {
}

@Test
public void testAssetFromWidthHeight_SVG() throws Exception {
public void testAssetFromWidthHeight_SVG() {
Asset asset = context.create().asset(damRoot + "/sample1.svg", 100, 50, "image/svg+xml");
assertNotNull(asset);

Expand All @@ -313,7 +313,7 @@ public void testAssetFromWidthHeight_SVG() throws Exception {
}

@Test
public void testAssetWithMetadata() throws Exception {
public void testAssetWithMetadata() {
Asset asset = context.create().asset(damRoot + "/sample1.jpg", 100, 50, "image/jpeg",
"prop1", "value1", "prop2", 1);
assertNotNull(asset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AemContextImplTest {
private String appsRoot;

@Before
public void setUp() throws Exception {
public void setUp() {
contentRoot = context.uniqueRoot().content() + "/sample";
appsRoot = context.uniqueRoot().apps() + "/sample";

Expand All @@ -56,7 +56,7 @@ public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
public void tearDown() {
this.context.tearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MockAemSlingBindingsTest {
private Resource currentResource;

@Before
public void setUp() throws Exception {
public void setUp() {
context.addModelsForClasses(SlingBindingsModel.class);

currentPage = context.create().page("/content/testPage");
Expand Down Expand Up @@ -182,7 +182,7 @@ public void testBindings_EditMode() {
}

@Test
public void testBindingsModelFactory() throws Exception {
public void testBindingsModelFactory() {
context.currentResource(currentResource);

ModelFactory modelFactory = context.getService(ModelFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SlingAlias_JcrMockTest {
private String contentRoot;

@Before
public void setUp() throws Exception {
public void setUp() {
contentRoot = context.uniqueRoot().content() + "/sample";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SlingAlias_JcrOakTest {
private String contentRoot;

@Before
public void setUp() throws Exception {
public void setUp() {
contentRoot = context.uniqueRoot().content() + "/sample";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -75,7 +74,7 @@ private TestAemContext() {
private static final class SetUpCallback implements AemContextCallback {

@Override
public void execute(@NotNull AemContext context) throws PersistenceException, IOException {
public void execute(@NotNull AemContext context) throws IOException {
try {
// register manually because in project's unit tests itself MANIFEST.MF is not available
NodeTypeDefinitionScanner.get().register(context.resourceResolver().adaptTo(Session.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UniqueRootTest {
public AemContext context = TestAemContext.newAemContext();

@Test
public void testDam() throws Exception {
public void testDam() {
String path = context.uniqueRoot().dam();
assertNotNull(context.resourceResolver().getResource(path));
assertTrue(path.matches("^/content/dam/[^/]+"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testAssetHandler_Invalid() {
}

@Test
public void testGetAssetHandler_JPEG() throws Exception {
public void testGetAssetHandler_JPEG() {
assertNotNull(underTest.getAssetHandler(JPEG_MIME_TYPE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class MockAssetTest {
private DamEventHandler damEventHandler;

@Before
public void setUp() throws Exception {
public void setUp() {
context.load().json("/json-import-samples/dam.json", "/content/dam/sample");

Resource resource = this.context.resourceResolver().getResource("/content/dam/sample/portraits/scott_reynolds.jpg");
Expand Down Expand Up @@ -110,7 +110,7 @@ private boolean hasRendition(List<Rendition> renditions, String renditionName) {
}

@Test
public void testEquals() throws Exception {
public void testEquals() {
Asset asset1 = this.context.resourceResolver().getResource("/content/dam/sample/portraits/scott_reynolds.jpg").adaptTo(Asset.class);
Asset asset2 = this.context.resourceResolver().getResource("/content/dam/sample/portraits/scott_reynolds.jpg").adaptTo(Asset.class);

Expand Down Expand Up @@ -146,18 +146,18 @@ private void doTestAddRemoveRendition(final String renditionName) {
}

@Test
public void testAddRemoveRendition() throws Exception {
public void testAddRemoveRendition() {
doTestAddRemoveRendition("test.bin");
}

@Test
public void testRenditionListMutable() throws Exception {
public void testRenditionListMutable() {
// make sure rendition list is modifiable by calling getBestfitRendition which does a sort on it
UIHelper.getBestfitRendition(asset, 100);
}

@Test
public void testBatchMode() throws Exception {
public void testBatchMode() {
if (context.resourceResolverType() == ResourceResolverType.JCR_MOCK) {
// resource resolver revert not support for JCR_MOCK - skip test
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MockPublishUtilsTest {
private PublishUtils underTest;

@Before
public void setUp() throws Exception {
public void setUp() {
underTest = context.getService(PublishUtils.class);
assertNotNull(underTest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MockRenditionTest {
private Rendition rendition;

@Before
public void setUp() throws Exception {
public void setUp() {
context.load().json("/json-import-samples/dam.json", "/content/dam/sample");

Resource resource = this.context.resourceResolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class MockAssetDeliveryTest {
private Resource assetResource;

@Before
public void setUp() throws Exception {
public void setUp() {
this.underTest = context.registerInjectActivateService(MockAssetDelivery.class);
asset = context.create().asset("/content/dam/test.jpg", 10, 10, "image/jpeg");
assetResource = asset.adaptTo(Resource.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MockNextGenDynamicMediaConfigTest {
private MockNextGenDynamicMediaConfig underTest;

@Before
public void setUp() throws Exception {
public void setUp() {
underTest = context.registerInjectActivateService(MockNextGenDynamicMediaConfig.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class MockResourceCollectionManagerTest {
private Asset sampleAsset;

@Before
public void setUp() throws Exception {
public void setUp() {
underTest = context.getService(ResourceCollectionManager.class);

samplePage1 = context.create().page("/content/mysite/page1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private AemContextStore() {
return null;
}
// try to get existing context from current extension context, or any parent extension context (in case of nested tests)
return Optional.ofNullable(AemContextStore.getStore(extensionContext).get(testClass, AemContext.class))
return Optional.ofNullable(getStore(extensionContext).get(testClass, AemContext.class))
.orElseGet(() -> extensionContext.getParent().map(AemContextStore::getAemContext).orElse(null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void beforeAll() throws Exception {
}

@Test
void testRequest() throws Exception {
void testRequest() {
assertNotNull(context.request());
}

Expand Down

0 comments on commit 5329558

Please sign in to comment.