/*
 * (C) Copyright 2012, IBM Corporation
 *
 * 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.ibm.jaggr.core.impl.resource;

import com.ibm.jaggr.core.IAggregator;
import com.ibm.jaggr.core.resource.IResource;

import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.junit.Test;

import java.io.File;
import java.net.URI;

import junit.framework.Assert;

public class FileResourceTest {

	@Test
	public void testAuthority() throws Exception {
		if (File.separatorChar == '\\') {	// Authority component only supported on Windows
			FileResource res = new FileResource(new URI("file://server/path/name.ext"));
			Assert.assertEquals("\\\\server\\path\\name.ext", res.file.getAbsolutePath());
			Assert.assertEquals("file://server/path/name.ext", res.getURI().toString());
		}
	}

	@Test
	public void testAsResourceVisitor() throws Exception {
		IAggregator mockAggregator = EasyMock.createMock(IAggregator.class);
		EasyMock.expect(mockAggregator.runConverters(EasyMock.isA(FileResource.class))).andAnswer(new IAnswer<IResource>() {
			@Override
			public IResource answer() throws Throwable {
				return (IResource)EasyMock.getCurrentArguments()[0];
			}
		}).once();
		EasyMock.replay(mockAggregator);
		FileResource res = new FileResource(URI.create("file://foo/bar.js"));
		FileResource.VisitorResource visitorRes = res.asVisitorResource();
		IResource res2 = visitorRes.newResource(mockAggregator);
		EasyMock.verify(mockAggregator);
		Assert.assertEquals("file://foo/bar.js", res2.getURI().toString());
	}

}

@@ -1829,33 +1829,32 @@
 I.create(%22file:/
-/
 foo/bar.js%22));%0D%0A
@@ -2050,21 +2050,8 @@
 file
-://foo/bar.js
 %22, r
@@ -2059,34 +2059,213 @@
 s2.getURI().
-toString()
+getScheme());%0D%0A%09%09String path = res2.getURI().getPath();%0D%0A%09%09int idx = path.indexOf(%22:%22);%0D%0A%09%09if (idx != -1) %7B%0D%0A%09%09%09path = path.substring(idx+1);%0D%0A%09%09%7D%0D%0A%09%09Assert.assertEquals(%22/foo/bar.js%22, path
 );%0D%0A%09%7D%0D%0A%0D%0A%7D%0D

Fix unit test failure on Linux