Ignore:
Timestamp:
11/01/11 23:20:13 (13 years ago)
Author:
masberg
Message:

Additional cleanups, clearer error messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestModelicaProject.java

    r1059 r1069  
    9595                "components_bananza",
    9696                "nested_models",
    97                 "childless_package",               
     97                "childless_package",
    9898                "import_rich_model",
    99                 "folder_package",               
     99                "folder_package",
    100100                "hepp",
    101101                "muu",
     
    107107     */
    108108    @Test
    109     public void testGetClass() 
     109    public void testGetClass()
    110110            throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException, Exception {
    111111        /*
     
    136136        testGetClass("components_bananza.a_class", "components_bananza.a_class", IModelicaClass.Restriction.CLASS);
    137137
    138         testGetClass("components_bananza.a_type", "components_bananza.a_type", IModelicaClass.Restriction.TYPE);   
     138        testGetClass("components_bananza.a_type", "components_bananza.a_type", IModelicaClass.Restriction.TYPE);
    139139
    140140        testGetClass("components_bananza.a_connector", "components_bananza.a_connector", IModelicaClass.Restriction.CONNECTOR);
     
    231231        }
    232232
    233         String errorMsg = "could not find following expeced root classes:";
     233        String errorMsg = "Could not find following expected root classes:";
    234234        for (String cls : expectedRootPackages) {
    235235            errorMsg += " " + cls;
     
    251251        testFindElement("package_look_alike", IModelicaFolder.class, null);
    252252
    253         /* 
     253        /*
    254254         * FIXME: We are currently not creating the empty file package.mo inside package_look_alike
    255255         * because it makes OMC to freeze. When this problem has been fixed, we can run this test
     
    294294        testFindElement("root_model.mo", IModelicaSourceFile.class, null);
    295295
    296         testFindElement("empty_file", IModelicaFile.class, null);   
     296        testFindElement("empty_file", IModelicaFile.class, null);
    297297
    298298        testFindElement("README.txt", IModelicaFile.class, null);
     
    300300        /*
    301301         * check what happens when trying to find non-existing elements
    302          * 
     302         *
    303303         * BEWARE, the test below can break if elements search for are added
    304304         * to the area51 modelica project
     
    307307
    308308        testFindElementNonExisting("packages_folder/file_package.mo/file_package2");
    309        
     309
    310310        testFindElementNonExisting("non_existing_file");
    311311
     
    325325    }
    326326
    327     private void testGetClass(String className, String expectedFullName, IModelicaClass.Restriction expectedRestriction) throws Exception {
     327    private void testGetClass(String className, String expectedFullName, IModelicaClass.Restriction expectedRestriction)
     328            throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException {
    328329        IModelicaClass pkg = project.getClass(className);
    329330
     
    332333        }
    333334
    334         assertNotNull("project.getClass() returned null for \"" + className + "\"", pkg);
     335        String getClassFail = "project.getClass() returned null for className \"" + className + "\".";
     336
     337        assertNotNull(getClassFail, pkg);
    335338
    336339        String actualFullName = pkg.getFullName();
    337 
    338         assertEquals("Expected pkg.getFullName() to return \"" + expectedFullName + "\" for className \"" + className + "\", but got \"" + actualFullName + "\".", expectedFullName, actualFullName);
     340        String fullNameFail = "Expected pkg.getFullName() to return \"" + expectedFullName + "\" for className \"" + className +
     341                "\", but got \"" + actualFullName + "\".";
     342
     343        assertEquals(fullNameFail, expectedFullName, actualFullName);
    339344
    340345        IModelicaClass.Restriction actualRestriction = pkg.getRestriction();
    341 
    342         assertEquals("Expected restriction " + expectedRestriction + ", but got " + actualRestriction + ".", expectedRestriction, actualRestriction);
     346        String restrictionFail = "For className \"" + className + "\", the expected restriction was \"" + expectedRestriction +
     347                "\", but we got \"" + actualRestriction + "\".";
     348
     349        assertEquals(restrictionFail, expectedRestriction, actualRestriction);
    343350    }
    344351
    345352    private void testGetClassNonExisting(String className) throws Exception {
    346353        IModelicaClass pkg = project.getClass(className);
    347 
    348         assertNull("project.getClass() was called with \"" + className + "\", and was expected to return NULL, but didn't.", pkg);
    349     }
    350    
     354        String getClassNonExistingFail = "project.getClass() was called with className \"" + className +
     355                "\", and was expected to return NULL, but didn't.";
     356
     357        assertNull(getClassNonExistingFail, pkg);
     358    }
     359
    351360    private void testFindElement(String pathName, Class<?> expectedClass, IModelicaClass.Restriction expectedRestriction)
    352361            throws ConnectException, UnexpectedReplyException, CompilerInstantiationException, InvocationError, CoreException {
    353362        Path path = new Path(pathName);
    354363        IModelicaElement element = project.findElement(path);
    355        
    356         assertNotNull(element);
    357        
     364        String findElementFail = "project.findElement() returned null for pathName \"" + pathName + "\".";
     365
     366        assertNotNull(findElementFail, element);
     367
    358368        Class<?> actualClass = element.getClass();
    359369        String expectedClassName = expectedClass.getCanonicalName();
    360370        String actualClassName = actualClass.getCanonicalName();
    361         String errorMsgClass = "Was expecting " + expectedClassName + ", but got " + actualClassName;
    362        
     371        String errorMsgClass = "For pathName \"" + pathName + "\", we expected to find an element that is an instance of \"" +
     372                expectedClassName + "\", but the returned class \"" + actualClassName + "\" is not an instance of that class.";
     373
    363374        assertTrue(errorMsgClass, expectedClass.isAssignableFrom(actualClass));
    364        
     375
    365376        if (expectedRestriction != null) {
    366             assertTrue(element instanceof IModelicaClass);
     377            String typeFail = "Since a restriction \"" + expectedRestriction + "\" was specified for pathName \"" +
     378                    pathName + "\", it was expected to be an instance of IModelicaClass, but it was not.";
     379
     380            assertTrue(typeFail, element instanceof IModelicaClass);
     381
    367382            IModelicaClass.Restriction actualRestriction = ((IModelicaClass)element).getRestriction();
    368            
    369             assertEquals("Expected restriction " + expectedRestriction + ", but got " + actualRestriction + ".", expectedRestriction, actualRestriction);
     383            String restrictionFail = "For pathName \"" + pathName + "\", the expected restriction was \"" + expectedRestriction
     384                    + "\", but we got \"" + actualRestriction + "\".";
     385
     386            assertEquals(restrictionFail, expectedRestriction, actualRestriction);
    370387        }
    371388    }
    372    
    373     private void testFindElementNonExisting(String pathName) 
     389
     390    private void testFindElementNonExisting(String pathName)
    374391            throws ConnectException, UnexpectedReplyException, CompilerInstantiationException, InvocationError, CoreException {
    375392        Path path = new Path(pathName);
    376393        IModelicaElement element = project.findElement(path);
    377         assertNull(element);
    378     }
    379 
    380     private void printAll(Collection<? extends IModelicaElement> children, int indent) throws Exception {       
     394        String findElementNonExistingFail = "project.findElement() was called with pathName \"" + pathName +
     395                "\", and was expected to return NULL, but didn't.";
     396
     397        assertNull(findElementNonExistingFail, element);
     398    }
     399
     400    private void printAll(Collection<? extends IModelicaElement> children, int indent)
     401            throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException {
    381402        for (IModelicaElement elem : children) {
    382403            for (int i = 0; i < indent; i++) System.out.print("  ");
Note: See TracChangeset for help on using the changeset viewer.