3

I am trying to learn how to write tests for apex services using ApexMocks framework. I want to generate Mock classes through apex-mocks-generator and I am following simple instructions given in this article.

I download repository from GitHub and placed required apex files to src/classes location. I run following in from my terminal:

java -jar apex-mocks-generator-3.0.1.jar src/classes IAccountUpdate mockAccountUpdate src/results

Error:

sourcePath=src/classes interfaces=IAccountUpdate mocksClassname=mockAccountUpdate targetPath=src/results

Exception in thread "main" java.io.FileNotFoundException: IAccountUpdate (The system cannot find the file specified) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.(Unknown Source) at java.io.FileInputStream.(Unknown Source) at java.io.FileReader.(Unknown Source) at com.financialforce.apexmocks.MocksGenerator.(MocksGenerator.jav a:34) at com.financialforce.apexmocks.ApexMockGenerator.main(ApexMockGenerator .java:31)

I have tried the older version of this generator which has a different command to create mocks. And it also gives java.io.FileNotFoundException. Interface is present in src folder. I am not sure what I am doing wrong here.

1
  • I'm having the same issue, are you also using a relative path (from the .jar)? The examples seem to indicate that you can do this, but I'm curious if that is causing it to not be found – Xtremefaith Feb 11 '17 at 0:58
0

I was able to get this to work using the new 4.0.1.jar. I placed the .jar script along with the interfacemocks.properties file in my environment folder just before the /src/ directory. Then from my terminal (I use Cmder), from the directory of the .jar I ran the following

java -jar apex-mocks-generator-4.0.1.jar "src\classes" "interfacemocks.properties" "Mocks" "src\classes"

This then populated my Mocks.cls (already created previous to running the command) with the mock interfaces I defined in the interfacemocks.properties file.

NOTE: Notice the relative paths did not include a preceding \ as the documentation suggest. Also a previous tutorial showed an example without the "" wrappers for each parameter, but I found I needed those like the ApexMocks documentation/readme indicates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.