Skip to content

Commit

Permalink
and even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Nov 1, 2024
1 parent 5b26335 commit fbedc16
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
*******************************************************************************/
package org.eclipse.jdt.ui.tests.packageview;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.eclipse.jdt.testplugin.JavaProjectHelper;
import org.eclipse.jdt.testplugin.JavaTestPlugin;
Expand Down Expand Up @@ -105,84 +105,84 @@ public class ContentProviderTests1 {
public void testGetChildrenProjectWithSourceFolders() throws Exception {
Object[] expectedChildren= new Object[]{fRoot1, fDotClasspathFile, dotSettings, fDotProjectFile};
Object[] actualChildren= fProvider.getChildren(fJProject2);
assertTrue("Wrong children found for project", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "Wrong children found for project");//$NON-NLS-1$
}

@Test
public void testGetChildrentMidLevelFragment() throws Exception {
Object[] expectedChildren= new Object[]{fPack4, fPack5};
Object[] actualChildren= fProvider.getChildren(fPack3);
assertTrue("Wrong children found for PackageFragment", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "Wrong children found for PackageFragment");//$NON-NLS-1$
}

@Test
public void testGetChildrenBottomLevelFragment() throws Exception {
Object[] expectedChildren= new Object[]{fCU1};
Object[] actualChildren= fProvider.getChildren(fPack2);
assertTrue("Wrong children found for PackageFragment", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "Wrong children found for PackageFragment");//$NON-NLS-1$
}

@Test
public void testGetChildrenMidLevelFragmentInArchive() throws Exception {
Object[] expectedChildren= new Object[]{fPackJunitSamplesMoney, fCUAllTests, fCUSimpleTest, fCUVectorTest };
Object[] actualChildren= fProvider.getChildren(fPackJunitSamples);
assertTrue("wrong chidren found for mid level PackageFragment in Archive", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "wrong chidren found for mid level PackageFragment in Archive");//$NON-NLS-1$
}

@Test
public void testGetChildrenBottomLevelFragmentInArchive() throws Exception {
Object[] expectedChildren= new Object[]{fCUIMoney, fCUMoney, fCUMoneyBag, fCUMoneyTest};
Object[] actualChildren= fProvider.getChildren(fPackJunitSamplesMoney);
assertTrue("wrong children found for a bottom PackageFragment in PackageFragmentRoot Archive", compareArrays(actualChildren, expectedChildren)); //$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "wrong children found for a bottom PackageFragment in PackageFragmentRoot Archive"); //$NON-NLS-1$
}

@Test
public void testGetChildrenSourceFolder() throws Exception {
Object[] expectedChildren = new Object[] { fPack1, fPack2, fPack3, fRoot1.getPackageFragment("")};//$NON-NLS-1$
Object[] actualChildren = fProvider.getChildren(fRoot1);
assertTrue("Wrong children found for PackageFragmentRoot", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "Wrong children found for PackageFragmentRoot");//$NON-NLS-1$
}

@Test
public void testGetChildrenArchive(){ Object[] expectedChildren= new Object[]{fPackJunit, fArchiveFragmentRoot.getPackageFragment("")};//$NON-NLS-1$
Object[] actualChildren= fProvider.getChildren(fArchiveFragmentRoot);
assertTrue("Wrong child found for PackageFragmentRoot Archive", compareArrays(actualChildren, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(actualChildren, expectedChildren), "Wrong child found for PackageFragmentRoot Archive");//$NON-NLS-1$
}

//---------------Get Parent Tests-----------------------------

@Test
public void testGetParentArchive() throws Exception {
Object parent= fProvider.getParent(fArchiveFragmentRoot);
assertSame("Wrong parent found for PackageFragmentRoot Archive", parent, fJProject1);//$NON-NLS-1$
assertSame(parent, fJProject1, "Wrong parent found for PackageFragmentRoot Archive");//$NON-NLS-1$
}

@Test
public void testGetParentMidLevelFragmentInArchive() throws Exception {
Object expectedParent= fPackJunitSamples;
Object actualParent= fProvider.getParent(fPackJunitSamplesMoney);
assertEquals("Wrong parent found for a NON top level PackageFragment in an Archive", expectedParent, actualParent);//$NON-NLS-1$
assertEquals(expectedParent, actualParent, "Wrong parent found for a NON top level PackageFragment in an Archive");//$NON-NLS-1$
}

@Test
public void testGetParentTopLevelFragmentInArchive() throws Exception {
Object expectedParent= fPackJunit;
Object actualParent= fProvider.getParent(fPackJunitSamples);
assertEquals("Wrong parent found for a top level PackageFragment in an Archive", expectedParent, actualParent); //$NON-NLS-1$
assertEquals(expectedParent, actualParent, "Wrong parent found for a top level PackageFragment in an Archive"); //$NON-NLS-1$
}

@Test
public void testGetParentTopLevelFragment() throws Exception {
Object expectedParent= fRoot1;
Object actualParent= fProvider.getParent(fPack3);
assertEquals("Wrong parent found for a top level PackageFragment", expectedParent, actualParent);//$NON-NLS-1$
assertEquals(expectedParent, actualParent, "Wrong parent found for a top level PackageFragment");//$NON-NLS-1$
}

@Test
public void testGetParentMidLevelFragment() throws Exception {
Object expectedParent= fPack3;
Object actualParent= fProvider.getParent(fPack4);
assertEquals("Wrong parent found for a NON top level PackageFragment", expectedParent, actualParent);//$NON-NLS-1$
assertEquals(expectedParent, actualParent, "Wrong parent found for a NON top level PackageFragment");//$NON-NLS-1$
}

@Test
Expand All @@ -195,9 +195,9 @@ public void testDeleteBottomLevelFragment() throws Exception {
// Force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

assertTrue("Remove happened", fMyPart.hasRemoveHappened());//$NON-NLS-1$
assertTrue("Correct Remove", fMyPart.getRemovedObjects().contains(fPack2));//$NON-NLS-1$
assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size());//$NON-NLS-1$
assertTrue(fMyPart.hasRemoveHappened(), "Remove happened");//$NON-NLS-1$
assertTrue(fMyPart.getRemovedObjects().contains(fPack2), "Correct Remove");//$NON-NLS-1$
assertEquals(0, fMyPart.getRefreshedObject().size(), "No refreshes");//$NON-NLS-1$
}

@Test
Expand All @@ -212,9 +212,9 @@ public void testAddBottomLevelFragment() throws Exception {
// Force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

assertTrue("Add happened", fMyPart.hasAddHappened()); //$NON-NLS-1$
assertEquals("Correct Add", test, fMyPart.getAddedObject()); //$NON-NLS-1$
assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$
assertTrue(fMyPart.hasAddHappened(), "Add happened"); //$NON-NLS-1$
assertEquals(test, fMyPart.getAddedObject(), "Correct Add"); //$NON-NLS-1$
assertEquals(0, fMyPart.getRefreshedObject().size(), "No refreshes"); //$NON-NLS-1$
}

@Test
Expand All @@ -227,7 +227,7 @@ public void testChangedTopLevelPackageFragment() throws Exception {
// Force events from display
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

assertEquals("No refresh happened", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$
assertEquals(0, fMyPart.getRefreshedObject().size(), "No refresh happened"); //$NON-NLS-1$
}

@Test
Expand All @@ -241,7 +241,7 @@ public void testChangeBottomLevelPackageFragment() throws Exception {
// Force events from display
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

assertEquals("No refresh happened", 0, fMyPart.getRefreshedObject().size());//$NON-NLS-1$
assertEquals(0, fMyPart.getRefreshedObject().size(), "No refresh happened");//$NON-NLS-1$
}

@Test
Expand All @@ -255,7 +255,7 @@ public void testRemoveCUsFromPackageFragment() throws Exception {
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

// removing more than one CU now results in a refresh.
assertEquals("One refresh", 1, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$
assertEquals(1, fMyPart.getRefreshedObject().size(), "One refresh"); //$NON-NLS-1$
}

@Test
Expand All @@ -268,9 +268,9 @@ public void testRemoveCUFromPackageFragment() throws Exception {
// Force events from display
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {}

assertTrue("Remove happened", fMyPart.hasRemoveHappened()); //$NON-NLS-1$
assertTrue("Correct refresh", fMyPart.getRemovedObjects().contains(fCU2)); //$NON-NLS-1$
assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$
assertTrue(fMyPart.hasRemoveHappened(), "Remove happened"); //$NON-NLS-1$
assertTrue(fMyPart.getRemovedObjects().contains(fCU2), "Correct refresh"); //$NON-NLS-1$
assertEquals(0, fMyPart.getRefreshedObject().size(), "No refreshes"); //$NON-NLS-1$
}

@Test
Expand All @@ -282,11 +282,11 @@ public void testBug65240() throws Exception {
fJProject2.setRawClasspath(new IClasspathEntry[] {element.getClasspathEntry()}, null);
Object[] expectedChildren= new Object[]{fPack4.getResource(), fPack5};
Object[] children= fProvider.getChildren(fPack3.getResource());
assertTrue("Wrong children found for folder", compareArrays(children, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(children, expectedChildren), "Wrong children found for folder");//$NON-NLS-1$

expectedChildren= new Object[]{fPack1.getResource(), fPack2.getResource(), fPack3.getResource()};
children= fProvider.getChildren(fRoot1);
assertTrue("Wrong children found for source folder", compareArrays(children, expectedChildren));//$NON-NLS-1$
assertTrue(compareArrays(children, expectedChildren), "Wrong children found for source folder");//$NON-NLS-1$
}

// public void testAddWorkingCopyCU() throws Exception {
Expand Down Expand Up @@ -323,7 +323,7 @@ public void testBug65240() throws Exception {
// }


@Before
@BeforeEach
public void setUp() throws Exception {
fWorkspace= ResourcesPlugin.getWorkspace();
assertNotNull(fWorkspace);
Expand All @@ -337,8 +337,8 @@ public void setUp() throws Exception {
fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");//$NON-NLS-1$//$NON-NLS-2$
fJProject2= JavaProjectHelper.createJavaProject("TestProject2", "bin");//$NON-NLS-1$//$NON-NLS-2$

assertNotNull("project1 null", fJProject1);//$NON-NLS-1$
assertNotNull("project2 null", fJProject2);//$NON-NLS-1$
assertNotNull(fJProject1, "project1 null");//$NON-NLS-1$
assertNotNull(fJProject2, "project2 null");//$NON-NLS-1$

fJProject1.setRawClasspath(new IClasspathEntry[0], null);

Expand All @@ -362,22 +362,22 @@ else if (".project".equals(file.getName()))//$NON-NLS-1$

// Set up project #1 : External Jar and zip file
IPackageFragmentRoot jdk= JavaProjectHelper.addVariableRTJar(fJProject1, "JRE_LIB_TEST", null, null);//$NON-NLS-1$
assertNotNull("jdk not found", jdk);//$NON-NLS-1$
assertNotNull(jdk, "jdk not found");//$NON-NLS-1$

java.io.File junitSrcArchive= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.JUNIT_SRC_381);
assertNotNull("junit src not found", junitSrcArchive);//$NON-NLS-1$
assertTrue("junit src not found", junitSrcArchive.exists());//$NON-NLS-1$
assertNotNull(junitSrcArchive, "junit src not found");//$NON-NLS-1$
assertTrue(junitSrcArchive.exists(), "junit src not found");//$NON-NLS-1$

fArchiveFragmentRoot= JavaProjectHelper.addSourceContainerWithImport(fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);//$NON-NLS-1$
assertTrue("Unable to create zipfile archive",fArchiveFragmentRoot.exists());//$NON-NLS-1$
assertTrue(fArchiveFragmentRoot.exists(),"Unable to create zipfile archive");//$NON-NLS-1$

fPackJunit= fArchiveFragmentRoot.getPackageFragment("junit");//$NON-NLS-1$
fPackJunitSamples= fArchiveFragmentRoot.getPackageFragment("junit.samples");//$NON-NLS-1$
fPackJunitSamplesMoney= fArchiveFragmentRoot.getPackageFragment("junit.samples.money");//$NON-NLS-1$

assertNotNull("creating fPackJunit", fPackJunit);//$NON-NLS-1$
assertNotNull("creating fPackJunitSamples", fPackJunitSamples);//$NON-NLS-1$
assertNotNull("creating fPackJunitSamplesMoney",fPackJunitSamplesMoney);//$NON-NLS-1$
assertNotNull(fPackJunit, "creating fPackJunit");//$NON-NLS-1$
assertNotNull(fPackJunitSamples, "creating fPackJunitSamples");//$NON-NLS-1$
assertNotNull(fPackJunitSamplesMoney,"creating fPackJunitSamplesMoney");//$NON-NLS-1$

fCUIMoney= fPackJunitSamplesMoney.getCompilationUnit("IMoney.java");//$NON-NLS-1$
fCUMoney= fPackJunitSamplesMoney.getCompilationUnit("Money.java");//$NON-NLS-1$
Expand Down Expand Up @@ -431,7 +431,7 @@ public void setUpMockView() throws Exception {
assertNotNull(fProvider);
}

@After
@AfterEach
public void tearDown() throws Exception {
fArchiveFragmentRoot.close();

Expand Down
Loading

0 comments on commit fbedc16

Please sign in to comment.