<commit_before>package com.github.agfsapi4j;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class GlusterFsSessionTest
{
	private static final long CONNECTED_SESSION_ID = 1;

	private static final long OPENED_FILE_ID = 2;

	@InjectMocks
	private GlusterFsSession session;

	@Mock
	private LogAccess logAccess;

	@Mock
	private ResourceTracker resourceTracker;

	@Mock
	private LibGfapi lib;

	@Test
	public void openedFileIsTracked()
	{
		givenAConnectedSession();
		givenOpenSucceeds("aPath");

		GlusterFsFile file = session.openFile("aPath", 0);

		verify(resourceTracker).allocated(file);
	}

	private void givenOpenSucceeds(String aPath)
	{
		when(lib.glfs_open(CONNECTED_SESSION_ID, aPath, 0)).thenReturn(OPENED_FILE_ID);
	}

	private void givenAConnectedSession()<commit_msg>Added test that created files are tracked.<commit_after>package com.github.agfsapi4j;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class GlusterFsSessionTest
{
	private static final long CONNECTED_SESSION_ID = 1;

	private static final long OPENED_FILE_ID = 2;

	@InjectMocks
	private GlusterFsSession session;

	@Mock
	private LogAccess logAccess;

	@Mock
	private ResourceTracker resourceTracker;

	@Mock
	private LibGfapi lib;

	@Test
	public void openedFileIsTracked()
	{
		givenAConnectedSession();
		givenOpenSucceeds("aPath");

		GlusterFsFile file = session.openFile("aPath", 0);

		verify(resourceTracker).allocated(file);
	}

	@Test
	public void createdFileIsTracked()
	{
		givenAConnectedSession();
		givenCreateSucceeds("aPath");

		GlusterFsFile file = session.createFile("aPath", 0, 0);

		verify(resourceTracker).allocated(file);
	}

	private void givenCreateSucceeds(String aPath)
	{
		when(lib.glfs_creat(CONNECTED_SESSION_ID, aPath, 0, 0)).thenReturn(OPENED_FILE_ID);
	}

	private void givenOpenSucceeds(String aPath)
	{
		when(lib.glfs_open(CONNECTED_SESSION_ID, aPath, 0)).thenReturn(OPENED_FILE_ID);
	}

	private void givenAConnectedSession()
{'fraction_non_alphanumeric': 0.09440842787682334, 'fraction_numerical': 0.005672609400324149, 'mean_word_length': 6.014204545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '530372', 'n_tokens_mistral': 903, 'n_tokens_neox': 840, 'n_words': 170}