Closed Harshitha942 closed 3 years ago
Java Class
package com.aem.geeks.core.models.impl;
import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.Default; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Via; import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import com.aem.geeks.core.models.Component;
@Model(adaptables = SlingHttpServletRequest.class, adapters = Component.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class Componentimpl implements Component {
@ValueMapValue
@Via("Resource")@Default(values = "****")
String fname;
@ValueMapValue
@Default(values = "####")
String lname;
@ValueMapValue
String gender;
@ValueMapValue
Long phno;
@Override
public String getFirstName() {
return fname;
}
@Override
public String getLastName() {
return lname;
}
@Override
public String getGender() {
return gender;
}
@Override
public Long getPhoneNo() {
return phno;
}
}
Interface package com.aem.geeks.core.models;
public interface Component {
String getFirstName();
String getLastName();
String getGender();
Long getPhoneNo();
}
I'm not quite sure what your issue is here, but your errors seem to be related to running junit in general as there is nothing in the error message that refers to your test class. Are you able to run junit tests for other classes in your project?
Im also curious if you have multiple versions of junit on your path. Your test seems to be referring to junit 5 classes, but your error messages are referring to junit 4.
I tried running Junit for other classes in the same project , but gives the same error I have included Junit 5 in the Java build path , Yes exactly , error is referring to Junit 4 I even tried to have Junit 4 , instead of Junit 5 ,in the build path, but that did not work Also tried to change my version from 4.8.2 to 5. , but no luck
Try adding the following to your pom.xml
<!-- for testing we need the new ResourceTypeBasedResourcePicker -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
<version>1.4.6</version>
<scope>test</scope>
</dependency>
Now im getting the above error
Try all of this in your pom.xml for the testing scope
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock.junit5</artifactId>
<version>2.4.16</version>
<scope>test</scope>
</dependency>
<!-- for testing we need the new ResourceTypeBasedResourcePicker -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
<version>1.4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
</dependency>
Closing this issue as it appears to be related to the user's project setup and not directly caused by the Component Generator (which simply generates a stubbed test).
Hi ,for the same component above , I am trying to write down a testcase with help of Junit , but there are errors throwing up
this is the error im getting
This is my test class. package com.aem.geeks.core.models.impl;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith;
import com.aem.geeks.core.models.Component;
import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension;
@ExtendWith(AemContextExtension.class) class ComponentimplTest { private final AemContext ctx = new AemContext();
}
Mock Json class { "component": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "aemgeeks/components/content/component", "firstname": "Jane", "lastname": "Doe", "gender": "Female"
}
Originally posted by @Harshitha942 in https://github.com/adobe/aem-component-generator/issues/41#issuecomment-721549776