From fc2e349f2bdadf5e05734a9304d20a84d4b6d927 Mon Sep 17 00:00:00 2001 From: Ellen Spertus Date: Tue, 28 Aug 2018 07:37:28 -0700 Subject: fixed tests after replacing NoSlug with None --- .../scala/sandcrawler/CrossrefScorableTest.scala | 67 +++++++++++----------- 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'scalding/src/test/scala/sandcrawler/CrossrefScorableTest.scala') diff --git a/scalding/src/test/scala/sandcrawler/CrossrefScorableTest.scala b/scalding/src/test/scala/sandcrawler/CrossrefScorableTest.scala index c0d1cb0..8302b8f 100644 --- a/scalding/src/test/scala/sandcrawler/CrossrefScorableTest.scala +++ b/scalding/src/test/scala/sandcrawler/CrossrefScorableTest.scala @@ -79,59 +79,64 @@ class CrossrefScorableTest extends FlatSpec with Matchers { // Unit tests "CrossrefScorable.jsonToMapFeatures()" should "handle invalid JSON" in { - val result = CrossrefScorable.jsonToMapFeatures(MalformedCrossrefString) - result.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(MalformedCrossrefString) should be (None) } it should "handle missing title" in { - val result = CrossrefScorable.jsonToMapFeatures(CrossrefStringWithoutTitle) - result.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(CrossrefStringWithoutTitle) should be (None) } it should "handle null title" in { - val result = CrossrefScorable.jsonToMapFeatures(CrossrefStringWithNullTitle) - result.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(CrossrefStringWithNullTitle) should be (None) } it should "handle empty title" in { - val result = CrossrefScorable.jsonToMapFeatures(CrossrefStringWithEmptyTitle) - result.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(CrossrefStringWithEmptyTitle) should be (None) } it should "handle subtitle" in { - val result = CrossrefScorable.jsonToMapFeatures( - """{"title": ["short but not too short"], "subtitle": ["just right!"], "DOI": "10.123/asdf", "type":"journal-article", "author":[{ "given" : "W", "family" : "Gaier"}]}""") - result.slug shouldBe "shortbutnottooshortjustright" + CrossrefScorable.jsonToMapFeatures( + """{"title": ["short but not too short"], "subtitle": ["just right!"], "DOI": "10.123/asdf", "type":"journal-article","author":[{ "given" : "W", "family" : "Gaier"}]}""") match { + case None => fail() + case Some(result) => result.slug shouldBe "shortbutnottooshortjustright" + } } it should "handle empty subtitle" in { - val result = CrossrefScorable.jsonToMapFeatures( - """{"title": ["short but not too short"], "subtitle": [""], "DOI": "10.123/asdf", "type":"journal-article", "author":[{ "given" : "W", "family" : "Gaier"}]}""") - result.slug shouldBe "shortbutnottooshort" + CrossrefScorable.jsonToMapFeatures( + """{"title": ["short but not too short"], "subtitle": [""], "DOI": "10.123/asdf", "type":"journal-article", "author":[{ "given" : "W", "family" : "Gaier"}]}""") match { + case None => fail() + case Some(result) => result.slug shouldBe "shortbutnottooshort" + } } it should "handle null subtitle" in { - val result = CrossrefScorable.jsonToMapFeatures( - """{"title": ["short but not too short"], "subtitle": [null], "DOI": "10.123/asdf", "type":"journal-article", "author":[{ "given" : "W", "family" : "Gaier"}]}""") - result.slug shouldBe "shortbutnottooshort" + CrossrefScorable.jsonToMapFeatures( + """{"title": ["short but not too short"], "subtitle": [null], "DOI": "10.123/asdf", "type":"journal-article", "author":[{ "given" : "W", "family" : "Gaier"}]}""") match { + case None => fail() + case Some(result) => result.slug shouldBe "shortbutnottooshort" + } } it should "handle missing authors" in { - val result = CrossrefScorable.jsonToMapFeatures(CrossrefStringWithNoAuthors) - result.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(CrossrefStringWithNoAuthors) should be (None) } it should "handle valid input" in { - val result = CrossrefScorable.jsonToMapFeatures(CrossrefStringWithGoodTitle) - result.slug shouldBe "sometitle" - Scorable.jsonToMap(result.json) match { + CrossrefScorable.jsonToMapFeatures(CrossrefStringWithGoodTitle) match { case None => fail() - case Some(map) => { - map("title").asInstanceOf[String] shouldBe "Some Title" - map("doi").asInstanceOf[String] shouldBe "10.123/abc" - // TODO: full name? not just a string? - map("authors").asInstanceOf[List[String]] shouldBe List("Gaier") - map("year").asInstanceOf[Double].toInt shouldBe 2002 + case Some(result) => { + result.slug shouldBe "sometitle" + Scorable.jsonToMap(result.json) match { + case None => fail() + case Some(map) => { + map("title").asInstanceOf[String] shouldBe "Some Title" + map("doi").asInstanceOf[String] shouldBe "10.123/abc" + // TODO: full name? not just a string? + map("authors").asInstanceOf[List[String]] shouldBe List("Gaier") + map("year").asInstanceOf[Double].toInt shouldBe 2002 + } + } } } } @@ -161,9 +166,7 @@ class CrossrefScorableTest extends FlatSpec with Matchers { } it should "handle content types" in { - val resultWrong = CrossrefScorable.jsonToMapFeatures(CrossrefStringWrongType) - resultWrong.slug shouldBe Scorable.NoSlug - val resultMissing = CrossrefScorable.jsonToMapFeatures(CrossrefStringNoType) - resultMissing.slug shouldBe Scorable.NoSlug + CrossrefScorable.jsonToMapFeatures(CrossrefStringWrongType) should be (None) + CrossrefScorable.jsonToMapFeatures(CrossrefStringNoType) should be (None) } } -- cgit v1.2.3