diff options
12 files changed, 197 insertions, 86 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureVersionsTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureVersionsTest.java index 37b0097b17c..afa6f74f604 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureVersionsTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureVersionsTest.java @@ -10,9 +10,9 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import static junit.framework.TestCase.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author freva diff --git a/vespajlib/src/test/java/com/yahoo/io/GrowableByteBufferTestCase.java b/vespajlib/src/test/java/com/yahoo/io/GrowableByteBufferTestCase.java index 5e7c2e30816..1dbc7661164 100644 --- a/vespajlib/src/test/java/com/yahoo/io/GrowableByteBufferTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/GrowableByteBufferTestCase.java @@ -1,20 +1,30 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; +import org.junit.Test; + import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.InvalidMarkException; import java.nio.ReadOnlyBufferException; import java.util.Arrays; -import static org.junit.Assert.assertArrayEquals;; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail;; /** * Tests GrowableByteBuffer. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ -public class GrowableByteBufferTestCase extends junit.framework.TestCase { +public class GrowableByteBufferTestCase { + + private static final double delta = 0.00000000001; + + @Test public void testBuffer() { GrowableByteBuffer buf = new GrowableByteBuffer(20, 1.5f); @@ -82,6 +92,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(130, buf.capacity()); } + @Test public void testGrowth() { GrowableByteBuffer buf = new GrowableByteBuffer(256, 2.0f); @@ -140,6 +151,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(45468, buf.limit()); } + @Test public void testBadGrowthFactors() { try { new GrowableByteBuffer(100, 1.0f); @@ -162,6 +174,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { } + @Test public void testPropertiesNonDirect() { GrowableByteBuffer buf = new GrowableByteBuffer(10, 1.5f); buf.order(ByteOrder.LITTLE_ENDIAN); @@ -184,6 +197,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(false, buf.isDirect()); } + @Test public void testPropertiesDirect() { // allocate* are simply encapsulated, so don't add logic to them, // therefore minimum size becomes what it says @@ -207,6 +221,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(true, buf.isDirect()); } + @Test public void testNumberEncodings() { GrowableByteBuffer buf = new GrowableByteBuffer(); buf.putInt1_2_4Bytes(124); @@ -334,6 +349,8 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(endWritePos, endReadPos); } + + @Test public void testNumberLengths() { assertEquals(1, GrowableByteBuffer.getSerializedSize1_4Bytes(0)); assertEquals(1, GrowableByteBuffer.getSerializedSize1_4Bytes(1)); @@ -374,12 +391,14 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(4, GrowableByteBuffer.getSerializedSize1_2_4Bytes(16385)); } + @Test public void testSize0() { GrowableByteBuffer buf = new GrowableByteBuffer(0, 2.0f); buf.put((byte) 1); buf.put((byte) 1); } + @Test public void testExceptionSafety() { GrowableByteBuffer g = new GrowableByteBuffer(32); ByteBuffer b = ByteBuffer.allocate(232); @@ -397,11 +416,13 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { } } + @Test public void testGrowthFactorAccessor() { GrowableByteBuffer g = new GrowableByteBuffer(32); - assertEquals(GrowableByteBuffer.DEFAULT_GROW_FACTOR, g.getGrowFactor()); + assertEquals(GrowableByteBuffer.DEFAULT_GROW_FACTOR, g.getGrowFactor(), delta); } + @Test public void testGrowthWithNonZeroMark() { GrowableByteBuffer g = new GrowableByteBuffer(32); final int mark = 16; @@ -415,12 +436,14 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(mark, g.getByteBuffer().reset().position()); } + @Test public void testPutInt2_4_8BytesMore() { GrowableByteBuffer g = new GrowableByteBuffer(32); g.putInt2_4_8Bytes(0x9000); assertEquals(4, g.position()); } + @Test public void testPutInt2_4_8BytesAs4() { GrowableByteBuffer g = new GrowableByteBuffer(32); boolean caught = false; @@ -441,6 +464,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(4, g.position()); } + @Test public void testGetInt2_4_8Bytes() { GrowableByteBuffer g = new GrowableByteBuffer(32); final long expected3 = 37L; @@ -455,6 +479,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(expected, g.getInt2_4_8Bytes()); } + @Test public void testSerializedSize2_4_8BytesIllegalValues() { boolean caught = false; try { @@ -472,6 +497,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertTrue(caught); } + @Test public void testPutInt1_2_4BytesAs4IllegalValues() { GrowableByteBuffer g = new GrowableByteBuffer(32); boolean caught = false; @@ -490,6 +516,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertTrue(caught); } + @Test public void testSerializedSize1_2_4BytesIllegalValues() { boolean caught = false; try { @@ -507,6 +534,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertTrue(caught); } + @Test public void testPutInt1_4BytesAs4() { GrowableByteBuffer g = new GrowableByteBuffer(32); boolean caught = false; @@ -520,6 +548,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(4, g.position()); } + @Test public void testSerializedSize1_4BytesIllegalValues() { boolean caught = false; try { @@ -530,16 +559,18 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertTrue(caught); } + @Test public void testBuilders() { GrowableByteBuffer g = GrowableByteBuffer.allocate(1063); assertEquals(1063, g.capacity()); g = GrowableByteBuffer.allocate(1063, 37.0f); assertEquals(1063, g.capacity()); - assertEquals(37.0f, g.getGrowFactor()); + assertEquals(37.0f, g.getGrowFactor(), delta); g = GrowableByteBuffer.allocateDirect(1063); assertTrue(g.isDirect()); } + @Test public void testForwarding() { GrowableByteBuffer g = new GrowableByteBuffer(1063); int first = g.arrayOffset(); @@ -550,11 +581,11 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals('a', g.getChar(0)); assertEquals('a', g.asCharBuffer().get(0)); g.putDouble(0, 10.0d); - assertEquals(10.0d, g.getDouble(0)); - assertEquals(10.0d, g.asDoubleBuffer().get(0)); + assertEquals(10.0d, g.getDouble(0), delta); + assertEquals(10.0d, g.asDoubleBuffer().get(0), delta); g.putFloat(0, 10.0f); - assertEquals(10.0f, g.getFloat(0)); - assertEquals(10.0f, g.asFloatBuffer().get(0)); + assertEquals(10.0f, g.getFloat(0), delta); + assertEquals(10.0f, g.asFloatBuffer().get(0), delta); g.putInt(0, 10); assertEquals(10, g.getInt(0)); assertEquals(10, g.asIntBuffer().get(0)); @@ -580,6 +611,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals((byte) 10, g.get(0)); } + @Test public void testComparison() { GrowableByteBuffer g0 = new GrowableByteBuffer(32); GrowableByteBuffer g1 = new GrowableByteBuffer(32); @@ -593,6 +625,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(-1, g0.compareTo(g1)); } + @Test public void testDuplicate() { GrowableByteBuffer g0 = new GrowableByteBuffer(32); GrowableByteBuffer g1 = g0.duplicate(); @@ -600,6 +633,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(12, g1.get()); } + @Test public void testGetByteArrayOffsetLen() { GrowableByteBuffer g = new GrowableByteBuffer(32); byte[] expected = new byte[] { (byte) 1, (byte) 2, (byte) 3 }; @@ -612,6 +646,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertArrayEquals(expected, got); } + @Test public void testPutByteArrayOffsetLen() { GrowableByteBuffer g = new GrowableByteBuffer(32); byte[] expected = new byte[] { (byte) 1, (byte) 2, (byte) 3 }; @@ -622,6 +657,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertArrayEquals(expected, got); } + @Test public void testPutGrowableBuffer() { GrowableByteBuffer g0 = new GrowableByteBuffer(32); byte[] expected = new byte[] { (byte) 1, (byte) 2, (byte) 3 }; @@ -643,6 +679,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { return g; } + @Test public void testPutWithGrow() { GrowableByteBuffer g = fullBuffer(); final int capacity = g.capacity(); @@ -697,6 +734,7 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertTrue(capacity < g.capacity()); } + @Test public void testSlice() { GrowableByteBuffer g0 = new GrowableByteBuffer(32); GrowableByteBuffer g1 = g0.slice(); @@ -705,27 +743,30 @@ public class GrowableByteBufferTestCase extends junit.framework.TestCase { assertEquals(expected, g1.getInt()); } + @Test public void testToString() { assertEquals("GrowableByteBuffer[pos=32 lim=32 cap=32 grow=2.0]", - fullBuffer().toString()); + fullBuffer().toString()); } + @Test public void testWrappers() { final byte expected = (byte) 2; byte[] data = new byte[] { (byte) 1, expected, (byte) 3 }; final float grow = 9e5f; GrowableByteBuffer g = GrowableByteBuffer.wrap(data, grow); assertEquals(expected, g.get(1)); - assertEquals(grow, g.getGrowFactor()); + assertEquals(grow, g.getGrowFactor(), delta); g = GrowableByteBuffer.wrap(data, 1, 1); assertEquals(expected, g.get()); assertEquals(2, g.limit()); g = GrowableByteBuffer.wrap(data, 1, 1, grow); assertEquals(expected, g.get()); assertEquals(2, g.limit()); - assertEquals(grow, g.getGrowFactor()); + assertEquals(grow, g.getGrowFactor(), delta); } + @Test public void testByteBufferMethods() { GrowableByteBuffer g = fullBuffer(); assertFalse(g.hasRemaining()); diff --git a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java index 3926a08a03c..fcbc855bf74 100644 --- a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java @@ -9,15 +9,19 @@ import java.util.Collections; import com.yahoo.io.reader.NamedReader; import com.yahoo.protect.ClassValidator; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests all method of NamedReader. * * @author bratseth - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class NamedReaderTestCase extends junit.framework.TestCase { +public class NamedReaderTestCase { + @Test public void testIt() { StringReader stringReader=new StringReader("hello world"); NamedReader r=new NamedReader("test1",stringReader); @@ -28,9 +32,10 @@ public class NamedReaderTestCase extends junit.framework.TestCase { NamedReader.closeAll(null); // noop, nor exception } + @Test public void testMethodMasking() { assertEquals(0, - ClassValidator.unmaskedMethodsFromSuperclass(NamedReader.class).size()); + ClassValidator.unmaskedMethodsFromSuperclass(NamedReader.class).size()); } private static class MarkerReader extends Reader { @@ -104,6 +109,7 @@ public class NamedReaderTestCase extends junit.framework.TestCase { } } + @Test public void testAllDelegators() throws IOException { MarkerReader m = new MarkerReader(); NamedReader r = new NamedReader("nalle", m); @@ -128,4 +134,5 @@ public class NamedReaderTestCase extends junit.framework.TestCase { r.close(); assertEquals(MarkerReader.CLOSE, m.lastMethodHit); } + } diff --git a/vespajlib/src/test/java/com/yahoo/net/URITestCase.java b/vespajlib/src/test/java/com/yahoo/net/URITestCase.java index e35a8aa481a..7b7c8356437 100644 --- a/vespajlib/src/test/java/com/yahoo/net/URITestCase.java +++ b/vespajlib/src/test/java/com/yahoo/net/URITestCase.java @@ -1,19 +1,23 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.net; +import org.junit.Test; + import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Tests the URI class * * @author bratseth */ -public class URITestCase extends junit.framework.TestCase { - - public URITestCase(String name) { - super(name); - } +public class URITestCase { + @Test public void testEquality() { URI one = new URI("http://www.nils.arne.com"); URI two = new URI("http://www.nils.arne.com"); @@ -39,6 +43,7 @@ public class URITestCase extends junit.framework.TestCase { new URI("http://www.strange_host.com/b", true).stringValue()); } + @Test public void testOpaque() { URI uri = new URI("mailto:knut"); @@ -46,6 +51,7 @@ public class URITestCase extends junit.framework.TestCase { assertTrue(uri.isOpaque()); } + @Test public void testValid() { assertTrue( new URI("http://www.one.com/isValid?even=if&theres=args").isValid()); @@ -58,6 +64,7 @@ public class URITestCase extends junit.framework.TestCase { assertTrue(!new URI("http://www.strange_host.com/b").isOpaque()); } + @Test public void testSorting() { URI first = new URI("http://aisfirst.kanoo.com"); URI second = new URI("www.thentheresw.com"); @@ -67,6 +74,7 @@ public class URITestCase extends junit.framework.TestCase { assertTrue(second.compareTo(first) > 1); } + @Test public void testHost() { assertEquals("a.b.c", new URI("http://A.B.C:567").getHost()); assertEquals("www.kanoo.com", @@ -77,6 +85,7 @@ public class URITestCase extends junit.framework.TestCase { assertEquals("a", new URI("http://A:80").getHost()); } + @Test public void testUnfragmenting() { assertEquals("http://www.sng.no/a/b/dee?kanoos&at=nught#chapter3", new URI("http://www.sng.no/a/b/cee/../dee?kanoos&at=nught#chapter3", true).stringValue()); @@ -84,6 +93,7 @@ public class URITestCase extends junit.framework.TestCase { new URI("http://www.sng.no/a/b/cee/../dee?kanoos&at=nught#chapter3", false).stringValue()); } + @Test public void testNormalizing() { // Abbreviation resolving heuristics assertEquals("http://www.a.b/c", @@ -117,6 +127,7 @@ public class URITestCase extends junit.framework.TestCase { new URI(" WWW.a.B:80//m\u00E5l/.//&/./\u00F8l&&/foo/../upp/./..", true, true).toString()); } + @Test public void testParemeterAdding() { assertEquals("http://a/?knug=zagg", new URI("http://a/").addParameter("knug", "zagg").stringValue()); @@ -128,6 +139,7 @@ public class URITestCase extends junit.framework.TestCase { assertEquals(fasit, new URI(test).toString()); } + @Test public void testDepth() { assertEquals(0, new URI("test:hit").getDepth()); assertEquals(0, new URI("test://hit").getDepth()); @@ -140,6 +152,7 @@ public class URITestCase extends junit.framework.TestCase { assertEquals(2, new URI("test://hit.test/hello/test2/").getDepth()); } + @Test public void testURLEmpty() { URI uri = new URI("", true); assertTrue(uri.isValid()); @@ -156,6 +169,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLDot() { URI uri = new URI(".", true); assertTrue(uri.isValid()); @@ -172,6 +186,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLDotDot() { URI uri = new URI("..", true); assertTrue(uri.isValid()); @@ -188,6 +203,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLUninett() { URI uri = new URI("http://180.uninett.no/servlet/online.Bransje", true); assertTrue(uri.isValid()); @@ -204,6 +220,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLUnderdusken() { URI uri = new URI("http://www.underdusken.no", true); assertTrue(uri.isValid()); @@ -220,6 +237,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLUnderduskenUholdbar() { URI uri = new URI("http://www.underdusken.no/?page=dusker/html/0008/Uholdbar.html", true); @@ -237,6 +255,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLUniKarlsruhe() { URI uri = new URI("http://www.uni-karlsruhe.de/~ig25/ssh-faq/", true); assertTrue(uri.isValid()); @@ -253,6 +272,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLDetteErEn() { URI uri = new URI("https://dette.er.en:2020/~janie/index.htm?param1=q¶m2=r", true); assertTrue(uri.isValid()); @@ -269,6 +289,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLSonyCoUk() { URI uri = new URI("http://www.sony.co.uk/", true); assertTrue(uri.isValid()); @@ -285,6 +306,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLSonyCoUk2() { URI uri = new URI("http://sony.co.uk/", true); assertTrue(uri.isValid()); @@ -303,6 +325,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLSomehostSomedomain() { URI uri = new URI("http://somehost.somedomain/this!is!it/boom", true); assertTrue(uri.isValid()); @@ -319,6 +342,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLTestCom() { URI uri = new URI("http://test.com/index.htm?p1=q%20test&p2=r%10d", true); assertTrue(uri.isValid()); @@ -335,6 +359,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLArthur() { URI uri = new URI("http://arthur/qm/images/qm1.gif", true); assertTrue(uri.isValid()); @@ -351,6 +376,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLFooCom() { URI uri = new URI("http://foo.com/ui;.gif", true); assertTrue(uri.isValid()); @@ -367,6 +393,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLFooCom2() { URI uri = new URI("http://foo.com/ui;par1=1/par2=2", true); assertTrue(uri.isValid()); @@ -383,6 +410,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testURLFooNo() { URI uri = new URI( "http://www.foo.no:8080/path/filename.ext;par1=hello/par2=world?query=test#fragment", true); @@ -400,6 +428,7 @@ public class URITestCase extends junit.framework.TestCase { assertEquals("fragment", uri.getFragment()); } + @Test public void testURLAmpersand() { URI uri = new URI("http://canonsarang.com/zboard/data/gallery04/HU&BANG.jpg", true); assertTrue(uri.isValid()); @@ -416,6 +445,7 @@ public class URITestCase extends junit.framework.TestCase { assertNull(uri.getFragment()); } + @Test public void testQMark() { URI uri = new URI("http://foobar/?"); assertTrue(uri.isValid()); @@ -424,6 +454,7 @@ public class URITestCase extends junit.framework.TestCase { assertEquals("", uri.getQuery()); } + @Test public void testTokenization() { URI uri = new URI("http://this.i_s:5000/wo_ho;ba-lo?gobo#banana", true); List<URI.Token> tokens = uri.tokenize(); @@ -468,45 +499,45 @@ public class URITestCase extends junit.framework.TestCase { } } - // Error reported int bug #2466528 - public void testFileURIEmptyHost() { - URI uri = new URI("file:///C:/Inetpub/wwwroot/DW_SHORTCUTS.htm"); - List<URI.Token> tokens = uri.tokenize(); - URI.Token token; - token = tokens.get(0); - assertEquals("file", token.getToken()); - assertEquals(URI.URLContext.URL_SCHEME, token.getContext()); - - token = tokens.get(1); - assertEquals("localhost", token.getToken()); - assertEquals(URI.URLContext.URL_HOST, token.getContext()); - - token = tokens.get(2); - assertEquals("C", token.getToken()); - assertEquals(URI.URLContext.URL_PATH, token.getContext()); - - token = tokens.get(3); - assertEquals("Inetpub", token.getToken()); - assertEquals(URI.URLContext.URL_PATH, token.getContext()); - - token = tokens.get(4); - assertEquals("wwwroot", token.getToken()); - assertEquals(URI.URLContext.URL_PATH, token.getContext()); - - token = tokens.get(5); - assertEquals("DW_SHORTCUTS", token.getToken()); - assertEquals(URI.URLContext.URL_PATH, token.getContext()); - - token = tokens.get(6); - assertEquals("htm", token.getToken()); - assertEquals(URI.URLContext.URL_PATH, token.getContext()); - - try { - tokens.get(7); - fail(); - } catch (IndexOutOfBoundsException ioobe) { - // Success - } + @Test + public void testFileURIEmptyHost() { + URI uri = new URI("file:///C:/Inetpub/wwwroot/DW_SHORTCUTS.htm"); + List<URI.Token> tokens = uri.tokenize(); + URI.Token token; + token = tokens.get(0); + assertEquals("file", token.getToken()); + assertEquals(URI.URLContext.URL_SCHEME, token.getContext()); + + token = tokens.get(1); + assertEquals("localhost", token.getToken()); + assertEquals(URI.URLContext.URL_HOST, token.getContext()); + + token = tokens.get(2); + assertEquals("C", token.getToken()); + assertEquals(URI.URLContext.URL_PATH, token.getContext()); + + token = tokens.get(3); + assertEquals("Inetpub", token.getToken()); + assertEquals(URI.URLContext.URL_PATH, token.getContext()); + + token = tokens.get(4); + assertEquals("wwwroot", token.getToken()); + assertEquals(URI.URLContext.URL_PATH, token.getContext()); + + token = tokens.get(5); + assertEquals("DW_SHORTCUTS", token.getToken()); + assertEquals(URI.URLContext.URL_PATH, token.getContext()); + + token = tokens.get(6); + assertEquals("htm", token.getToken()); + assertEquals(URI.URLContext.URL_PATH, token.getContext()); + + try { + tokens.get(7); + fail(); + } catch (IndexOutOfBoundsException ioobe) { + // Success } + } } diff --git a/vespajlib/src/test/java/com/yahoo/protect/TestErrorMessage.java b/vespajlib/src/test/java/com/yahoo/protect/TestErrorMessage.java index 3a923ebbb47..58a35b2bddf 100644 --- a/vespajlib/src/test/java/com/yahoo/protect/TestErrorMessage.java +++ b/vespajlib/src/test/java/com/yahoo/protect/TestErrorMessage.java @@ -1,11 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.protect; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author bratseth */ -public class TestErrorMessage extends junit.framework.TestCase { +public class TestErrorMessage { + @Test public void testErrorMessages() { ErrorMessage m1=new ErrorMessage(17,"Message"); ErrorMessage m2=new ErrorMessage(17,"Message","Detail"); @@ -17,6 +24,7 @@ public class TestErrorMessage extends junit.framework.TestCase { assertEquals("error : Message (Detail: Throwable message)",m3.toString()); } + @Test public void testErrorMessageEquality() { assertEquals(new ErrorMessage(17,"Message"),new ErrorMessage(17,"Message")); assertFalse(new ErrorMessage(16,"Message").equals(new ErrorMessage(17,"Message"))); diff --git a/vespajlib/src/test/java/com/yahoo/protect/ValidatorTestCase.java b/vespajlib/src/test/java/com/yahoo/protect/ValidatorTestCase.java index 42e9cd0298b..e4549968ebd 100644 --- a/vespajlib/src/test/java/com/yahoo/protect/ValidatorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/protect/ValidatorTestCase.java @@ -1,11 +1,17 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.protect; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * @author bratseth */ -public class ValidatorTestCase extends junit.framework.TestCase { +public class ValidatorTestCase { + @Test public void testEnsureNotNull() { try { Validator.ensureNotNull("Description",null); @@ -16,6 +22,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testEnsureNotInitialized() { try { Validator.ensureNotInitialized("Description","Field-owner","Initialized-field-value"); @@ -26,6 +33,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testEnsureInRange() { try { Validator.ensureInRange("Description",2,4,5); @@ -36,6 +44,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testSmallerInts() { try { Validator.ensureSmaller("Small-description",3,"Large-description",2); @@ -46,6 +55,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testSmallerComparables() { try { Validator.ensureSmaller("Small-description","b","Large-description","a"); @@ -56,6 +66,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testEnsure() { try { Validator.ensure("Description",false); @@ -66,6 +77,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testEnsureInstanceOf() { try { Validator.ensureInstanceOf("Description","item",Integer.class); @@ -76,6 +88,7 @@ public class ValidatorTestCase extends junit.framework.TestCase { } } + @Test public void testVarArgsEnsure() { Validator.ensure(true, "ignored"); try { diff --git a/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java b/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java index d13889f8e30..9b370d4ce10 100644 --- a/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java @@ -1,19 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.system; -import com.yahoo.system.CatchSigTerm; +import org.junit.Test; + import java.util.concurrent.atomic.AtomicBoolean; /** * @author arnej27959 */ -public class CatchSigTermTestCase extends junit.framework.TestCase { - - public CatchSigTermTestCase(String name) { - super(name); - } +public class CatchSigTermTestCase { + @Test public void testThatSetupCompiles() { CatchSigTerm.setup(new AtomicBoolean(false)); } + } diff --git a/vespajlib/src/test/java/com/yahoo/system/CommandLineParserTestCase.java b/vespajlib/src/test/java/com/yahoo/system/CommandLineParserTestCase.java index e9f5c7a9e11..5553414cfca 100644 --- a/vespajlib/src/test/java/com/yahoo/system/CommandLineParserTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/system/CommandLineParserTestCase.java @@ -1,10 +1,17 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.system; -import junit.framework.TestCase; +import org.junit.Test; -public class CommandLineParserTestCase extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +public class CommandLineParserTestCase { + + @Test public void testParse1() { String[] args = new String[] {"-d", "-f", "hello.txt"}; CommandLineParser parser = new CommandLineParser(args); @@ -21,6 +28,7 @@ public class CommandLineParserTestCase extends TestCase { assertEquals(parser.getArguments().size(), 0); } + @Test public void testParse2() { String[] args = new String[] {"-d", "-f", "hello.txt", "-XX", "myName", "-o", "output file", "myLastField"}; CommandLineParser parser = new CommandLineParser("progname", args); @@ -56,6 +64,7 @@ public class CommandLineParserTestCase extends TestCase { } } + @Test public void testIllegal() { String[] args = new String[] {"-d", "-f", "hello.txt", "-XX", "myName", "-o", "output file", "myLastField"}; CommandLineParser parser = new CommandLineParser(args); @@ -82,6 +91,7 @@ public class CommandLineParserTestCase extends TestCase { } } + @Test public void testRequired() { String[] args1 = new String[] {"-d", "-f", "hello.txt", "-XX", "myName", "-o", "output file", "myLastField"}; String[] args2 = new String[] {"-XX", "myName", "-o", "output file", "myLastField"}; @@ -122,4 +132,5 @@ public class CommandLineParserTestCase extends TestCase { parser.parse(); assertEquals(parser.getUnarySwitches().get(0), "-d"); } + } diff --git a/vespajlib/src/test/java/com/yahoo/system/ForceLoadTestCase.java b/vespajlib/src/test/java/com/yahoo/system/ForceLoadTestCase.java index f385ea5beec..81395c3c765 100644 --- a/vespajlib/src/test/java/com/yahoo/system/ForceLoadTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/system/ForceLoadTestCase.java @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.system; -public class ForceLoadTestCase extends junit.framework.TestCase { +import org.junit.Test; - public ForceLoadTestCase(String name) { - super(name); - } +import static org.junit.Assert.assertTrue; + +public class ForceLoadTestCase { + @Test public void testLoadClasses() { try { @@ -18,6 +19,7 @@ public class ForceLoadTestCase extends junit.framework.TestCase { } } + @Test public void testLoadBogusClass() { try { ForceLoad.forceLoad(getClass().getPackage().getName(), new String[] { "Foo", "Bar", "Baz" }, @@ -27,4 +29,5 @@ public class ForceLoadTestCase extends junit.framework.TestCase { } assertTrue(false); } + } diff --git a/vespajlib/src/test/java/com/yahoo/system/ProcessExecuterTestCase.java b/vespajlib/src/test/java/com/yahoo/system/ProcessExecuterTestCase.java index dba6047b0c6..c7651d46933 100644 --- a/vespajlib/src/test/java/com/yahoo/system/ProcessExecuterTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/system/ProcessExecuterTestCase.java @@ -3,15 +3,19 @@ package com.yahoo.system; import com.yahoo.collections.Pair; import com.yahoo.io.IOUtils; +import org.junit.Test; import java.io.File; import java.io.IOException; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class ProcessExecuterTestCase extends junit.framework.TestCase { +public class ProcessExecuterTestCase { + @Test public void testIt() throws IOException { IOUtils.writeFile("tmp123.txt","hello\nworld",false); ProcessExecuter exec=new ProcessExecuter(); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java index c94a735149a..c986fe40931 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor; -import junit.framework.TestCase; import org.junit.Test; import java.util.Collections; @@ -9,9 +8,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bratseth diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java index 164412fe76d..e312560d04c 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java @@ -2,14 +2,10 @@ package com.yahoo.tensor; import com.google.common.collect.Sets; -import junit.framework.TestCase; import org.junit.Test; -import java.util.Set; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * Basic tensor tests. Tensor operations are tested in EvaluationTestCase @@ -22,13 +18,13 @@ public class MappedTensorTestCase { public void testEmpty() { TensorType type = new TensorType.Builder().mapped("x").build(); Tensor empty = Tensor.Builder.of(type).build(); - TestCase.assertTrue(empty instanceof MappedTensor); - TestCase.assertTrue(empty.isEmpty()); + assertTrue(empty instanceof MappedTensor); + assertTrue(empty.isEmpty()); assertEquals("tensor(x{}):{}", empty.toString()); Tensor emptyFromString = Tensor.from(type, "{}"); assertEquals("tensor(x{}):{}", Tensor.from("tensor(x{}):{}").toString()); - TestCase.assertTrue(emptyFromString.isEmpty()); - TestCase.assertTrue(emptyFromString instanceof MappedTensor); + assertTrue(emptyFromString.isEmpty()); + assertTrue(emptyFromString instanceof MappedTensor); assertEquals(empty, emptyFromString); } |