#vulnerable code 
                                @Test
    public void testStore2() throws IOException {
        StorageWorker storageWorker = new StorageWorker(averageAggregator, reportingFolder, new DBManager(null));

        ConcurrentHashMap<AggregationKey, AggregationValue> map = new ConcurrentHashMap<>();

        long ts = getTS() / AverageAggregator.HOUR;

        AggregationKey aggregationKey = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts);
        AggregationValue aggregationValue = new AggregationValue();
        aggregationValue.update(100);
        AggregationKey aggregationKey2 = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts - 1);
        AggregationValue aggregationValue2 = new AggregationValue();
        aggregationValue2.update(150.54);
        AggregationKey aggregationKey3 = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts - 2);
        AggregationValue aggregationValue3 = new AggregationValue();
        aggregationValue3.update(200);

        map.put(aggregationKey, aggregationValue);
        map.put(aggregationKey2, aggregationValue2);
        map.put(aggregationKey3, aggregationValue3);

        when(averageAggregator.getMinute()).thenReturn(new ConcurrentHashMap<>());
        when(averageAggregator.getHourly()).thenReturn(map);
        when(averageAggregator.getDaily()).thenReturn(new ConcurrentHashMap<>());

        storageWorker.run();

        assertTrue(Files.exists(Paths.get(reportingFolder, "test", generateFilename(1, PinType.ANALOG, (byte) 1, GraphType.HOURLY))));

        //take less
        byte[] data = ReportingDao.getAllFromDisk(reportingFolder, "test", 1, PinType.ANALOG, (byte) 1, 1, GraphType.HOURLY);
        ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        assertNotNull(data);
        assertEquals(16, data.length);

        assertEquals(100.0, byteBuffer.getDouble(), 0.001);
        assertEquals(ts * AverageAggregator.HOUR, byteBuffer.getLong());


        //take more
        data = ReportingDao.getAllFromDisk(reportingFolder, "test", 1, PinType.ANALOG, (byte) 1, 24, GraphType.HOURLY);
        byteBuffer = ByteBuffer.wrap(data);
        assertNotNull(data);
        assertEquals(48, data.length);

        assertEquals(200.0, byteBuffer.getDouble(), 0.001);
        assertEquals((ts - 2) * AverageAggregator.HOUR, byteBuffer.getLong());

        assertEquals(150.54, byteBuffer.getDouble(), 0.001);
        assertEquals((ts - 1) * AverageAggregator.HOUR, byteBuffer.getLong());

        assertEquals(100.0, byteBuffer.getDouble(), 0.001);
        assertEquals(ts * AverageAggregator.HOUR, byteBuffer.getLong());
    } 
                            #location 27 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testStore2() throws IOException {
        StorageWorker storageWorker = new StorageWorker(averageAggregator, reportingFolder, new DBManager());

        ConcurrentHashMap<AggregationKey, AggregationValue> map = new ConcurrentHashMap<>();

        long ts = getTS() / AverageAggregator.HOUR;

        AggregationKey aggregationKey = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts);
        AggregationValue aggregationValue = new AggregationValue();
        aggregationValue.update(100);
        AggregationKey aggregationKey2 = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts - 1);
        AggregationValue aggregationValue2 = new AggregationValue();
        aggregationValue2.update(150.54);
        AggregationKey aggregationKey3 = new AggregationKey("test", 1, PinType.ANALOG, (byte) 1, ts - 2);
        AggregationValue aggregationValue3 = new AggregationValue();
        aggregationValue3.update(200);

        map.put(aggregationKey, aggregationValue);
        map.put(aggregationKey2, aggregationValue2);
        map.put(aggregationKey3, aggregationValue3);

        when(averageAggregator.getMinute()).thenReturn(new ConcurrentHashMap<>());
        when(averageAggregator.getHourly()).thenReturn(map);
        when(averageAggregator.getDaily()).thenReturn(new ConcurrentHashMap<>());

        storageWorker.run();

        assertTrue(Files.exists(Paths.get(reportingFolder, "test", generateFilename(1, PinType.ANALOG, (byte) 1, GraphType.HOURLY))));

        //take less
        byte[] data = ReportingDao.getAllFromDisk(reportingFolder, "test", 1, PinType.ANALOG, (byte) 1, 1, GraphType.HOURLY);
        ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        assertNotNull(data);
        assertEquals(16, data.length);

        assertEquals(100.0, byteBuffer.getDouble(), 0.001);
        assertEquals(ts * AverageAggregator.HOUR, byteBuffer.getLong());


        //take more
        data = ReportingDao.getAllFromDisk(reportingFolder, "test", 1, PinType.ANALOG, (byte) 1, 24, GraphType.HOURLY);
        byteBuffer = ByteBuffer.wrap(data);
        assertNotNull(data);
        assertEquals(48, data.length);

        assertEquals(200.0, byteBuffer.getDouble(), 0.001);
        assertEquals((ts - 2) * AverageAggregator.HOUR, byteBuffer.getLong());

        assertEquals(150.54, byteBuffer.getDouble(), 0.001);
        assertEquals((ts - 1) * AverageAggregator.HOUR, byteBuffer.getLong());

        assertEquals(100.0, byteBuffer.getDouble(), 0.001);
        assertEquals(ts * AverageAggregator.HOUR, byteBuffer.getLong());
    }