ImageWS { MediaType getMediaTypeFromImageName(String imageName) { MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; String fileExtension = FilenameUtils.getExtension(imageName).toLowerCase(); switch (fileExtension) { case "jpeg": case "jpg": mediaType = MediaType.IMAGE_JPEG; break; case "png": mediaType = MediaType.IMAGE_PNG; break; case "gif": mediaType = MediaType.IMAGE_GIF; break; } return mediaType; }  @RequestMapping(value = "/api/images/**", method = RequestMethod.GET) @ResponseBody ResponseEntity getImage(HttpServletRequest httpServletRequest); @RequestMapping(value = "/api/images/**", method = RequestMethod.PUT) @ResponseBody void uploadImage(@RequestBody byte[] imageContent, HttpServletRequest httpServletRequest);  }
@Test public void testGetMediaTypeFromImageNameNoExtension() { String imageName = "noextension"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.APPLICATION_OCTET_STREAM; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
@Test public void testGetMediaTypeFromImageNamePng() { String imageName = "image1.png"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_PNG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
@Test public void testGetMediaTypeFromImageNamePngUpper() { String imageName = "image1.PNG"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_PNG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
@Test public void testGetMediaTypeFromImageNameJpg() { String imageName = "image1.jpg"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_JPEG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
@Test public void testGetMediaTypeFromImageNameJpeg() { String imageName = "image1.jpeg"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_JPEG; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }
@Test public void testGetMediaTypeFromImageNameGif() { String imageName = "image1.gif"; ImageWS instance = new ImageWS(); MediaType expResult = MediaType.IMAGE_GIF; MediaType result = instance.getMediaTypeFromImageName(imageName); assertEquals(expResult, result); }