blob: 9a2ada2bebe3228714ac6bedc8edca53efcd30f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.file;
import org.junit.Test;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class FileAttributesCacheTest {
@Test
public void exists() {
UnixPath unixPath = mock(UnixPath.class);
FileAttributesCache cache = new FileAttributesCache(unixPath);
when(unixPath.getAttributesIfExists()).thenReturn(Optional.empty());
assertFalse(cache.get().isPresent());
verify(unixPath, times(1)).getAttributesIfExists();
verifyNoMoreInteractions(unixPath);
FileAttributes attributes = mock(FileAttributes.class);
when(unixPath.getAttributesIfExists()).thenReturn(Optional.of(attributes));
assertTrue(cache.get().isPresent());
verify(unixPath, times(1 + 1)).getAttributesIfExists();
verifyNoMoreInteractions(unixPath);
assertEquals(attributes, cache.getOrThrow());
verifyNoMoreInteractions(unixPath);
}
}
|