Skip to content

Commit

Permalink
Simplify resources content tests #903
Browse files Browse the repository at this point in the history
Simplifies the tests in org.eclipse.core.tests.resources.content:
* Removes obsolete ContentTypeTest superclass for test classes, uses
existing utility functionality instead
* Removes obsolete numbering of assertions
* Replaces try/catch/fail with assertThrows or making test framework
handle the exception

Contributes to
#903
  • Loading branch information
HeikoKlare committed Nov 6, 2024
1 parent 4712d12 commit 53a2431
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.eclipse.core.internal.content.ContentDescription;
import org.eclipse.core.internal.content.ContentType;
Expand All @@ -28,7 +28,7 @@
import org.eclipse.core.runtime.content.IContentDescription;
import org.junit.Test;

public class ContentDescriptionTest extends ContentTypeTest {
public class ContentDescriptionTest {
private static final String CT_VOID = PI_RESOURCES_TESTS + '.' + "void";
private static final QualifiedName ZOO_PROPERTY = new QualifiedName(PI_RESOURCES_TESTS, "zoo");
private static final QualifiedName BAR_PROPERTY = new QualifiedName(PI_RESOURCES_TESTS, "bar");
Expand All @@ -42,89 +42,69 @@ private ContentType getContentType() {
@Test
public void testAllProperties() {
ContentDescription description = new ContentDescription(IContentDescription.ALL, getContentType());
assertTrue("1.0", description.isRequested(FOO_PROPERTY));
assertNull("1.1", description.getProperty(FOO_PROPERTY));
assertTrue(description.isRequested(FOO_PROPERTY));
assertNull(description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1");
assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY));
assertEquals("value1", description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1b");
assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY));
assertTrue("2.0", description.isRequested(BAR_PROPERTY));
assertEquals("value1b", description.getProperty(FOO_PROPERTY));
assertTrue(description.isRequested(BAR_PROPERTY));
description.setProperty(BAR_PROPERTY, "value2");
assertEquals("2.1", "value2", description.getProperty(BAR_PROPERTY));
assertEquals("value2", description.getProperty(BAR_PROPERTY));
description.setProperty(ZOO_PROPERTY, "value3");
assertEquals("2.2", "value3", description.getProperty(ZOO_PROPERTY));
assertEquals("value3", description.getProperty(ZOO_PROPERTY));
description.markImmutable();
try {
description.setProperty(FOO_PROPERTY, "value1c");
fail("3.0 - should have failed");
} catch (IllegalStateException e) {
// success - the object was marked as immutable
}
assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c"));
}

@Test
public void testOneProperty() {
ContentDescription description = new ContentDescription(new QualifiedName[] {FOO_PROPERTY}, getContentType());
assertTrue("1.0", description.isRequested(FOO_PROPERTY));
assertNull("1.1", description.getProperty(FOO_PROPERTY));
assertTrue(description.isRequested(FOO_PROPERTY));
assertNull(description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1");
assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY));
assertEquals("value1", description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1b");
assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY));
assertEquals("value1b", description.getProperty(FOO_PROPERTY));
description.setProperty(BAR_PROPERTY, "value2");
assertFalse("2.0", description.isRequested(BAR_PROPERTY));
assertFalse(description.isRequested(BAR_PROPERTY));
description.setProperty(BAR_PROPERTY, "value2");
assertNull("2.1", description.getProperty(BAR_PROPERTY));
assertNull(description.getProperty(BAR_PROPERTY));
description.markImmutable();
try {
description.setProperty(FOO_PROPERTY, "value1c");
fail("3.0 - should have failed");
} catch (IllegalStateException e) {
// success - the object was marked as immutable
}
assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c"));
}

@Test
public void testZeroProperties() {
ContentDescription description = new ContentDescription(new QualifiedName[0], getContentType());
assertFalse("1.0", description.isRequested(FOO_PROPERTY));
assertNull("1.1", description.getProperty(FOO_PROPERTY));
assertFalse(description.isRequested(FOO_PROPERTY));
assertNull(description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1");
assertNull("1.2", description.getProperty(FOO_PROPERTY));
assertNull(description.getProperty(FOO_PROPERTY));
description.markImmutable();
try {
description.setProperty(FOO_PROPERTY, "value1b");
fail("2.0 - should have failed");
} catch (IllegalStateException e) {
// success - the object was marked as immutable
}
assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1b"));
}

@Test
public void testMultipleProperties() {
ContentDescription description = new ContentDescription(new QualifiedName[] {FOO_PROPERTY, BAR_PROPERTY, ZOO_PROPERTY}, getContentType());
assertTrue("1.0", description.isRequested(FOO_PROPERTY));
assertNull("1.1", description.getProperty(FOO_PROPERTY));
assertTrue(description.isRequested(FOO_PROPERTY));
assertNull(description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1");
assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY));
assertEquals("value1", description.getProperty(FOO_PROPERTY));
description.setProperty(FOO_PROPERTY, "value1b");
assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY));
assertEquals("value1b", description.getProperty(FOO_PROPERTY));
description.setProperty(BAR_PROPERTY, "value2");
assertTrue("2.0", description.isRequested(BAR_PROPERTY));
assertTrue(description.isRequested(BAR_PROPERTY));
description.setProperty(BAR_PROPERTY, "value2");
assertEquals("2.1", "value2", description.getProperty(BAR_PROPERTY));
assertTrue("2.2", description.isRequested(ZOO_PROPERTY));
assertEquals("value2", description.getProperty(BAR_PROPERTY));
assertTrue(description.isRequested(ZOO_PROPERTY));
description.setProperty(ZOO_PROPERTY, "value3");
assertEquals("2.3", "value3", description.getProperty(ZOO_PROPERTY));
assertFalse("3.0", description.isRequested(FRED_PROPERTY));
assertEquals("value3", description.getProperty(ZOO_PROPERTY));
assertFalse(description.isRequested(FRED_PROPERTY));
description.setProperty(FRED_PROPERTY, "value3");
assertNull("3.1", description.getProperty(FRED_PROPERTY));
assertNull(description.getProperty(FRED_PROPERTY));
description.markImmutable();
try {
description.setProperty(FOO_PROPERTY, "value1c");
fail("4.0 - should have failed");
} catch (IllegalStateException e) {
// success - the object was marked as immutable
}
assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c"));
}
}

This file was deleted.

Loading

0 comments on commit 53a2431

Please sign in to comment.