Category: Uncategorized

Technical User Standards Design Experience Interface Documentation

If I had ever thought I would be doing a post on documentation, I would have made sure to have more topic starters in the back log. Let me put this out in the open, I hate writing documentation. Now that that is out of the way I feel empowered and what better way to express that than by judging all of you. I am going to guess that a great many of you hate documentation as well. Now don’t get put off by that statement or think I am belittling anyone in particular. I have seen it everywhere, on projects big and small, proprietary and open source, useful and utter garbage. Even my own git hub projects languish with bad documentation. Actually writing documentation, it seems, is farther down on my todo list than writing a blog post about writing documentation. Part of the problem is that once you start getting serious about documenting it appears that everyone has different ideas of the style, scope, and purpose. With every single sample different, finding a consistent thread of what a specific type of documentation is for, becomes an infuriating mess. If you are like me, this turns into mental gridlock as you agonize over how far you go with the details.

Let me paraphrase a joke I once heard: A group of developers were going over all the different formats their new media player would play. They narrowed it down to a list of 13 formats. Staring at the mess they thought to themselves, “Hey, we’re smart people, we should make a new format to overthrow and unify these other formats.” Then they had 14 formats to code to.

I mention that, because I will not be calling out one style of documentation above the rest. No, I will be adding my voice to the din. Just as a forewarning, I have no place telling anyone how documentation should be done. That being said, I will divide the documentation into three segments. The first will be the foundation, the second will be the stories, and the third will be the generated docs. They have been split based on their audience and their goal.


I call this the foundation because it will have information pertinent to the entire project and is readable by everybody, from the managers to the developers. The goal here is to be only as technical as we need to be. To use a Heroku project as an example, this area will hold information like what technology is being used, what coding standards should be followed, what certification the app must meet, and any other project wide promises the app will be held to. Much of this paragraph is built off of section five in the book, Software Architecture for Developers. If your project is using MySQL instead of PostgreSQL, that goes here. If your project is being held to five 9s, god help you and that goes here. If  you have a specific task to submit your app for PCI certification, then that goes in the next section but the fact that it must be PCI certified goes here. So what is the next section?


I love stories. No, seriously, a well written user story is a wonderful thing to behold. I am basing this section off of my experiences with Jira, but I can think of no better place for documentation about what the project should be then right in the Jira stories themselves. These should contain all of the information about specific functionality that has been promised. The arrangement works out perfectly as all the information, including screen mocks can be added to the story. Questions and comments can be added as well to turn it into a living document, recorded for posterity. This should be a boon to QA testers who only have to look in one location to find out all the information on what a task should and should not do.

Code Documentation

While the above described what should happen, the code comments should communicate how. I am not talking about commenting every line of code, that is pointless and prone to error. Your code documentation should be twofold. First is structured comment blocks, ones that can be parsed by documentation generating tools, placed at the beginning of classes and at least on all public API. You can get the private methods to help out maintainers (and yourself) in the future. The next is inline comments, ONLY when there is a need to explicitly call out what you are doing. To use a real life example, to get JSTL referenced correctly in a recent project, I had to add in three lines of what can only be described as code voodoo. I added a comment stating not to remove it carelessly, why it was there, and a link to a page I got the piece of code from.


All told, with these three components there should be a complete picture with very little overlap or duplication. I say should because documentation is a soft skill. If you have bad code then you can get compilation errors, or test failures, or regressions in QA. Bad documentation can take a long while to surface, if they ever do. The side effect of bad documentation can be confusion, inefficiency, and delay that is hard to quantify but easy to feel. So whether it be a grain or a fast food serving worth salt, take this plan into consideration.


MavensMate Vs IDE

Are you looking for a no holds bared, pulse pounding, head-to-head match up between two established titans!? Then I am sorry, this is just a comparison between two code editors. I am sorry to have wasted your time. If, however, you came here looking for the type of fuel that can keep a flame war burning for way longer than it should have, then have I got a post for you. First let me frame this for anyone who isn’t in the know.

