Browse Source

More isEmpty(), less assertThat()

master
Gintas Grigelionis 7 years ago
parent
commit
6eefa0f435
5 changed files with 41 additions and 49 deletions
  1. +19
    -10
      src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
  2. +3
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
  3. +2
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
  4. +10
    -16
      src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java
  5. +7
    -11
      src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java

+ 19
- 10
src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java View File

@@ -49,7 +49,8 @@ public class HeadTailTest {
buildRule.executeTarget("testHead"); buildRule.executeTarget("testHead");
File expected = buildRule.getProject().resolveFile("expected/head-tail.head.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.head.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.head.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.head.test");
assertEquals("testHead: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testHead: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -57,7 +58,8 @@ public class HeadTailTest {
buildRule.executeTarget("testHeadLines"); buildRule.executeTarget("testHeadLines");
File expected = buildRule.getProject().resolveFile("expected/head-tail.headLines.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.headLines.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLines.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLines.test");
assertEquals("testHeadLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testHeadLines: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -65,7 +67,8 @@ public class HeadTailTest {
buildRule.executeTarget("testHeadSkip"); buildRule.executeTarget("testHeadSkip");
File expected = buildRule.getProject().resolveFile("expected/head-tail.headSkip.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.headSkip.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headSkip.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headSkip.test");
assertEquals("testHeadSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testHeadSkip: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -73,7 +76,8 @@ public class HeadTailTest {
buildRule.executeTarget("testHeadLinesSkip"); buildRule.executeTarget("testHeadLinesSkip");
File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLinesSkip.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLinesSkip.test");
assertEquals("testHeadLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testHeadLinesSkip: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -88,9 +92,10 @@ public class HeadTailTest {
@Test @Test
public void testTail() throws IOException { public void testTail() throws IOException {
buildRule.executeTarget("testTail"); buildRule.executeTarget("testTail");
File expected =buildRule.getProject().resolveFile("expected/head-tail.tail.test");
File expected = buildRule.getProject().resolveFile("expected/head-tail.tail.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tail.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tail.test");
assertEquals("testTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testTail: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -98,7 +103,8 @@ public class HeadTailTest {
buildRule.executeTarget("testTailLines"); buildRule.executeTarget("testTailLines");
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLines.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLines.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLines.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLines.test");
assertEquals("testTailLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testTailLines: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -106,7 +112,8 @@ public class HeadTailTest {
buildRule.executeTarget("testTailSkip"); buildRule.executeTarget("testTailSkip");
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailSkip.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.tailSkip.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailSkip.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailSkip.test");
assertEquals("testTailSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testTailSkip: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -114,7 +121,8 @@ public class HeadTailTest {
buildRule.executeTarget("testTailLinesSkip"); buildRule.executeTarget("testTailLinesSkip");
File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLinesSkip.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLinesSkip.test");
assertEquals("testTailLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testTailLinesSkip: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


@Test @Test
@@ -131,7 +139,8 @@ public class HeadTailTest {
buildRule.executeTarget("testHeadTail"); buildRule.executeTarget("testHeadTail");
File expected = buildRule.getProject().resolveFile("expected/head-tail.headtail.test"); File expected = buildRule.getProject().resolveFile("expected/head-tail.headtail.test");
File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headtail.test"); File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headtail.test");
assertEquals("testHeadTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
assertEquals("testHeadTail: Result not like expected",
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
} }


} }

+ 3
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java View File

@@ -425,7 +425,7 @@ public class AntTest {
} }


public void targetStarted(BuildEvent event) { public void targetStarted(BuildEvent event) {
if (event.getTarget().getName().equals("")) {
if (event.getTarget().getName().isEmpty()) {
return; return;
} }
if (error == null) { if (error == null) {
@@ -476,7 +476,7 @@ public class AntTest {
} }


public void targetStarted(BuildEvent event) { public void targetStarted(BuildEvent event) {
if (event.getTarget().getName().equals("")) {
if (event.getTarget().getName().isEmpty()) {
return; return;
} }
if (error == null) { if (error == null) {
@@ -602,7 +602,7 @@ public class AntTest {
} }


public void targetStarted(BuildEvent event) { public void targetStarted(BuildEvent event) {
if (event.getTarget().getName().equals("")) {
if (event.getTarget().getName().isEmpty()) {
return; return;
} }
if (calls >= expectedValues.length) { if (calls >= expectedValues.length) {


+ 2
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java View File

@@ -32,7 +32,6 @@ import java.io.InputStream;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;


/** /**
*/ */
@@ -83,14 +82,8 @@ public class BZip2Test {
while (true) { while (true) {
int expected = originalIn.read(); int expected = originalIn.read();
int actual = actualIn.read(); int actual = actualIn.read();
if (expected >= 0) {
if (expected != actual) {
fail("File content mismatch");
}
} else {
if (actual >= 0) {
fail("File content mismatch");
}
assertEquals("File content mismatch", expected, actual);
if (expected < 0) {
break; break;
} }
} }


+ 10
- 16
src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java View File

@@ -24,16 +24,16 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;


public class EchoXMLTest { public class EchoXMLTest {


@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml");
@@ -51,22 +51,16 @@ public class EchoXMLTest {


@Test @Test
public void testFail() { public void testFail() {
try {
buildRule.executeTarget("testFail");
fail("BuildException expected: must fail");
} catch (BuildException ex) {
assertThat(ex.getMessage(), containsString("${foo}=bar"));
}
thrown.expect(BuildException.class);
thrown.expectMessage("${foo}=bar");
buildRule.executeTarget("testFail");
} }


@Test @Test
public void testEmpty() { public void testEmpty() {
try {
buildRule.executeTarget("testEmpty");
fail("BuildException expected: must fail");
} catch (BuildException ex) {
assertThat(ex.getMessage(), containsString("No nested XML specified"));
}
thrown.expect(BuildException.class);
thrown.expectMessage("No nested XML specified");
buildRule.executeTarget("testEmpty");
} }


} }

+ 7
- 11
src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java View File

@@ -22,10 +22,7 @@ import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;


/** /**
* Test that scripting selection works. Needs scripting support to work * Test that scripting selection works. Needs scripting support to work
@@ -35,6 +32,9 @@ public class ScriptSelectorTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public ExpectedException thrown = ExpectedException.none();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml"); buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml");
@@ -42,13 +42,9 @@ public class ScriptSelectorTest {


@Test @Test
public void testNolanguage() { public void testNolanguage() {
try {
buildRule.executeTarget("testNolanguage");
fail("Absence of language attribute not detected");
} catch (BuildException ex) {
assertThat(ex.getMessage(), containsString("script language must be specified"));

}
thrown.expect(BuildException.class);
thrown.expectMessage("script language must be specified");
buildRule.executeTarget("testNolanguage");
} }


@Test @Test


Loading…
Cancel
Save