// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int SUCCESS = 0;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/DirectoryFiller.java
// public interface DirectoryFiller {
// 
// 	int add(String name, Path path)
// 			throws IOException;
// 
// 	int addWithExtraSize(String name, Path path, long extraSize)
// 			throws IOException;
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/FileHandleFiller.java
// @FunctionalInterface
// public interface FileHandleFiller {
// 
// 	void setFileHandle(int fileHandle);
// 
// 	public static class Recorder implements FileHandleFiller {
// 
// 		private final FileHandleFiller delegate;
// 		private int fileHandle = -1;
// 
// 		public static Recorder wrap(FileHandleFiller filler) {
// 			return new Recorder(filler);
// 		}
// 
// 		private Recorder(FileHandleFiller filler) {
// 			this.delegate = filler;
// 		}
// 
// 		public int getFileHandle() {
// 			return fileHandle;
// 		}
// 
// 		@Override
// 		public void setFileHandle(int fileHandle) {
// 			this.fileHandle = fileHandle;
// 			delegate.setFileHandle(fileHandle);
// 		}
// 	}
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/StatFiller.java
// public interface StatFiller {
// 
// 	UnixFileStat stat(Path path)
// 			throws IOException;
// 
// 	UnixFileStat statWithSize(Path path, Function<FileInfo, Optional<Long>> sizeGetter, Supplier<Long> extraSizeGetter)
// 			throws IOException;
// }


import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.AdditionalMatchers.gt;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static se.tfiskgul.mux2fs.Constants.SUCCESS;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import ru.serce.jnrfuse.ErrorCodes;
import se.tfiskgul.mux2fs.fs.base.DirectoryFiller;
import se.tfiskgul.mux2fs.fs.base.FileHandleFiller;
import se.tfiskgul.mux2fs.fs.base.StatFiller;

	@Test
	public void testReadLinkLongNameIsTruncated()
			throws Exception {
		// Given
		Path fooBar = mockPath("foo.bar");
		Path target = mockPath("ThisIsALongName");
		when(fileSystem.provider().readSymbolicLink(fooBar)).thenReturn(target);
		// When
		int result = fs.readLink("foo.bar", (name) -> assertThat(name).isEqualTo("ThisI"), 5);
		// Then
		assertThat(result).isEqualTo(SUCCESS);
	}

	@Test
	public void testReleaseClosesOpenFileChannel()
			throws Exception {
		// Given
		FileHandleFiller filler = mock(FileHandleFiller.class);
		ArgumentCaptor<Integer> handleCaptor = ArgumentCaptor.forClass(Integer.class);
		doNothing().when(filler).setFileHandle(handleCaptor.capture());
		Path fooBar = mockPath(mirrorRoot, "foo.bar");
		FileChannel fileChannel = mock(FileChannel.class);
		when(fileSystem.provider().newFileChannel(eq(fooBar), eq(set(StandardOpenOption.READ)))).thenReturn(fileChannel);
		fs.open("foo.bar", filler);
		// When
		int result = fs.release("foo.bar", handleCaptor.getValue());
		// Then
		assertThat(result).isEqualTo(SUCCESS);
		verify(fileChannelCloser).close(fileChannel);
// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int SUCCESS = 0;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/DirectoryFiller.java
// public interface DirectoryFiller {
// 
// 	int add(String name, Path path)
// 			throws IOException;
// 
// 	int addWithExtraSize(String name, Path path, long extraSize)
// 			throws IOException;
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/FileHandleFiller.java
// @FunctionalInterface
// public interface FileHandleFiller {
// 
// 	void setFileHandle(int fileHandle);
// 
// 	public static class Recorder implements FileHandleFiller {
// 
// 		private final FileHandleFiller delegate;
// 		private int fileHandle = -1;
// 
// 		public static Recorder wrap(FileHandleFiller filler) {
// 			return new Recorder(filler);
// 		}
// 
// 		private Recorder(FileHandleFiller filler) {
// 			this.delegate = filler;
// 		}
// 
// 		public int getFileHandle() {
// 			return fileHandle;
// 		}
// 
// 		@Override
// 		public void setFileHandle(int fileHandle) {
// 			this.fileHandle = fileHandle;
// 			delegate.setFileHandle(fileHandle);
// 		}
// 	}
// }
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/StatFiller.java
// public interface StatFiller {
// 
// 	UnixFileStat stat(Path path)
// 			throws IOException;
// 
// 	UnixFileStat statWithSize(Path path, Function<FileInfo, Optional<Long>> sizeGetter, Supplier<Long> extraSizeGetter)
// 			throws IOException;
// }


// Path: core/src/test/java/se/tfiskgul/mux2fs/fs/mirror/MirrorFsTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.AdditionalMatchers.gt;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static se.tfiskgul.mux2fs.Constants.SUCCESS;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import ru.serce.jnrfuse.ErrorCodes;
import se.tfiskgul.mux2fs.fs.base.DirectoryFiller;
import se.tfiskgul.mux2fs.fs.base.FileHandleFiller;
import se.tfiskgul.mux2fs.fs.base.StatFiller;


	@Test
	public void testReadLinkLongNameIsTruncated()
			throws Exception {
		// Given
		Path fooBar = mockPath("foo.bar");
		Path target = mockPath("ThisIsALongName");
		when(fileSystem.provider().readSymbolicLink(fooBar)).thenReturn(target);
		// When
		int result = fs.readLink("foo.bar", (name) -> assertThat(name).isEqualTo("ThisI"), 5);
		// Then
		assertThat(result).isEqualTo(SUCCESS);
	}

	@Test
	public void testReleaseClosesOpenFileChannel()
			throws Exception {
		// Given
		FileHandleFiller filler = mock(FileHandleFiller.class);
		ArgumentCaptor<Integer> handleCaptor = ArgumentCaptor.forClass(Integer.class);
		doNothing().when(filler).setFileHandle(handleCaptor.capture());
		Path fooBar = mockPath(mirrorRoot, "foo.bar");
		FileChannel fileChannel = mock(FileChannel.class);
		when(fileSystem.provider().newFileChannel(eq(fooBar), eq(set(StandardOpenOption.READ)))).thenReturn(fileChannel);
		fs.open("foo.bar", filler);
		// When
		int result = fs.release("foo.bar", handleCaptor.getValue());
		// Then
		assertThat(result).isEqualTo(SUCCESS);
		verify(fileChannelCloser).close(fileChannel);
		verifyNoMoreInteractions(fileChannel);