-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/com/jetbrains/jacobfs/tree/TreeLocatorEncoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.jetbrains.jacobfs.tree; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.file.FileAlreadyExistsException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
class TreeLocatorEncoderTest { | ||
|
||
@Test | ||
void shouldThrowIfTreeLocatorTooBig() { | ||
TreeLocatorMetadata mockedTLM = mock(TreeLocatorMetadata.class); | ||
int reservedSpace = 8; | ||
when(mockedTLM.getTreeLocatorReservedSpace()).thenReturn(reservedSpace); | ||
|
||
TreeLocatorEncoder treeLocatorEncoder = spy(new TreeLocatorEncoder()); | ||
doReturn(new String(new byte[reservedSpace + 1])).when(treeLocatorEncoder).encode(any()); | ||
assertThrows(RuntimeException.class, | ||
() -> treeLocatorEncoder.saveTreeLocatorToFile(new RootNode(), mockedTLM)); | ||
} | ||
|
||
@Test | ||
void shouldEncodeDecode() throws FileAlreadyExistsException { | ||
DirNode lvl31 = new DirNode("lvl3"); | ||
lvl31.addFileNode(new FileNode("31.txt", 0L, 8)); | ||
lvl31.addFileNode(new FileNode("32.txt", 8L, 16)); | ||
|
||
DirNode lvl32 = new DirNode("lvl3"); | ||
lvl32.addFileNode(new FileNode("33.txt", 16L, 24)); | ||
|
||
DirNode lvl2 = new DirNode("lvl2"); | ||
lvl2.addDirNode(lvl31); | ||
lvl2.addDirNode(lvl32); | ||
lvl2.addFileNode(new FileNode("34.dll", 24L, 32)); | ||
|
||
DirNode lvl1 = new DirNode("lvl1"); | ||
lvl1.addDirNode(lvl2); | ||
|
||
RootNode rootNode = new RootNode(); | ||
rootNode.addDirNode(lvl1); | ||
rootNode.addFileNode(new FileNode("35.lock", 32L, 40)); | ||
|
||
TreeLocatorEncoder treeLocatorEncoder = new TreeLocatorEncoder(); | ||
TreeLocatorDecoder treeLocatorDecoder = new TreeLocatorDecoder(); | ||
String encoded1 = treeLocatorEncoder.encode(rootNode); | ||
RootNode decoded1 = treeLocatorDecoder.decode(encoded1); | ||
String encoded2 = treeLocatorEncoder.encode(decoded1); | ||
assertEquals(encoded1, encoded2); | ||
} | ||
} |