SaveRecord extends Action { void save(final String providerKey, final String dynamicKey, final String dynamicKeyGroup, final Object data, final Long lifeTime, final boolean isExpirable, final boolean isEncrypted) { String composedKey = composeKey(providerKey, dynamicKey, dynamicKeyGroup); Record record = new Record(data, isExpirable, lifeTime); memory.put(composedKey, record); if (persistence.storedMB() >= maxMgPersistenceCache) { System.out.println(Locale.RECORD_CAN_NOT_BE_PERSISTED_BECAUSE_WOULD_EXCEED_THRESHOLD_LIMIT); } else { persistence.saveRecord(composedKey, record, isEncrypted, encryptKey); } evictExpirableRecordsPersistence.startTaskIfNeeded(isEncrypted); } @Inject  SaveRecord(Memory memory, Persistence persistence, Integer maxMgPersistenceCache,
      io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence evictExpirableRecordsPersistence, String encryptKey);   }
@Test @Theory public void When_Max_Persistence_Exceed_Do_Not_Persists_Data(Integer maxMB) { saveRecordUT = new SaveRecord(memory, disk, maxMB, new io.rx_cache2.internal.cache.EvictExpirableRecordsPersistence(memory, disk, 100, null), null); int records = 250; for (int i = 0; i < records; i++) { saveRecordUT.save(i+"", "", "", createMocks(records), null, true, false); } assertTrue("storedMB minor or equal than " + maxMB, disk.storedMB() <= maxMB); assertThat(memory.keySet().size(), is(records)); }