Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Issue while writing Junit for Bitbucket plugin custom java class

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);

 

  • Every time when I run the Junit

Getting null value of  “fileDetails” object

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,093 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you