Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 15, 2024
1 parent 0aa9b7a commit cbc8aa5
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* 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.
* #L%
*/
package io.wcm.caconfig.sample.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Collections;

import org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import io.wcm.caconfig.editor.ConfigurationCategory;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

@ExtendWith(AemContextExtension.class)
class SampleConfigurationCategoryProviderTest {

private final AemContext context = new AemContext();

private SampleConfigurationCategoryProvider underTest;

@BeforeEach
void setUp() {
underTest = context.registerInjectActivateService(SampleConfigurationCategoryProvider.class);
}

@Test
void testGetCategoryMetadata() {
ConfigurationCategory category = underTest.getCategoryMetadata("test");
assertNotNull(category);
assertEquals("test", category.getCategory());
assertEquals("Test", category.getLabel());
}

@Test
void testGetCategory() {
ConfigurationMetadata metadata = new ConfigurationMetadata("test", Collections.emptyList(), false);
assertEquals("default", underTest.getCategory(metadata));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* 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.
* #L%
*/
package io.wcm.caconfig.sample.impl;

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.day.cq.wcm.api.Page;

import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

@ExtendWith(AemContextExtension.class)
class SampleDropdownOptionProviderTest {

private final AemContext context = new AemContext();

private SampleDropdownOptionProvider underTest;

@BeforeEach
void setUp() {
underTest = context.registerInjectActivateService(SampleDropdownOptionProvider.class);
}

@Test
void testGetDropdownOptions() {
Page page = context.create().page("/content/sample");
assertEquals(underTest.getDropdownOptions(page.getContentResource()).size(), 3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void testContentComponent() {
ConfigSampleNestedModel model = context.request().adaptTo(ConfigSampleNestedModel.class);
assertNotNull(model);
assertEquals("value1", model.getConfig().stringParam());

assertNotNull(model.getSub());
assertNotNull(model.getSub2());
assertNotNull(model.getSub2List());
}

@Test
Expand Down

0 comments on commit cbc8aa5

Please sign in to comment.