blob: 59298fabf8c23eef3cf8a96d560e64a31225c12b [file] [log] [blame]
/*
* Copyright (c) 2012 Google Inc.
*
* All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.protoc.command;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
import java.io.File;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
/**
* Tests for <code>{@link ImportRootsProtocOption#singleImportRoot(File, File)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
public class ImportRootsProtocOption_singleImportRoot_Test {
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File project;
@Before public void setUp() {
project = temporaryFolder.newFolder("project");
}
@Test public void should_return_project_directory_if_file_is_underneath_it() {
File protoFile = new File(project, "test.proto");
String singleImportRoot = ImportRootsProtocOption.singleImportRoot(project, protoFile);
assertThat(singleImportRoot, equalTo(project.toString()));
}
@Test public void should_return_parent_directory_directly_below_project() {
File srcDirectory = createDirectory(project, "src");
File protoFile = new File(createDirectory(srcDirectory, "proto"), "test.proto");
String singleImportRoot = ImportRootsProtocOption.singleImportRoot(project, protoFile);
assertThat(singleImportRoot, equalTo(srcDirectory.toString()));
}
private File createDirectory(File parent, String name) {
File directory = new File(parent, name);
assertTrue(directory.mkdir());
return directory;
}
}