2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
6 package com.threerings.getdown.data;
9 import java.io.IOException;
10 import java.nio.file.Path;
11 import java.util.Arrays;
14 import org.junit.rules.TemporaryFolder;
15 import org.junit.runner.RunWith;
16 import static org.junit.Assert.assertEquals;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import static org.mockito.Mockito.when;
22 @RunWith(MockitoJUnitRunner.class)
23 public class PathBuilderTest
25 @Before public void setupFilesAndResources () throws IOException
27 _firstJarFile = _appdir.newFile("a.jar");
28 _secondJarFile = _appdir.newFile("b.jar");
30 when(_firstJar.getFinalTarget()).thenReturn(_firstJarFile);
31 when(_secondJar.getFinalTarget()).thenReturn(_secondJarFile);
32 when(_application.getActiveCodeResources()).thenReturn(Arrays.asList(_firstJar, _secondJar));
33 when(_application.getAppDir()).thenReturn(_appdir.getRoot());
36 @Test public void shouldBuildDefaultClassPath () throws IOException
38 ClassPath classPath = PathBuilder.buildDefaultClassPath(_application);
39 String expectedClassPath = _firstJarFile.getAbsolutePath() + File.pathSeparator +
40 _secondJarFile.getAbsolutePath();
41 assertEquals(expectedClassPath, classPath.asArgumentString());
44 @Test public void shouldBuildCachedClassPath () throws IOException
46 when(_application.getDigest(_firstJar)).thenReturn("first");
47 when(_application.getDigest(_secondJar)).thenReturn("second");
48 when(_application.getCodeCacheRetentionDays()).thenReturn(1);
50 Path firstCachedJarFile = _appdir.getRoot().toPath().
51 resolve(PathBuilder.CODE_CACHE_DIR).resolve("fi").resolve("first.jar");
53 Path secondCachedJarFile = _appdir.getRoot().toPath().
54 resolve(PathBuilder.CODE_CACHE_DIR).resolve("se").resolve("second.jar");
56 String expectedClassPath = firstCachedJarFile.toAbsolutePath() + File.pathSeparator +
57 secondCachedJarFile.toAbsolutePath();
59 ClassPath classPath = PathBuilder.buildCachedClassPath(_application);
60 assertEquals(expectedClassPath, classPath.asArgumentString());
63 @Mock protected Application _application;
64 @Mock protected Resource _firstJar;
65 @Mock protected Resource _secondJar;
67 protected File _firstJarFile, _secondJarFile;
69 @Rule public TemporaryFolder _appdir = new TemporaryFolder();