/*
 * Copyright 2014 protoc-jar developers
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.os72.protocjar;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.File;

import org.junit.Test;

import com.github.os72.protocjar.MavenUtil.MavenSettings;

public class MavenUtilTest
{
	@Test
	public void testParseMavenSettings() throws Exception {
		log("testParseMavenSettings");
		MavenSettings settings = MavenUtil.parseMavenSettings(new File("src/test/resources/maven-settings.xml"));
		assertEquals("http://mirrors.ibiblio.org/pub/mirrors/maven2/", settings.mMirrorUrl);
		log(settings.mMirrorUrl);
		assertEquals("localhost", settings.mProxyHost);
		assertEquals(3128, settings.mProxyPort);
		log(settings.mProxyHost + ":" + settings.mProxyPort);
	}

	@Test
	public void testParseReleaseBuild() throws Exception {
		log("testParseReleaseBuild");
		File mdFile = new File("src/test/resources/maven-metadata-release.xml");
		String build = MavenUtil.parseLastReleaseBuild(mdFile, new ProtocVersion(null, null, "2.4.1"));
		assertEquals("2.4.1-build3", build);
		build = MavenUtil.parseLastReleaseBuild(mdFile, new ProtocVersion(null, null, "3.5.1"));
		assertEquals("3.5.1-build2", build);
		build = MavenUtil.parseLastReleaseBuild(mdFile, new ProtocVersion(null, null, "3.7.0"));
		assertNull(build);
	}

	@Test
	public void testParseSnapshotExeName() throws Exception {
		log("testParseSnapshotExeName");
		File mdFile = new File("src/test/resources/maven-metadata-snapshot.xml");
		String name = MavenUtil.parseSnapshotExeName(mdFile);
		assertEquals("protoc-2.4.1-20180823.052533-7-windows-x86_64.exe", name);
	}

	static void log(Object msg) {
		System.out.println("protoc-jar-test: " + msg);
	}
}

@@ -745,16 +745,45 @@
 io.File;
+%0Aimport java.util.Properties;
 %0A%0Aimport
@@ -1881,17 +1881,17 @@
 ull, %223.
-7
+8
 .0%22));%0A%09
@@ -2147,16 +2147,176 @@
 dFile);%0A
+    %09Properties props = new Properties();%0A%09%09new PlatformDetector().detect(props, null);%0A%09%09String osName = props.getProperty(PlatformDetector.DETECTED_NAME);%0A%09%09%0A
 %09%09assert
@@ -2322,16 +2322,30 @@
 tEquals(
+String.format(
 %22protoc-
@@ -2372,14 +2372,9 @@
 3-7-
-window
+%25
 s-x8
@@ -2383,16 +2383,25 @@
 64.exe%22,
+ osName),
  name);%0A

Fix test with platform detector