Skip to content

Commit

Permalink
limit visibility of classes/methods, mocks are created via adapter fa…
Browse files Browse the repository at this point in the history
…ctory

apply null annotation for adaptTo() methods
add changelog
  • Loading branch information
stefanseifert committed Oct 12, 2023
1 parent 63ae06f commit ab24aac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="5.3.2" date="not released">
<release version="5.4.0" date="not released">
<action type="add" dev="royteeuwen" issue="23">
Add mocks for ExperienceFragment and ExperienceFragmentVariation, adaptable from page objects.
</action>
<action type="update" dev="sseifert">
Update to latest Sling Mock.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
/**
* Mock implementation of {@link ExperienceFragment}.
*/
public class MockExperienceFragment extends MockExperienceFragmentBase implements ExperienceFragment {
class MockExperienceFragment extends MockExperienceFragmentBase implements ExperienceFragment {

public MockExperienceFragment(Page page) {
MockExperienceFragment(Page page) {
super(page);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.cq.xf.ExperienceFragmentVariation"
})
@ProviderType
public class MockExperienceFragmentAdapterFactory implements AdapterFactory {
public final class MockExperienceFragmentAdapterFactory implements AdapterFactory {

@SuppressWarnings("unchecked")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.apache.sling.api.adapter.SlingAdaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.wcm.api.Page;

public class MockExperienceFragmentBase extends SlingAdaptable {
class MockExperienceFragmentBase extends SlingAdaptable {

private final Page page;

Expand All @@ -55,7 +57,8 @@ protected InheritanceValueMap getInheritedProperties() {
}

@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
@SuppressWarnings({ "unchecked", "null" })
public @Nullable <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) {
if (type == Resource.class) {
return (AdapterType)page.adaptTo(Resource.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static com.adobe.cq.xf.ExperienceFragmentsConstants.PN_XF_VARIANT_TYPE;

import org.apache.sling.api.resource.ValueMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.adobe.cq.xf.ExperienceFragment;
import com.adobe.cq.xf.ExperienceFragmentVariation;
Expand All @@ -32,11 +34,11 @@
/**
* Mock implementation of {@link ExperienceFragmentVariation}.
*/
public class MockExperienceFragmentVariation extends MockExperienceFragmentBase implements ExperienceFragmentVariation {
class MockExperienceFragmentVariation extends MockExperienceFragmentBase implements ExperienceFragmentVariation {

private ExperienceFragment parent;

public MockExperienceFragmentVariation(Page page) {
MockExperienceFragmentVariation(Page page) {
super(page);
}

Expand All @@ -56,11 +58,12 @@ public String getType() {
}

@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> aClass) {
if (aClass == Page.class) {
@SuppressWarnings("unchecked")
public @Nullable <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) {
if (type == Page.class) {
return (AdapterType)getPage();
}
return super.adaptTo(aClass);
return super.adaptTo(type);
}

@Override
Expand Down

0 comments on commit ab24aac

Please sign in to comment.