Skip to content

Commit

Permalink
GradleUtil test.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-wyluda committed Jul 5, 2013
1 parent d62802b commit 9725772
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static String removeRepository(String source, String name, String url)
return source;
}

// There is no way to remove task because tasks are composed of many actions
// so we can only insert new tasks
public static String insertTask(String source, String name, List<String> dependsOn, String type, String code)
{
// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,176 @@
*/
package org.jboss.forge.addon.gradle.parser;

import static org.junit.Assert.assertEquals;

import org.gradle.jarjar.com.google.common.collect.Lists;
import org.jboss.forge.addon.gradle.projects.exceptions.UnremovableElementException;
import org.junit.Ignore;
import org.junit.Test;

/**
* @author Adam Wyłuda
*/
public class GradleUtilTest
{
@Test
public void testInsertDependency()
{
String source = "" +
"dependencies {\n" +
" compile 'a:b:1.0'\n" +
"}";
String expected = "" +
"dependencies {\n" +
" compile 'a:b:1.0'\n" +
" testRuntime 'x:y:3.0'\n" +
"}";
String result = GradleUtil.insertDependency(source, "y", "x", "3.0", "testRuntime");
assertEquals(expected, result);
}

@Test
public void testRemoveDependency() throws UnremovableElementException
{
String source = "" +
"dependencies {\n" +
" compile 'a:b:1.0'\n" +
"}";
String expected = "" +
"dependencies {\n" +
"}";
String result = GradleUtil.removeDependency(source, "b", "a", "1.0", "compile");
assertEquals(expected, result);
}

@Test(expected = UnremovableElementException.class)
public void testRemoveDependencyForException() throws UnremovableElementException
{
String source = "" +
"dependencies {\n" +
" def alias = compile" +
" alias 'a:b:1.0'\n" +
"}";
GradleUtil.removeDependency(source, "b", "a", "1.0", "compile");
}

@Test
public void testInsertPlugin()
{
String source = "" +
"version = '4.0'\n" +
"\n" +
"apply plugin: 'java'\n" +
"\n" +
"repositories {}\n";
String expected = "" +
"version = '4.0'\n" +
"\n" +
"apply plugin: 'java'\n" +
"apply plugin: 'groovy'\n" +
"\n" +
"repositories {}\n";
String result = GradleUtil.insertPlugin(source, "groovy");
assertEquals(expected, result);
}

@Test
public void testRemovePlugin() throws UnremovableElementException
{
String source = "" +
"version = '4.0'\n" +
"\n" +
"apply plugin: 'java'\n" +
"\n" +
"repositories {}\n";
String expected = "" +
"version = '4.0'\n" +
"\n" +
"\n" +
"repositories {}\n";
String result = GradleUtil.removePlugin(source, "java");
assertEquals(expected, result);
}

@Test(expected = UnremovableElementException.class)
public void testRemovePluginForException() throws UnremovableElementException
{
String source = "" +
"version = '4.0'\n" +
"\n" +
"\n" +
"repositories {}\n";
GradleUtil.removePlugin(source, "scala");
}

@Test
public void testInsertRepository()
{
String source = "" +
"repositories {\n" +
"}";
String expected = "" +
"repositories {\n" +
" maven {\n" +
" url 'http://repo.com\n" +
" }\n" +
"}";
String result = GradleUtil.insertRepository(source, "", "http://repo.com");
assertEquals(expected, result);
}

@Test
public void testRemoveRepository() throws UnremovableElementException
{
String source = "" +
"repositories {\n" +
" maven {\n" +
" url 'http://repo.com\n" +
" }\n" +
"}";
String expected = "" +
"repositories {\n" +
"}";
String result = GradleUtil.removeRepository(source, "", "http://repo.com");
assertEquals(expected, result);
}

@Test(expected = UnremovableElementException.class)
public void testRemoveRepositoryForException() throws UnremovableElementException
{
String source = "" +
"repositories {\n" +
"}";
GradleUtil.removeRepository(source, "", "http://repo.com");
}

@Test
public void testInsertTask()
{
String source = "" +
"task abcd << {\n" +
" println 'ABCD!!'\n" +
"}\n";
String expected = "" +
"task abcd << {\n" +
" println 'ABCD!!'\n" +
"}\n" +
"\n" +
"task efgh << {\n" +
" def variable = 10\n" +
" println variable\n" +
"}\n";
String result = GradleUtil.insertTask(source, "efgh", Lists.<String> newArrayList(), "", "" +
"\n" +
" def variable = 10\n" +
" println variable\n");
assertEquals(expected, result);
}

@Test
@Ignore
public void testCheckForIncludeProfileAndInsert()
{
// TODO implement test
}
}

1 comment on commit 9725772

@lincolnthree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adam, this is really good. Very comprehensive. I'm more and more impressed every day :)

Please sign in to comment.