Software Engineer

I am a Software Engineer. I have a Bachelor (Honours) of Science in Information Technology from the University of Sunderland - Class of 2003. I have been developing software since 2001 when I was offered a role at CERN as part of their Technical Student Programme.

By 2016 I had grown really tired of the software industry and by the end of 2019 Apple killed whatever excitement I had left. I am not sure what the next 10 years will bring. What I do know is that my apettite to do work that is impactful has only grown bigger and stronger. Great people make me tick more than anything.

I am also tired.

Focus on your test, leave buggage behind

public class MySelfTest
    {
        @Test
        public void goOutWithYourMates() throws Exception
        {
            MySelf mySelf = new MySelf();
            
            /**
             * Not DRY
             */
            mySelf.getOver( new ExGirlfriend() );
            
            Assert.assertTrue( mySelf.goOutWithYourMates() );        
        }
        
        @Test
        public void playStarcraft() throws Exception
        {
            MySelf mySelf = new MySelf();

            /**
             * Not DRY
             */
            mySelf.getOver( new ExGirlfriend() );
            
            Assert.assertTrue( mySelf.playStarcraft() );        
        }
    }

    /**
     * DRY yourself
     */

    /**
     * Create implementations of this interface with your conditions
     */
    public interface Condition
    {
        /**
         * Put the condition logic here 
         */
        public void apply();
    }


    /**
     * Introduce Preconditions
     */
    class Preconditions
    {
        static Condition all(final Condition... conditions)
        {
        return new Condition() {            
                @Override
                public void apply()
                {
                    for (Condition condition : conditions)
                    {
                        condition.apply();
                    }                
                }
            };
        }
        /**
         * @return
         */
        static Condition buggageShouldBeLeftBehind(final MySelf mySelf, final Girlfriend girlfriend)
        {
        return new Condition() {        
                @Override
                public void apply(){
                    mySelf.getOver( girlfriend );
                }
            };
        }
    }

    /**
     * Leave buggage behind
     *
     */
    public class MySelfTest
    {
        @Test
        public void goOutWithYourMates() throws Exception
        {
            MySelf mySelf = new MySelf();
            
            Preconditions.buggageShouldBeLeftBehind(mySelf, new ExGirlfriend()).apply();
            
            Assert.assertTrue( mySelf.goOutWithYourMates() );        
        }
        
        @Test
        public void playStarcraft() throws Exception
        {
            MySelf mySelf = new MySelf();

            Preconditions.buggageShouldBeLeftBehind(mySelf, new ExGirlfriend()).apply();
            
            Assert.assertTrue( mySelf.playStarcraft() );        
        }
    }
Use a class to define your Preconditions.

You don’t pollute your test class with methods not related explicitly to your tests and avoid boilerplate code.

Preconditions class

  • encapsulates the Condition(s)

while making your code

  • readable
  • reusable

Can apply to any conditions you would like to encapsulate really.

Disclaimer: It’s a trivial example to make you think of an alternative way to apply pre/post conditions to your tests.