-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from FasterXML/run-failing-tests-always
Always run failing tests, but make them pass
- Loading branch information
Showing
18 changed files
with
245 additions
and
96 deletions.
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
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
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
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/TestHelpers.kt
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,37 @@ | ||
package com.fasterxml.jackson.module.kotlin.test | ||
|
||
import kotlin.test.fail | ||
|
||
/** | ||
* Expect a block to throw an exception. If a different type of exception is thrown or no | ||
* exception is produced by the block, fail the test. In the latter case, no exception being | ||
* thrown, fixMessage is printed. | ||
* | ||
* This function is intended to allow failing tests to be written and run as part of the build | ||
* without causing it to fail, except if the failure is fixed, in which case the fixMessage | ||
* should make it clear what has happened (i.e. that some previously broken functionality | ||
* has been fixed). | ||
* | ||
* @param T The expected throwable | ||
* @param fixMessage The message to print when the block succeeds | ||
* @param block The block to execute | ||
*/ | ||
inline fun <reified T : Throwable> expectFailure( | ||
fixMessage: String, | ||
block: () -> Unit | ||
) { | ||
try { | ||
block() | ||
} catch (e: Throwable) { | ||
val throwableType = T::class | ||
if (throwableType.isInstance(e)) { | ||
// Expected exception, do nothing | ||
} else { | ||
fail("Expected $throwableType but got $e") | ||
} | ||
|
||
return | ||
} | ||
|
||
fail(fixMessage) | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/TestHelpersTest.kt
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,37 @@ | ||
package com.fasterxml.jackson.module.kotlin.test | ||
|
||
import org.junit.Assert.assertThrows | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class TestHelpersTest { | ||
@Test | ||
fun expectFailure_ExpectedExceptionThrown() { | ||
expectFailure<AssertionError>("This will not be printed") { | ||
throw AssertionError("This is expected") | ||
} | ||
} | ||
|
||
@Test | ||
fun expectFailure_AnotherExceptionThrown() { | ||
val throwable = assertThrows(AssertionError::class.java) { | ||
expectFailure<AssertionError>("This will not be printed") { | ||
throw Exception("This is not expected") | ||
} | ||
} | ||
|
||
assertEquals("Expected class java.lang.AssertionError but got java.lang.Exception: This is not expected", throwable.message) | ||
} | ||
|
||
@Test | ||
fun expectFailure_NoExceptionThrown() { | ||
val fixMessage = "Test will fail with this message" | ||
val throwable = assertThrows(AssertionError::class.java) { | ||
expectFailure<AssertionError>(fixMessage) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
assertEquals(fixMessage, throwable.message) | ||
} | ||
} |
24 changes: 12 additions & 12 deletions
24
...on/module/kotlin/test/github/Github138.kt → ...n/module/kotlin/test/failing/Github138.kt
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
package com.fasterxml.jackson.module.kotlin.test.github | ||
package com.fasterxml.jackson.module.kotlin.test.failing | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import org.junit.Ignore | ||
import com.fasterxml.jackson.module.kotlin.test.expectFailure | ||
import org.junit.Test | ||
|
||
class TestGithub138 { | ||
@JacksonXmlRootElement(localName = "sms") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Sms( | ||
@JacksonXmlProperty(localName = "Phone", isAttribute = true) | ||
val phone: String?, | ||
@JacksonXmlProperty(localName = "Phone", isAttribute = true) | ||
val phone: String?, | ||
|
||
@JacksonXmlText | ||
val text: String? = "" | ||
|
||
) | ||
@JacksonXmlText | ||
val text: String? = "" | ||
) | ||
|
||
@Test | ||
@Ignore("Not sure the cause of this yet...") | ||
fun testDeserProblem() { | ||
val xml = """<sms Phone="435242423412" Id="43234324">Lorem ipsum</sms>""" | ||
val xmlMapper = XmlMapper().registerKotlinModule() | ||
val sms = xmlMapper.readValue<Sms>(xml) | ||
|
||
expectFailure<InvalidDefinitionException>("GitHub #138 has been fixed!") { | ||
val jsms = xmlMapper.readValue<Sms>(xml) | ||
} | ||
} | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...st/kotlin/com/fasterxml/jackson/module/kotlin/test/failing/Github160DisableAnnotations.kt
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package com.fasterxml.jackson.module.kotlin.test.failing | ||
|
||
import com.fasterxml.jackson.databind.MapperFeature | ||
import com.fasterxml.jackson.databind.exc.MismatchedInputException | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import org.junit.Ignore | ||
import com.fasterxml.jackson.module.kotlin.test.expectFailure | ||
import org.junit.Test | ||
|
||
class TestGithub160 { | ||
data class DataClass(val blah: String) | ||
|
||
@Test | ||
// @Ignore("This error is caused by annotations being turned off, but in Jackson 2.x we cannot catch this uniformly across the board") | ||
fun dataClass() { | ||
val j = jacksonObjectMapper().configure( | ||
MapperFeature.USE_ANNOTATIONS, false | ||
)!! | ||
j.readValue<DataClass>(""" {"blah":"blah"}""") | ||
val mapper = jacksonObjectMapper().configure(MapperFeature.USE_ANNOTATIONS, false) | ||
expectFailure<MismatchedInputException>("GitHub #160 has been fixed!") { | ||
mapper.readValue<DataClass>("""{"blah":"blah"}""") | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.