Monday, October 31, 2016

Spam email

Sometime spam email is so bad it is pure comedy genius. The amount of things wrong with this opening statement.

It is my pleasure to inform you that Diplomatic Agent Terry has arrive in yournearest Airport today with your package worthy $5.5million you have to contacthim at this email address (diplomaticagentfredjames33@gmail.com

Wednesday, October 26, 2016

Side effects with not having decent UNIT tests

This is not Grails/Groovy specific but in general.

Grails/Groovy is certainly more reliant on tests, as it is dynamically typed, so code needs to be executed to pickup errors. The Java world seems to rely on static typing while Groovy on tests. Tests are always better than typing, period.

Besides the obvious, if it is not tested how do you know it works? There are some interesting side effects I see with poorly unit tested code.

Makes your Code Better

  • Having to write unit tests for a class/method makes your code structurally better.
  • It leads to better separation of concerns. 
  • Starts enforcing the law of Demeter. 
  • Easily tested code is generally easier to understand. 


Documents Code

  • Documentation falls out of date and quickly becomes irrelevant. Properly written tests (Spock helps) is a great way to document code. 


Makes changing existing code possible

  • I cannot change existing if I have no idea if it works, or how it works. 
  • In larger systems knowing if existing code works without tests becomes increasingly difficult.
  • It can be very difficult to execute see what code is doing if you need to stand up the whole system just to test a method.


Quicker to Change and Safer to Change

  • If your code has a unit test you can execute it immediately.
  • You can see changes, and what they do to existing tests immediately
  • 100's of times an hour.

Tuesday, October 25, 2016

Intellij Color Schemes

Found a neat little site with colour schemes for Intellij

http://color-themes.com/?view=index

Once you have downloaded the jar, just go to File->import settings and load that jar.

Friday, October 14, 2016

Grails3 GORM running MongoDB

Had some issues getting Mongo to work with Grails3 based on this doc, ended up creating an example project of it all working

Feel free to download, have a look

Spock data driven testing with interactions (Mocks)

You can do data driven testing with Mocks and interactions, the key is that your interaction should be in the setup: block For Example
    @Unroll
    def "createOtherField test to see if label override works #fieldName override(#fieldLabel) == #resultName"() {
        setup:
        FormFieldMapManager formFieldMapManager = Mock()
        String onlineFormId = '1'
        List<LabelValue> otherFields = []
        1*formFieldMapManager.getMappedFields(onlineFormId, false) >> [new FormFieldMap()]

        expect:
        List<LabelValue> result = ProcessorUtil.createOtherField(formFieldMapManager, onlineFormId, otherFields, fieldName, 'fieldValue')
        result[0].label == resultName

        where:
        fieldName   | fieldLabel    || resultName
        'fieldName' | null          || 'fieldName'
        'fieldName' | ''            || 'fieldName'
        ''          | null          || ''
        'fieldName' | 'OVERRIDE'    || 'OVERRIDE'
    }

Tuesday, October 11, 2016

Intellij H2 Database viewer

For some reason to be able to see you tables in the Intellij H2 DB viewer you have append the following mv_store=false in your application.yml so the connection string looks like so:
jdbc:h2:file:./devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;mv_store=false