The IDE was a plugin for Eclipse built on the metadata API. If you wanted to do any code editing out of the cloud, this was about your only choice. It was rough at times; tests were slow to the point of useless, there were a few missing features that people had come to expect from code editors, & it used the whole weight and heft of Eclipse to essentially act as a text editor with some fancy saving. MavensMate came along and, for some of my coworkers and myself, completely blew IDE out of the water. It was light, it was fast, there was code completion, there was an intuitive test results screen AND you could play games during a deploy. How cool is that! I suppose the only drawback is that the text editor it was a plug-in for, Sublime Text 3, is $80. That is not too bad considering how well loved Sublime is, but it is still something to keep in mind if you are going to be rolling this out to a large number of developers.

Ok, history lesson over. If you can’t tell by the fact that the above fight seems kinda lopsided and yet I am still writing, something has changed. The IDE has been released as open source and based off of the tooling API. Right off the bat this scores big with me since I am also a Java developer and can better understand what the code does. It is still an Eclipse plugin so that complaint still stands but lets see if it can wow us, shall we?

The IDE install process remains mostly unchanged and that is fine, as the Eclipse plugin manager is stable and robust enough to handle this easily. The project setup screen is also very familiar, though I did have to resize the ‘Choose initial project contents’ dialog  for the components to show up . It has a pile more choices for metadata types it can pull down, but it has always had that advantage. The tests were definitely faster, which was nice to see though the coverage report is lacking some polish. Two things I could not get working were the automatic builds and the code completion. The automatic builds caught me off guard as that was a feature that used to work. The code completion was something I was looking forward to working, but no dice. At this point I uninstalled and reinstalled, but it didn’t get any better.

When I set out to write this post, I wanted to be surprised. I will remember to be more careful with how I word my wishes. I was indeed surprised by how unimpressed I was. Compared to the old version, it did not feel like a significant improvement, or or an improvement warranting a blog post, or an  improvement at all. So I probably sound pretty down on the updated IDE, and I am, but I am hopeful. Releasing the source and making it much more possible to extend is a huge step forward. As it stands MavensMate still owns the IDE, but I will be happy to do another comparison in the future to see if the lead disappears.

Here comes NimbusMock!

Oh look, a git hub repo. That’s right, my mocking framework for apex has a name and a repo. Yay? Right now it is a 0.0.1 release. That means there is lots of chance for the api to change (I am still trying to decide whether to split out the object mocking and method stubbing). For now let’s see what it has to offer.

Class Setup in your Application

Before you can even hope to mock anything, there is a certian way to go about setting up your classes. The service classes must be setup with an interface. The point of the mock will be to override the default functionality with the mock methods. For any classes that are going to use these mocks, they must be setup so that the mocks can either be set in the constructor or a setter.

How to Mock

The first step, assuming your classes are all ready, is to make your mocks. In MockFactory.cls, create an inner class that extends NimbusMock and implements your interface. Your methods will simply call getCall with a unique name for that call in that class and an object array of your parameters. The following is a references for how to mock your calls:


Using your Mocks

Creating an instance of your mock is as easy as any regular class. For example:

From there, you need to tell the mock what to return or throw when a call is made with some combination of parameters. The base is the same in both cases, calling the when static method on NimbusMock and pass it the call to the mock method with the parameters you expect. After that you either chain thenReturn or thenThrow depending on what you want it to do. When put together, it looks something like this:


  • A generator for the mocks. I plan on writing this in apex and letting the devloper write up a script calling it with a list of classes they want mocked
  • The ability to set how many times the same call can be made and to see how many times a call is used after the fact
  • Mocking classes without interfaces. This isn’t that hard, I just need to settle on how I want to go about it

I am keeping good on my word

Like the title says, I am keeping good on my word to get some stuff done. I have been working on my mocking framework to post it to github. There have been a number of changes. Probably the biggest noticeable change is the switch to a mockito-like when+doReturn style. Along with this, I no longer use a static mock manager which means that there are less chances of method name conflict. The down side to this is that the mock now needs to be injected via constructor or property as the mocked calls are specific to the instance created in the test. The mocks have also been softened and now allow for out of order method invocation. There are still matchers but they have changed a bit. It is very much a work around for the lack of reflection and I expect them to change in the second release. In fact, there is a laundry list of features I want to add, but I need to get something out there first before I start planning where I will put the kitchen sink. Now, some may be wondering why I have not put anything in github and the reason is, is that this was a major overhaul from top to bottom. I didn’t want some broken piece of code attached to my name. Right now it is 90ish percent done. The code is working, but I want more tests and some clean up. You see, I do most of this at night… or the morning as it just so happens (12:11am as of this sentence) and while I produce working code, I also produce code with a high WTF/m at this time. So once I have it cleaned up, tested and commented, I will push it to github and make a big ol’ post about it here.

