Pages

Friday, August 17, 2018

Refactoring - How do I start?



According with the Software-craftsmanship legend Sandro Mancuso we should start:

  • Refactoring from the deepest nested branch of the code and work our way inside out.
  • Test from the shortest/less nested branch of the code and work our way from outside in.

Wednesday, August 8, 2018

Using Wiremock to simulate a slow responding server.

Here a little example of a stub created with Wiremock that simulates a slow reply from a server:

 import com.github.tomakehurst.wiremock.WireMockServer;  
 import java.util.Scanner;  
 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;  
 import static com.github.tomakehurst.wiremock.client.WireMock.get;  
 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;  
 public class FakeThirdPartySystem {  

   public static void main(String[] args) {  
     WireMockServer server = new WireMockServer(8081);  
     server.start();  
     server.stubFor(get(urlEqualTo("/someUrl"))  
         .willReturn(aResponse()  
             .withStatus(200)  
             .withFixedDelay(10000)  
             .withBody("Slow reply!")));  

     //This is just so that the app doesn't exit straight away
     Scanner scanner = new Scanner(System.in);  
     System.out.println("Press enter to exit");  
     scanner.nextLine();  
     server.stop();  
   }  

 }  

Note: This is just for illustration purposes but this same way of stubbing can be added to an acceptance test. 

Share with your friends