forked from twitter/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude org.hamcrest from the shading rules for junit runner
The shading of the junit runner specifically excludes the org.junit classes. As it turns out, we also need to exempt the org.hamcrest classes so that APIs work correctly. Testing Done: CI is running at: https://travis-ci.org/pantsbuild/pants/builds/60578769 We use 'assertThat' a fair amount in our code base. This change fixes those problems. Bugs closed: 1466, 1467 Reviewed at https://rbcommons.com/s/twitter/r/2137/
- Loading branch information
1 parent
17c3925
commit 35a513b
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
testprojects/tests/java/org/pantsbuild/testproject/matcher/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
|
||
junit_tests(name='matcher', | ||
sources=['MatcherTest.java'], | ||
dependencies=[ | ||
'3rdparty:junit', | ||
], | ||
) |
47 changes: 47 additions & 0 deletions
47
testprojects/tests/java/org/pantsbuild/testproject/matcher/MatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
// Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
package org.pantsbuild.testproject.matcher; | ||
|
||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* This test insures that the junit and hamcrest classes work for a junit test. | ||
*/ | ||
public class MatcherTest { | ||
|
||
class FooMatcher extends BaseMatcher<String> { | ||
|
||
@Override public boolean matches(Object o) { | ||
assertTrue(String.class.isInstance(o)); | ||
String value = (String) o; | ||
return value.contains("foo"); | ||
} | ||
|
||
@Override public void describeTo(Description description) { | ||
description.appendText(this.getClass().getSimpleName()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMatcher() { | ||
FooMatcher matcher = new FooMatcher(); | ||
assertTrue(matcher.matches("foobar")); | ||
assertFalse(matcher.matches("Hello World!")); | ||
} | ||
|
||
/** | ||
* This test fails if the org.hamcrest classes are shaded in junit runner | ||
*/ | ||
@Test | ||
public void testAssertThat() { | ||
assertThat("Give me some food", containsString("foo")); | ||
} | ||
} |