I’m not dead

I feel happy. I feel happy…

No grail fans? I thought I might use a dead parrot parody but in that sketch the parrot had most definitely ceased to be. “So where have you been,” you may be asking yourself and to you I reply, “that is none of your business but I will tell you anyway cuz I’m a nice person and I am sure you are too.” I moved, settled in, the steam sale happened…. yeah, anyway. I want to get back to posting and I would also like to update my site a bit. It seems to be lacking, well, imagine me frantically waving at the screen and you get the gist of it. No social icons, no about me and a bear bones theme leaves this looking like a fly-by-night hack job rather than someone genuinely interested in this technology. I also want to get my Mock framework out on git hub. I will admit, when I heard that someone else had beaten me to the punch with a few features I would have liked to use, I got a little down on my code. Well that was wrong of me because you know what is better than one good implementation, TWO! Let’s keep forcing the issue and maybe, just maybe, Salesforce will throw us a reflection bone or something, anything to make this mocking thing less clunky. A guy can hope right? Anyway, lets see if I can coax this blog back to life a’ight. See you all soon!


Enhanced Mock Mocks

Well color me surprised, my last article on mocking in apex was, well, a little more popular than I thought it would be. I was happy that so may people enjoyed it, but it got me thinking, “Bob, you handsome and brilliant, yet refreshingly humble man, you can do more for your fans!” After an obligatory back patting, I set off to add more features. This will build entirely off of the last article. In fact, you are doing yourself a disservice if you don’t read it post haste.

We start with a change to add parameter matcher, a handy feature for times when you are not 100% sure the value that is going into you method. All we need is an enum.

This is the bare minimum to work while still providing room for enhancement. The only thing in this enum is the value anyVal. What we are saying is when this is used, accept any value. Next I modified my interface, services and test to give the method getAuthCode a Datetime parameter. The OrderService will pass in, making this almost impossible to mock without matchers. There also needs to be a change in Mock maker to handle this new condition.

It isn’t much different than it was two weeks ago, except now it checks if the parameter is a matcher. If it is, and since there is only one possible value it could be, we just skip any check on the parameter and continue to the next. Now we can change our test to work with this new code.

Now our call to getAuthCode will work no matter what we pass in. A quick test run shows both tests passing… but that isn’t right, now is it? We only changed one test yet both still pass. It isn’t enough to simply check the parameters, we need to check the number of them as well. Otherwise our loop could give false positives like in this case, or throw exceptions. Let’s put a halt to that right now.

One extra line asserts that the number of parameters passed in is the same as those expected.

There is another case we are still not testing for. If you remember last time, I used mocks to return a purposeful bad value to test out some error handling. What if we wanted to test what happens when the service we are mocking throws an exception itself? We need some more code for this one but before that, we need an exception to throw.

Phew, that was a lot of work, but I soldier on. Next is some code in our service to expect such an exception.


Now we need to get MockMaker to throw the exception at the right time.

This getCall method keeps getting all of the attention. Another conditional now checks if the return value is actually an exception and if so, it throws it. The only thing left is the test.

The only real difference here is that the addCall for processPayment has an exception passed into it and the end assert reflects the caught exception.

With just a bit of work, MockMaker now checks the quantity of parameters, uses matchers to check for values that might not be known when the test is started, and throws exceptions on command. While not on par with some other language’s mock suits, it can go a long way to making life easier for a developer.

Apex Analyzer Dev Diary

Well, this is an interesting situation. When I started this blog, my intent was to do reviews, news, and the occasional small project. My post series on using Heroku to host a personal site was just that. My last post which laid the ground work for an Apex static code analyzer took a good deal of time but would have been fine if it ended there. It didn’t end there though. In fact, I poured a pile more work into it this week to hook together the express framework as well as an sqlite database. If you have been watching the git repo, you have likely noticed…. nothing at all. The changes are so drastic, I cannot commit until I have at least the functionality I had before. No real post this week but I wanted to keep people in the loop.