diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
commit | c8cdfb65631a6814f2d85e18171badc9144ed33e (patch) | |
tree | f807a0a4a9fd288c658611e36e5e9bb25e740b65 /document | |
parent | 6b9f956080484c22e894ee0ccd2692c2f442a333 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'document')
3 files changed, 41 insertions, 21 deletions
diff --git a/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java b/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java index 75768d464be..d10d4242f6f 100644 --- a/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java +++ b/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java @@ -5,18 +5,18 @@ import com.yahoo.document.BucketIdFactory; import com.yahoo.document.BucketId; import com.yahoo.document.DocumentId; import com.yahoo.document.idstring.*; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Date: Sep 7, 2007 * - * @author <a href="mailto:humbe@yahoo-inc.com">Håkon Humberset</a> + * @author HÃ¥kon Humberset */ -public class BucketIdFactoryTestCase extends junit.framework.TestCase { - - public BucketIdFactoryTestCase(String name) { - super(name); - } +public class BucketIdFactoryTestCase { + @Test public void testNormalUsage() { BucketIdFactory factory = new BucketIdFactory(); assertEquals(BucketId.COUNT_BITS, factory.getCountBitCount()); @@ -43,6 +43,7 @@ public class BucketIdFactoryTestCase extends junit.framework.TestCase { } } + @Test public void testBucketGeneration() { BucketIdFactory factory = new BucketIdFactory(32, 26, 6); DocumentId doc1 = new DocumentId(new DocIdString("ns", "spec")); @@ -99,6 +100,7 @@ public class BucketIdFactoryTestCase extends junit.framework.TestCase { } //Actually a BucketId testcase ... + @Test public void testBidContainsBid() { BucketId bid = new BucketId(18, 0x123456789L); @@ -109,6 +111,7 @@ public class BucketIdFactoryTestCase extends junit.framework.TestCase { assert(!bid.contains(new BucketId(16, 0x123456789L))); } + @Test public void testBidContainsDocId() { DocumentId docId = new DocumentId("userdoc:recovery:18:99999"); BucketIdFactory factory = new BucketIdFactory(32, 26, 6); @@ -122,6 +125,7 @@ public class BucketIdFactoryTestCase extends junit.framework.TestCase { assert(!bid.contains(docId, factory)); } + @Test public void testBucketIdSerializationAndCompare() { BucketId bid = new BucketId(18, 0x123456789L); diff --git a/document/src/test/java/com/yahoo/document/DocInDocTestCase.java b/document/src/test/java/com/yahoo/document/DocInDocTestCase.java index 63c38303161..cdc868af987 100644 --- a/document/src/test/java/com/yahoo/document/DocInDocTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocInDocTestCase.java @@ -3,19 +3,20 @@ package com.yahoo.document; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.StringFieldValue; -import com.yahoo.document.serialization.*; +import com.yahoo.document.serialization.DocumentDeserializer; +import com.yahoo.document.serialization.DocumentDeserializerFactory; +import com.yahoo.document.serialization.DocumentSerializer; +import com.yahoo.document.serialization.DocumentSerializerFactory; import com.yahoo.io.GrowableByteBuffer; -import junit.framework.TestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class DocInDocTestCase extends TestCase { +public class DocInDocTestCase { @Test public void testDocInDoc() { @@ -47,6 +48,6 @@ public class DocInDocTestCase extends TestCase { assertEquals(outer, outerDeserialized); assertNotSame(outer, outerDeserialized); - } + } diff --git a/document/src/test/java/com/yahoo/document/DocumentCalculatorTestCase.java b/document/src/test/java/com/yahoo/document/DocumentCalculatorTestCase.java index c16077d407a..0f8e28f107c 100755 --- a/document/src/test/java/com/yahoo/document/DocumentCalculatorTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentCalculatorTestCase.java @@ -5,18 +5,24 @@ import com.yahoo.document.datatypes.ByteFieldValue; import com.yahoo.document.datatypes.DoubleFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.LongFieldValue; +import org.junit.Before; +import org.junit.Test; import java.util.HashMap; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author thomasg */ -public class DocumentCalculatorTestCase extends junit.framework.TestCase { +public class DocumentCalculatorTestCase { DocumentType testDocType = null; DocumentTypeManager docMan; Document doc; + @Before public void setUp() { docMan = new DocumentTypeManager(); testDocType = new DocumentType("testdoc"); @@ -35,74 +41,83 @@ public class DocumentCalculatorTestCase extends junit.framework.TestCase { doc.setFieldValue(testDocType.getField("doubleattr"), new DoubleFieldValue(25.0)); } + @Test public void testConstant() throws Exception { DocumentCalculator calculator = new DocumentCalculator("4.0"); - assertEquals(4.0, calculator.evaluate(doc, new HashMap<String, Object>())); + assertEquals(4.0, calculator.evaluate(doc, new HashMap<>())); } + @Test public void testSimple() throws Exception { DocumentCalculator calculator = new DocumentCalculator("(3 + 5) / 2"); - assertEquals(4.0, calculator.evaluate(doc, new HashMap<String, Object>())); + assertEquals(4.0, calculator.evaluate(doc, new HashMap<>())); } + @Test public void testDivideByZero() throws Exception { DocumentCalculator calculator = new DocumentCalculator("(3 + 5) / 0"); try { - System.out.println(calculator.evaluate(doc, new HashMap<String, Object>())); + System.out.println(calculator.evaluate(doc, new HashMap<>())); assertTrue(false); } catch (IllegalArgumentException e) { // ok } } + @Test public void testModByZero() throws Exception { DocumentCalculator calculator = new DocumentCalculator("(3 + 5) % 0"); try { - System.out.println(calculator.evaluate(doc, new HashMap<String, Object>())); + System.out.println(calculator.evaluate(doc, new HashMap<>())); assertTrue(false); } catch (IllegalArgumentException e) { // ok } } + @Test public void testFieldDivideByZero() throws Exception { try { DocumentCalculator calculator = new DocumentCalculator("(testdoc.byteattr + testdoc.intattr) / testdoc.doubleattr"); doc.setFieldValue("doubleattr", new DoubleFieldValue(0.0)); - calculator.evaluate(doc, new HashMap<String, Object>()); + calculator.evaluate(doc, new HashMap<>()); assertTrue(false); } catch (IllegalArgumentException e) { // ok } } + @Test public void testVariables() throws Exception { - HashMap<String, Object> vars = new HashMap<String, Object>(); + HashMap<String, Object> vars = new HashMap<>(); vars.put("x", new Double(3.0)); vars.put("y", new Double(5.0)); DocumentCalculator calculator = new DocumentCalculator("($x + $y) / 2"); assertEquals(4.0, calculator.evaluate(doc, vars)); } + @Test public void testFields() throws Exception { DocumentCalculator calculator = new DocumentCalculator("(testdoc.byteattr + testdoc.intattr) / testdoc.doubleattr"); assertEquals(20.0, calculator.evaluate(doc, new HashMap<String, Object>())); } + @Test public void testMissingField() throws Exception { try { DocumentCalculator calculator = new DocumentCalculator("(testdoc.nosuchattribute + testdoc.intattr) / testdoc.doubleattr"); - calculator.evaluate(doc, new HashMap<String, Object>()); + calculator.evaluate(doc, new HashMap<>()); assertTrue(false); } catch (IllegalArgumentException e) { // ok } } + @Test public void testFieldNotSet() throws Exception { try { DocumentCalculator calculator = new DocumentCalculator("(testdoc.missingattr + testdoc.intattr) / testdoc.doubleattr"); - calculator.evaluate(doc, new HashMap<String, Object>()); + calculator.evaluate(doc, new HashMap<>()); assertTrue(false); } catch (IllegalArgumentException e) { // ok |