HI all
I am facing issue while writing Junit for Atlassian – bitbucket plugins custom class.
Can some help on this?
-----------------------------------------------------------
I am developing bitbucket plugin which store bitbucket file extra details in Bitbucket data-base [Embedded on bitbucket-server].
I have created one custom java class FileDetails.java which is mapped with Bitbucket database table.
FileDetails.java sample code:
public interface FileDetails extends net.java.ao.RawEntity<Long>{
//getters and setter
}
For fetch Bitbucket File-Detail I am using custom service class which fetch file-detail from bitbucket-database.
Sample Code of server class:
public FileDetails getFileDetails(String fileName) {
return ao.executeInTransaction(new TransactionCallback< FileDetails >()
@Override
public FileDetails doInTransaction() {
// getting file details from bitbucket Database
final FileDetails[] fileDetails =ao.find(FileDetails.class, GET_FILE_QUERY,fileName);
//returninig file details
return fileDetails;
}
});
Issue I am facing while writing Junit for service class
Where I am mocking method getFileDetails using Mockito framework.
Pom entry for Junit is:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
Sample code for Junit class where mocking file Object:
FileDetails fileDetails =new FileDetails();
fileDetails.setFileType("txt");
Mockito.when(Customervice.getFileDetails( fileName)).thenReturn(fileDetails);
Getting null value of “fileDetails” object
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.