class FileSystemOperations {

  public void validFileSize(String uri) throws IOException {
    boolean remote = remoteDirectoryManager.isRemote(uri);
    long actualSizeInBytes = getFileSizeInBytes(uri, remote);
    long maxFileSizeInBytes = convertToBytes(getMaxRemoteFileSizeMB());

    String locationType = remote ? "Remote" : "Local";
    LOG.info("{} file / directory path is {} with size: {} bytes."
        + " Allowed maximum file / directory size is {} bytes.",
        locationType, uri, actualSizeInBytes, maxFileSizeInBytes);

    if (actualSizeInBytes > maxFileSizeInBytes) {
      throw new IOException(
          String.format("Size of file / directory %s: %d bytes. " +
              "This exceeded the configured maximum " +
              "file / directory size, which is %d bytes.",
              uri, actualSizeInBytes, maxFileSizeInBytes));
    }
  }

}

class FileSystemOperationsTest {

  private static final String TARGET_ZIP_FILE;
  private static final String TARGET_ZIP_DIR;
  @Rule
  public ExpectedException expectedException;
  private FileUtilitiesForTests fileUtils;
  private FileSystemOperations fileSystemOperations;
  private Path stagingDir;

  @Test
  public void testValidFileSize() throws IOException {

    ClientContext clientContext = mock(ClientContext.class);

    RemoteDirectoryManager remoteDirectoryManager =
        mock(RemoteDirectoryManager.class);
    when(clientContext.getRemoteDirectoryManager())
        .thenReturn(remoteDirectoryManager);
    when(remoteDirectoryManager.isRemote(anyString())).thenReturn(true);
    when(remoteDirectoryManager.getRemoteFileSize(anyString()))
        .thenReturn(20000L);

    SubmarineConfiguration config =
        SubmarineConfiguration.newInstance();
    config.setLong(SubmarineConfVars
        .ConfVars.SUBMARINE_LOCALIZATION_MAX_ALLOWED_FILE_SIZE_MB, 21L);
    when(clientContext.getSubmarineConfig()).thenReturn(config);

    fileSystemOperations = new FileSystemOperations(clientContext);
  }

}