public class JU_Persisting {
- private static final String resourceDirString = "src/test/resources";
- private static final String tokenDirString = "tokenDir";
- private static final String tokenFileName = "token";
+ private static final String resourceDirString = "src/test/resources";
+ private static final String tokenDirString = "tokenDir";
+ private static final String tokenFileName = "token";
- private static final int data = 5;
- private static final long expires = 10000;
+ private static final int data = 5;
+ private static final long expires = 10000;
- private static final byte[] cred = "password".getBytes();
+ private static final byte[] cred = "password".getBytes();
- private PropAccess access;
+ private PropAccess access;
- @Mock private Persist<Integer, ?> persistMock;
- @Mock private RosettaDF<Integer> dfMock;
- @Mock private RosettaData<Integer> dataMock;
+ @Mock private Persist<Integer, ?> persistMock;
+ @Mock private RosettaDF<Integer> dfMock;
+ @Mock private RosettaData<Integer> dataMock;
- @Before
- public void setup() throws APIException {
- MockitoAnnotations.initMocks(this);
+ @Before
+ public void setup() throws APIException {
+ MockitoAnnotations.initMocks(this);
- when(dfMock.newData()).thenReturn(dataMock);
- when(dataMock.load(data)).thenReturn(dataMock);
- when(dataMock.load((CipherInputStream)any())).thenReturn(dataMock);
+ when(dfMock.newData()).thenReturn(dataMock);
+ when(dataMock.load(data)).thenReturn(dataMock);
+ when(dataMock.load((CipherInputStream)any())).thenReturn(dataMock);
- access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
- access.setProperty(Config.CADI_TOKEN_DIR, resourceDirString);
+ access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
+ access.setProperty(Config.CADI_TOKEN_DIR, resourceDirString);
- persistMock.access = access;
- }
+ persistMock.access = access;
+ }
- @After
- public void tearDown() {
- File dir = new File(resourceDirString + '/' + tokenDirString);
- for (File f : dir.listFiles()) {
- f.delete();
- }
- dir.delete();
- }
+ @After
+ public void tearDown() {
+ File dir = new File(resourceDirString + '/' + tokenDirString);
+ for (File f : dir.listFiles()) {
+ f.delete();
+ }
+ dir.delete();
+ }
- @Test
- public void test() throws CadiException, APIException {
- Path tokenPath = Paths.get(resourceDirString, tokenDirString);
+ @Test
+ public void test() throws CadiException, APIException {
+ Path tokenPath = Paths.get(resourceDirString, tokenDirString);
- Persisting<Integer> persisting = new Persisting<>(persistMock, data, expires, cred, tokenPath);
- assertThat(persisting.get(), is(data));
- assertThat(persisting.expires(), is(expires));
- assertThat(persisting.expired(), is(true));
- assertThat(persisting.hasBeenTouched(), is(true));
+ Persisting<Integer> persisting = new Persisting<>(persistMock, data, expires, cred, tokenPath);
+ assertThat(persisting.get(), is(data));
+ assertThat(persisting.expires(), is(expires));
+ assertThat(persisting.expired(), is(true));
+ assertThat(persisting.hasBeenTouched(), is(true));
- PersistFile persistFile = new PersistFile(access, tokenDirString);
- tokenPath = persistFile.writeDisk(dfMock, data, cred, tokenFileName, expires);
- persisting = new Persisting<>(persistMock, data, expires, cred, tokenPath);
- assertThat(persisting.hasBeenTouched(), is(false));
+ PersistFile persistFile = new PersistFile(access, tokenDirString);
+ tokenPath = persistFile.writeDisk(dfMock, data, cred, tokenFileName, expires);
+ persisting = new Persisting<>(persistMock, data, expires, cred, tokenPath);
+ assertThat(persisting.hasBeenTouched(), is(false));
- persisting = new Persisting<>(persistMock, data, expires * (int)10e9, cred, tokenPath);
- assertThat(persisting.expired(), is(false));
+ persisting = new Persisting<>(persistMock, data, expires * (int)10e9, cred, tokenPath);
+ assertThat(persisting.expired(), is(false));
- assertThat(persisting.checkSyncTime(), is(true));
- assertThat(persisting.checkSyncTime(), is(false));
+ assertThat(persisting.checkSyncTime(), is(true));
+ assertThat(persisting.checkSyncTime(), is(false));
- assertThat(persisting.checkReloadable(), is(false));
+ assertThat(persisting.checkReloadable(), is(false));
- assertThat(persisting.getHash(), is(cred));
+ assertThat(persisting.getHash(), is(cred));
- assertThat(persisting.match(null), is(false));
- assertThat(persisting.match("random!".getBytes()), is(false));
- assertThat(persisting.match("passwrod".getBytes()), is(false));
- assertThat(persisting.match(cred), is(true));
+ assertThat(persisting.match(null), is(false));
+ assertThat(persisting.match("random!".getBytes()), is(false));
+ assertThat(persisting.match("passwrod".getBytes()), is(false));
+ assertThat(persisting.match(cred), is(true));
- persisting.clearCount();
- assertThat(persisting.count(), is(0));
- persisting.inc();
- assertThat(persisting.count(), is(1));
+ persisting.clearCount();
+ assertThat(persisting.count(), is(0));
+ persisting.inc();
+ assertThat(persisting.count(), is(1));
- assertThat(persisting.path(), is(tokenPath));
- }
+ assertThat(persisting.path(), is(tokenPath));
+ }
}