From: <lh...@us...> - 2008-08-19 11:14:10
|
Revision: 65 http://tmapi.svn.sourceforge.net/tmapi/?rev=65&view=rev Author: lheuer Date: 2008-08-19 11:14:19 +0000 (Tue, 19 Aug 2008) Log Message: ----------- - Added IllegalArgumentException to the index docs - More variant tests - More ScopedIndex tests Modified Paths: -------------- trunk/src/main/java/org/tmapi/index/LiteralIndex.java trunk/src/main/java/org/tmapi/index/ScopedIndex.java trunk/src/test/java/org/tmapi/core/TestReified.java trunk/src/test/java/org/tmapi/core/TestVariant.java trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java trunk/src/test/java/org/tmapi/index/TestScopedIndex.java Modified: trunk/src/main/java/org/tmapi/index/LiteralIndex.java =================================================================== --- trunk/src/main/java/org/tmapi/index/LiteralIndex.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/main/java/org/tmapi/index/LiteralIndex.java 2008-08-19 11:14:19 UTC (rev 65) @@ -37,6 +37,7 @@ * * @param value The value of the {@link Occurrence}s to be returned. * @return An unmodifiable collection of {@link Occurrence}s. + * @throws IllegalArgumentException If the value is <tt>null</tt>. */ public Collection<Occurrence> getOccurrences(String value); @@ -53,6 +54,7 @@ * * @param value The value of the {@link Occurrence}s to be returned. * @return An unmodifiable collection of {@link Occurrence}s. + * @throws IllegalArgumentException If the value is <tt>null</tt>. */ public Collection<Occurrence> getOccurrences(Locator value); @@ -65,6 +67,7 @@ * @param value The value of the {@link Occurrence}s to be returned. * @param datatype The datatype of the {@link Occurrence}s to be returned. * @return An unmodifiable collection of {@link Occurrence}s. + * @throws IllegalArgumentException If the value or datatype is <tt>null</tt>. */ public Collection<Occurrence> getOccurrences(String value, Locator datatype); @@ -77,6 +80,7 @@ * * @param value The value of the {@link Variant}s to be returned. * @return An unmodifiable collection of {@link Variant}s. + * @throws IllegalArgumentException If the value is <tt>null</tt>. */ public Collection<Variant> getVariants(String value); @@ -93,6 +97,7 @@ * * @param value The value of the {@link Variant}s to be returned. * @return An unmodifiable collection of {@link Variant}s. + * @throws IllegalArgumentException If the value is <tt>null</tt>. */ public Collection<Variant> getVariants(Locator value); @@ -105,6 +110,7 @@ * @param value The value of the {@link Variant}s to be returned. * @param datatype The datatype of the {@link Variant}s to be returned. * @return An unmodifiable collection of {@link Variant}s. + * @throws IllegalArgumentException If the value or datatype is <tt>null</tt>. */ public Collection<Variant> getVariants(String value, Locator datatype); @@ -116,6 +122,7 @@ * * @param value The value of the {@link Name}s to be returned. * @return An unmodifiable collection of {@link Name}s. + * @throws IllegalArgumentException If the value is <tt>null</tt>. */ public Collection<Name> getNames(String value); Modified: trunk/src/main/java/org/tmapi/index/ScopedIndex.java =================================================================== --- trunk/src/main/java/org/tmapi/index/ScopedIndex.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/main/java/org/tmapi/index/ScopedIndex.java 2008-08-19 11:14:19 UTC (rev 65) @@ -57,6 +57,7 @@ * must match all <tt>themes</tt>, if <tt>false</tt> one * theme must be matched at least. * @return An unmodifiable collection of {@link Association}s. + * @throws IllegalArgumentException If <tt>themes</tt> is <tt>null</tt>. */ public Collection<Association> getAssociations(Topic[] themes, boolean matchAll); @@ -95,6 +96,7 @@ * must match all <tt>themes</tt>, if <tt>false</tt> one * theme must be matched at least. * @return An unmodifiable collection of {@link Occurrence}s. + * @throws IllegalArgumentException If <tt>themes</tt> is <tt>null</tt>. */ public Collection<Occurrence> getOccurrences(Topic[] themes, boolean matchAll); @@ -133,6 +135,7 @@ * must match all <tt>themes</tt>, if <tt>false</tt> one * theme must be matched at least. * @return An unmodifiable collection of {@link Name}s. + * @throws IllegalArgumentException If <tt>themes</tt> is <tt>null</tt>. */ public Collection<Name> getNames(Topic[] themes, boolean matchAll); @@ -155,6 +158,7 @@ * @param theme The {@link Topic} which must be part of the scope. This * must not be <tt>null</tt>. * @return An unmodifiable collection of {@link Variant}s. + * @throws IllegalArgumentException If <tt>theme</tt> is <tt>null</tt>. */ public Collection<Variant> getVariants(Topic theme); @@ -169,6 +173,7 @@ * must match all <tt>themes</tt>, if <tt>false</tt> one * theme must be matched at least. * @return An unmodifiable collection of {@link Variant}s. + * @throws IllegalArgumentException If <tt>themes</tt> is <tt>null</tt>. */ public Collection<Variant> getVariants(Topic[] themes, boolean matchAll); Modified: trunk/src/test/java/org/tmapi/core/TestReified.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestReified.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/test/java/org/tmapi/core/TestReified.java 2008-08-19 11:14:19 UTC (rev 65) @@ -45,6 +45,8 @@ assertEquals("Unexpected reifier property", reifier, reifiable.getReifier()); assertEquals("Unexpected reified property", reifiable, reifier.getReified()); try { + // Assigning the *same* reifier is allowed, the TM processor MUST NOT + // raise an exception reifiable.setReifier(reifier); } catch (ModelConstraintException ex) { Modified: trunk/src/test/java/org/tmapi/core/TestVariant.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestVariant.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/test/java/org/tmapi/core/TestVariant.java 2008-08-19 11:14:19 UTC (rev 65) @@ -62,7 +62,8 @@ final Topic varTheme = createTopic(); final Variant variant = name.createVariant("Variant", varTheme); assertNotNull(variant); - assertEquals(1, variant.getScope().size()); + assertEquals("Unexpected variant's scope", + 1, variant.getScope().size()); assertTrue(variant.getScope().contains(varTheme)); final Topic nameTheme = createTopic(); name.addTheme(nameTheme); @@ -73,7 +74,62 @@ assertTrue(variant.getScope().contains(varTheme)); name.removeTheme(nameTheme); assertTrue(name.getScope().isEmpty()); - assertEquals(1, variant.getScope().size()); + assertEquals("Name's theme wasn't remove from the variant", + 1, variant.getScope().size()); assertTrue(variant.getScope().contains(varTheme)); } + + /** + * Tests if a variant's theme equals to a name's theme stays + * even if the name's theme is removed. + */ + public void testScopeProperty2() { + final Topic theme = createTopic(); + final Topic varTheme = createTopic(); + final Name name = createTopic().createName("Name", theme); + assertEquals(1, name.getScope().size()); + assertTrue(name.getScope().contains(theme)); + final Variant variant = name.createVariant("Variant", theme, varTheme); + assertNotNull(variant); + assertEquals("Unexpected variant's scope", + 2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + assertTrue(variant.getScope().contains(varTheme)); + name.removeTheme(theme); + assertEquals(0, name.getScope().size()); + assertEquals("Unexpected variant's scope after removal of 'theme' from name", + 2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + assertTrue(variant.getScope().contains(varTheme)); + } + + /** + * Tests if a variant's theme equals to a name's theme stays + * even if the variant's theme is removed. + */ + public void testScopeProperty3() { + final Topic theme = createTopic(); + final Topic varTheme = createTopic(); + final Name name = createTopic().createName("Name", theme); + assertEquals(1, name.getScope().size()); + assertTrue(name.getScope().contains(theme)); + final Variant variant = name.createVariant("Variant", theme, varTheme); + assertNotNull(variant); + assertEquals("Unexpected variant's scope", + 2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + assertTrue(variant.getScope().contains(varTheme)); + variant.removeTheme(theme); + assertEquals("The parent still contains 'theme'", + 2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + assertTrue(variant.getScope().contains(varTheme)); + name.removeTheme(theme); + assertEquals(0, name.getScope().size()); + assertEquals("'theme' was removed from the name", + 1, variant.getScope().size()); + assertFalse(variant.getScope().contains(theme)); + assertTrue(variant.getScope().contains(varTheme)); + } + } Modified: trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java =================================================================== --- trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java 2008-08-19 11:14:19 UTC (rev 65) @@ -91,7 +91,7 @@ _litIdx.getNames(null); fail("getNames(null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -185,7 +185,7 @@ _litIdx.getOccurrences((String)null); fail("getOccurrences((String)null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -195,7 +195,7 @@ _litIdx.getOccurrences((Locator)null); fail("getOccurrences((Locator)null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -205,7 +205,7 @@ _litIdx.getOccurrences("value", null); fail("getOccurrences(\"value\", null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -299,7 +299,7 @@ _litIdx.getVariants((String)null); fail("getVariants((String)null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -309,7 +309,7 @@ _litIdx.getVariants((Locator)null); fail("getVariants((Locator)null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } @@ -319,7 +319,7 @@ _litIdx.getVariants("value", null); fail("getVariants(\"value\", null) is illegal"); } - catch (Exception ex) { + catch (IllegalArgumentException ex) { // noop. } } Modified: trunk/src/test/java/org/tmapi/index/TestScopedIndex.java =================================================================== --- trunk/src/test/java/org/tmapi/index/TestScopedIndex.java 2008-08-14 11:46:44 UTC (rev 64) +++ trunk/src/test/java/org/tmapi/index/TestScopedIndex.java 2008-08-19 11:14:19 UTC (rev 65) @@ -176,10 +176,11 @@ final Name name = createName(); assertEquals(0, name.getScope().size()); final Variant scoped = name.createVariant("Variant", theme); - assertEquals(1, scoped.getScope().size()); + assertEquals("Unexpected variant's scope size", 1, scoped.getScope().size()); _updateIndex(); assertFalse(_scopedIdx.getVariantThemes().isEmpty()); - assertEquals(1, _scopedIdx.getVariantThemes().size()); + assertEquals("Unexpected number of variant themes", + 1, _scopedIdx.getVariantThemes().size()); assertTrue(_scopedIdx.getVariants(theme).contains(scoped)); assertTrue(_scopedIdx.getVariantThemes().contains(theme)); // Add theme to name @@ -198,13 +199,14 @@ name.removeTheme(theme2); _updateIndex(); assertFalse(_scopedIdx.getVariantThemes().isEmpty()); - assertEquals(1, _scopedIdx.getVariantThemes().size()); + assertEquals("The scope change in the name is not reflected in variant", + 1, _scopedIdx.getVariantThemes().size()); assertTrue(_scopedIdx.getVariants(theme).contains(scoped)); assertTrue(_scopedIdx.getVariantThemes().contains(theme)); scoped.addTheme(theme2); _updateIndex(); assertEquals("Change of the variant's scope is not reflected in the index", - 2, _scopedIdx.getVariantThemes().size()); + 2, _scopedIdx.getVariantThemes().size()); assertTrue(_scopedIdx.getVariants(theme).contains(scoped)); assertTrue(_scopedIdx.getVariantThemes().contains(theme)); assertTrue(_scopedIdx.getVariants(theme2).contains(scoped)); @@ -212,7 +214,8 @@ // Add theme to name name.addTheme(theme2); _updateIndex(); - assertEquals(2, _scopedIdx.getVariantThemes().size()); + assertEquals("Adding a theme to the variant's parent is not reflected", + 2, _scopedIdx.getVariantThemes().size()); assertTrue(_scopedIdx.getVariants(theme).contains(scoped)); assertTrue(_scopedIdx.getVariantThemes().contains(theme)); assertTrue(_scopedIdx.getVariants(theme2).contains(scoped)); @@ -220,7 +223,8 @@ // Remove theme from name name.removeTheme(theme2); _updateIndex(); - assertEquals(2, _scopedIdx.getVariantThemes().size()); + assertEquals("Removing the name's theme MUST NOT be reflected in the variant's scope", + 2, _scopedIdx.getVariantThemes().size()); assertTrue(_scopedIdx.getVariants(theme).contains(scoped)); assertTrue(_scopedIdx.getVariantThemes().contains(theme)); assertTrue(_scopedIdx.getVariants(theme2).contains(scoped)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |