This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.
SpeedyImgImage decodeImage(List<SpeedyImgDecoder> decoders, byte[] data) { SpeedyImgOptions options = getDefaultConvertOptions(); for (SpeedyImgDecoder decoder : decoders) { SpeedyImgResult decodeResult = decoder.decode(decoder.formatBytes(data)); SpeedyImgImage image = decodeResult.getImage(options); if (validateGoodImage(image)) { return image; } } throw new RuntimeException(); }
Image decodeImage(List<ImageDecoder> decoders, byte[] data) { for (ImageDecoder decoder : decoders) { Image decodedImage = decoder.decode(data); if (validateGoodImage(decodedImage)) { return decodedImage; } } throw new RuntimeException(); }
“Separation of Concerns” in the context of external APIs is also described by Martin Fowler in his blog post, Refactoring code that accesses external services.