CameraUrlGenerator { public String[] generateUrls(String[] baseUrls) { Map<String, String> commands = new LinkedHashMap<>(); Resolution resolution = source.getTargetResolution(); if (resolution != null && resolution.getWidth() > 0 && resolution.getHeight() > 0) { commands.put("resolution", resolution.getWidth() + "x" + resolution.getHeight()); } int compression = source.getTargetCompression(); if (compression >= 0 && compression <= 100) { commands.put("compression", Integer.toString(compression)); } int frameRate = source.getTargetFps(); if (frameRate > 0) { commands.put("fps", Integer.toString(frameRate)); } if (source.getName().contains("IMAQdx")) { commands.put("name", source.getName()); } return generateUrls(commands, baseUrls); } CameraUrlGenerator(CameraServerSource source); String[] generateUrls(String[] baseUrls);  }
@Test public void testGenerateUrls() { Map<String, String> commands = new HashMap<>(); String url1 = "http: String url2 = "http: String[] baseUrls = {url1, url2}; assertArrayEquals(baseUrls, CameraUrlGenerator.generateUrls(commands, baseUrls), "No commands should return the base URLs"); commands.put("foo", "bar"); assertArrayEquals( new String[]{url1 + "?foo=bar", url2 + "?foo=bar"}, CameraUrlGenerator.generateUrls(commands, baseUrls), "Generated URLs do not match"); }
@Test public void testGenerateUrlsNI() { String cameraName = "IMAQdx:Microsoft LifeCam HD-3000"; Map<String, String> commands = new HashMap<>(); commands.put("name", cameraName); String url1 = "http: String url2 = "http: String[] baseUrls = {url1, url2}; String[] baseUrlsWithNames = Arrays.stream(baseUrls).map(x -> x + "?name=cam0").toArray(String[]::new); String[] baseUrlsWithCameraNames = Arrays.stream(baseUrls) .map(x -> x + "?name=IMAQdx%3AMicrosoft%20LifeCam%20HD-3000") .toArray(String[]::new); assertArrayEquals(baseUrlsWithCameraNames, CameraUrlGenerator.generateUrls(commands, baseUrlsWithNames), "Name should be replaced"); }