Ignore:
Timestamp:
11/11/13 01:14:18 (11 years ago)
Author:
masberg
Message:

Fix warnings, use more modern JUnit-style, formatting tweaks.

File:
1 edited

Legend:

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

    r720 r1834  
    22 * This file is part of Modelica Development Tooling.
    33 *
    4  * Copyright (c) 2005, Linkpings universitet, Department of
     4 * Copyright (c) 2005, Linköpings universitet, Department of
    55 * Computer and Information Science, PELAB
    66 *
     
    2323 *   distribution.
    2424 *
    25  * * Neither the name of Linkpings universitet nor the names of its
     25 * * Neither the name of Link�pings universitet nor the names of its
    2626 *   contributors may be used to endorse or promote products derived from
    2727 *   this software without specific prior written permission.
     
    4242package org.modelica.mdt.test;
    4343
     44import static org.junit.Assert.assertEquals;
     45import static org.junit.Assert.assertFalse;
     46import static org.junit.Assert.assertNotNull;
     47import static org.junit.Assert.assertTrue;
     48
    4449import org.eclipse.core.resources.IFile;
    4550import org.eclipse.core.resources.IFolder;
    4651import org.eclipse.core.resources.IProject;
     52import org.eclipse.core.resources.IWorkspace;
     53import org.eclipse.core.resources.IWorkspaceRoot;
    4754import org.eclipse.core.resources.ResourcesPlugin;
     55import org.eclipse.core.runtime.CoreException;
    4856import org.eclipse.jface.viewers.StructuredSelection;
    4957import org.eclipse.jface.wizard.IWizard;
    5058import org.eclipse.swt.widgets.Button;
    5159import org.eclipse.swt.widgets.Text;
     60import org.junit.BeforeClass;
     61import org.junit.Test;
    5262import org.modelica.mdt.core.IModelicaProject;
    5363import org.modelica.mdt.core.ModelicaCore;
     
    5969import abbot.tester.swt.TextTester;
    6070
    61 import junit.framework.Assert;
    62 import junit.framework.TestCase;
    63 
    64 /**
    65  * @author Elmir Jagudin
    66  */
    67 
    68 public class TestNewPackageWizard extends TestCase
    69 {
    70     private static final String PROJECT_NAME_1 =
    71         TestNewPackageWizard.class.getName() + "1";
    72 
    73     private TextTester ttester;
    74     private ButtonTester btester;
    75    
     71public class TestNewPackageWizard {
     72    private static final String PROJECT_NAME_1 = TestNewPackageWizard.class.getName() + "1";
     73
     74    private static TextTester ttester;
     75    private static ButtonTester btester;
     76
    7677    private Text packageName;
    7778    private Text parentPackage;
     
    8081    private Button isEncapsulated;
    8182    private Button finish;
    82    
    83     private IProject project;
    84     private StructuredSelection fileDestination;
    85 
    86     @Override
    87     protected void setUp() throws Exception
    88     {
    89         /*
    90          * setup project
    91          */
    92         project =
    93             ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME_1);
    94        
    95         /* create project only if it does not exist yet */
    96         if (!project.exists())
    97         {
    98             IModelicaProject mproj =
    99                 ModelicaCore.getModelicaRoot().createProject(project);//PROJECT_NAME_1);
    100             Assert.assertNotNull("failed to create project", mproj);
    101            
     83
     84    private static IProject project;
     85    private static StructuredSelection fileDestination;
     86
     87    @BeforeClass
     88    public static void setUp() throws CoreException {
     89        IWorkspace workspace = ResourcesPlugin.getWorkspace();
     90        IWorkspaceRoot workspaceRoot = workspace.getRoot();
     91        project = workspaceRoot.getProject(PROJECT_NAME_1);
     92
     93        if (!project.exists()) {
     94            IModelicaProject mproj = ModelicaCore.getModelicaRoot().createProject(project);
     95            assertNotNull("failed to create project", mproj);
     96
    10297            project = mproj.getWrappedProject();
    10398        }
    10499
    105         /*
    106          * create the selection that points at the root of the created project
    107          */
     100        // create the selection that points at the root of the created project
    108101        fileDestination = new StructuredSelection(project);
    109        
    110         /*
    111          * setup testing support objects
    112          */
     102
     103        // setup testing support objects
    113104        ttester = TextTester.getTextTester();
    114105        btester = ButtonTester.getButtonTester();
    115 
    116     }
    117    
    118     public void openWizardAndFetchWidgets()
    119     {
    120         /*
    121          * pop-up the wizard
    122          */
    123         IWizard wizard =
    124             Utility.openWizard("org.modelica.mdt.NewPackageWizard",
    125                     fileDestination);       
     106    }
     107
     108    private void openWizardAndFetchWidgets() {
     109        // pop-up the wizard
     110        IWizard wizard = Utility.openWizard("org.modelica.mdt.NewPackageWizard", fileDestination);
    126111        assertFalse(wizard.canFinish());
    127112
    128        
    129        
    130         /* fetch widgets */
    131         packageName =
    132             TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG);
    133         parentPackage =
    134             TextTester.getInstrumentedText(NewTypePage.PARENT_PACKAGE_TAG);
    135         packageDesc =
    136             TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG);
    137         sourceFolder =
    138             TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG);
    139         isEncapsulated =
    140             ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG);
    141         finish =
    142             Utility.findButtonByText("&Finish");
    143 
    144        
    145         /* make some checks on the state of the wizards */
    146         assertEquals("Wrong source folder selected",
    147                 sourceFolder.getText(), PROJECT_NAME_1);       
    148         assertEquals("Junk present in package name field",
    149                 packageName.getText(), "");
    150         assertFalse("is encapsulated unexpectedly selected",
    151                 isEncapsulated.getSelection());
    152         assertFalse("Finish button not disabled",
    153                 finish.getEnabled());
    154        
    155 
     113        // fetch widgets
     114        packageName = TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG);
     115        parentPackage = TextTester.getInstrumentedText(NewTypePage.PARENT_PACKAGE_TAG);
     116        packageDesc = TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG);
     117        sourceFolder = TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG);
     118        isEncapsulated = ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG);
     119        finish = Utility.findButtonByText("&Finish");
     120
     121        // make some checks on the state of the wizards
     122        assertEquals("Wrong source folder selected", sourceFolder.getText(), PROJECT_NAME_1);
     123        assertEquals("Junk present in package name field", packageName.getText(), "");
     124        assertFalse("is encapsulated unexpectedly selected", isEncapsulated.getSelection());
     125        assertFalse("Finish button not disabled", finish.getEnabled());
    156126    }
    157127
     
    159129     * create a plain package
    160130     */
    161     public void testCreatePackge()
    162     {
    163         openWizardAndFetchWidgets();
    164        
     131    @Test
     132    public void testCreatePackage() {
     133        openWizardAndFetchWidgets();
     134
    165135        String name = "pkg1";
    166        
    167         /*
    168          * fill in the wizard fields
    169          */
     136
     137        // fill in the wizard fields
    170138        ttester.actionEnterText(packageName, name);
    171139
    172         /* wait for the name change to propogate to enable the finish button */
    173         while (!finish.getEnabled()) { Utility.sleep(this, 100); }
    174         btester.actionClick(finish);
    175 
    176         /* check if the package folder was created */
     140        // wait for the name change to propagate to enable the finish button
     141        while (!finish.getEnabled()) {
     142            Utility.sleep(this, 100);
     143        }
     144        btester.actionClick(finish);
     145
     146        // check if the package folder was created
    177147        IFolder folder = project.getFolder(name);
    178148        assertTrue("no package folder was created", folder.exists());
    179149
    180         /*
    181          * check that the generated package.mo exists and is sane
    182          */
     150        // check that the generated package.mo exists and is sane
    183151        IFile packageMo = folder.getFile("package.mo");
    184152        assertTrue("package.mo was not created", packageMo.exists());
    185        
    186         boolean same =
    187             Utility.compareContent(packageMo,
    188                 "package " + name + "\n"+
    189                 "\n"+
    190                 "end " + name + ";");
     153
     154        String expectedContent = String.format("package %s\n\nend %s;", name, name);
     155        boolean same = Utility.compareContent(packageMo, expectedContent);
    191156        assertTrue("unexpected conted created in the package.mo", same);
    192        
    193 //TODO fix the bug that causes this test below to fail and expand   
    194 // testCreatePackageWithDesc(), testEncapsulatedCreatePackage() and
    195 // testEncapsulatedCreatePackageWithDesc() tests with creating a subpackage
    196 // after the main package is created
    197         /*
    198          * test to create a nested package inside pkg1
    199          */
    200        
    201         openWizardAndFetchWidgets();
    202        
     157
     158        // test to create a nested package inside pkg1
     159        openWizardAndFetchWidgets();
     160
    203161        String subName = "sub_pkg1";
    204        
    205         /*
    206          * fill in the wizard fields
    207          */
     162
     163        // fill in the wizard fields
    208164        ttester.actionEnterText(packageName, subName);
    209165        ttester.actionEnterText(parentPackage, name);
    210166
    211         /*
    212          * wait tops 5 seconds for the name change to propogate
    213          * to enable the finish button
    214          */
     167        // wait tops 5 seconds for the name change to propagate
     168        // to enable the finish button
    215169        long waitUntil = System.currentTimeMillis() + 5000;
    216         while (!finish.getEnabled() && waitUntil > System.currentTimeMillis())
    217         {
     170        while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) {
    218171            Utility.sleep(this, 95);
    219172        }
    220173        btester.actionClick(finish);
    221174
    222         /* check if the package folder was created */
     175        // check if the package folder was created
    223176        folder = folder.getFolder(subName);
    224177        assertTrue("no package folder was created", folder.exists());
    225178
    226         /*
    227          * check that the generated package.mo exists and is sane
    228          */
     179        // check that the generated package.mo exists and is sane
    229180        packageMo = folder.getFile("package.mo");
    230181        assertTrue("package.mo was not created", packageMo.exists());
    231        
    232         same =
    233             Utility.compareContent(packageMo,
    234                 "within " + name + ";\n" +
    235                 "\n" +
    236                 "package " + subName + "\n" +
    237                 "\n"+
    238                 "end " + subName + ";");
    239         assertTrue("unexpected conted created in the package.mo", same);
    240 
    241     }
    242    
     182
     183        String expectedContentSub = String.format("within %s;\n\npackage %s\n\nend %s;",
     184                name, subName, subName);
     185        boolean sameSub = Utility.compareContent(packageMo, expectedContentSub);
     186        assertTrue("unexpected conted created in the package.mo", sameSub);
     187    }
     188
    243189    /**
    244190     * create a plain package with description
    245191     */
    246     public void testCreatePackgeWithDesc()
    247     {
    248         openWizardAndFetchWidgets();
    249        
     192    @Test
     193    public void testCreatePackgeWithDesc() {
     194        openWizardAndFetchWidgets();
     195
    250196        String name = "pkg2";
    251197        String description = "jolly good package";
    252        
    253         /*
    254          * fill in the wizard fields
    255          */
     198
     199        // fill in the wizard fields
    256200        ttester.actionEnterText(packageName, name);
    257201        ttester.actionEnterText(packageDesc, description);
    258    
    259 
    260         /* wait for the name change to propogate to enable the finish button */
    261         while (!finish.getEnabled()) { Utility.sleep(this, 100); }
    262         btester.actionClick(finish);
    263 
    264         /* check if the package folder was created */
     202
     203        // wait for the name change to propagate to enable the finish button
     204        while (!finish.getEnabled()) {
     205            Utility.sleep(this, 100);
     206        }
     207        btester.actionClick(finish);
     208
     209        // check if the package folder was created
    265210        IFolder folder = project.getFolder(name);
    266211        assertTrue("no package folder was created", folder.exists());
    267212
    268         /*
    269          * check that the generated package.mo exists and is sane
    270          */
     213        // check that the generated package.mo exists and is sane
    271214        IFile packageMo = folder.getFile("package.mo");
    272215        assertTrue("package.mo was not created", packageMo.exists());
    273        
    274         boolean same =
    275             Utility.compareContent(packageMo,
    276                 "package " + name + " \"" + description + "\"" + "\n"+
    277                 "\n"+
    278                 "end " + name + ";");
     216
     217        String expectedContent = String.format("package %s \"%s\"\n\nend %s;", name, description, name);
     218        boolean same = Utility.compareContent(packageMo, expectedContent);
    279219        assertTrue("unexpected conted created in the package.mo", same);
    280        
    281         /*
    282          * test to create a nested package inside pkg2
    283          */
    284        
    285         openWizardAndFetchWidgets();
    286        
     220
     221        // test to create a nested package inside pkg2
     222        openWizardAndFetchWidgets();
     223
    287224        String subName = "sub_pkg2";
    288225        description = "a jolly good subpackage";
    289        
    290         /*
    291          * fill in the wizard fields
    292          */
     226
     227        // fill in the wizard fields
    293228        ttester.actionEnterText(packageName, subName);
    294229        ttester.actionEnterText(parentPackage, name);
    295230        ttester.actionEnterText(packageDesc, description);
    296231
    297         /*
    298          * wait tops 5 seconds for the name change to propogate
    299          * to enable the finish button
    300          */
     232        // wait tops 5 seconds for the name change to propagate
     233        // to enable the finish button
    301234        long waitUntil = System.currentTimeMillis() + 5000;
    302         while (!finish.getEnabled() && waitUntil > System.currentTimeMillis())
    303         {
     235        while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) {
    304236            Utility.sleep(this, 95);
    305237        }
    306238        btester.actionClick(finish);
    307239
    308         /* check if the package folder was created */
     240        // check if the package folder was created
    309241        folder = folder.getFolder(subName);
    310242        assertTrue("no package folder was created", folder.exists());
    311243
    312         /*
    313          * check that the generated package.mo exists and is sane
    314          */
     244        // check that the generated package.mo exists and is sane
    315245        packageMo = folder.getFile("package.mo");
    316246        assertTrue("package.mo was not created", packageMo.exists());
    317        
    318         same =
    319             Utility.compareContent(packageMo,
    320                 "within " + name + ";\n" +
    321                 "\n" +
    322                 "package " + subName + " \"" + description + "\"" + "\n" +
    323                 "\n"+
    324                 "end " + subName + ";");
    325         assertTrue("unexpected conted created in the package.mo", same);
    326     }
    327    
     247
     248        String expectedContentSub = String.format("within %s;\n\npackage %s \"%s\"\n\nend %s;",
     249                name, subName, description, subName);
     250        boolean sameSub = Utility.compareContent(packageMo, expectedContentSub);
     251        assertTrue("unexpected conted created in the package.mo", sameSub);
     252    }
     253
    328254    /**
    329255     * create a encapsulated package
    330256     */
    331     public void testEncapsulatedCreatePackge()
    332     {
    333         openWizardAndFetchWidgets();
    334        
     257    @Test
     258    public void testEncapsulatedCreatePackge() {
     259        openWizardAndFetchWidgets();
     260
    335261        String name = "pkg3";
    336        
    337         /*
    338          * fill in the wizard fields
    339          */
     262
     263        // fill in the wizard fields
    340264        ttester.actionEnterText(packageName, name);
    341265        btester.actionClick(isEncapsulated);
    342266
    343         /* wait for the name change to propogate to enable the finish button */
    344         while (!finish.getEnabled()) { Utility.sleep(this, 100); }
    345         btester.actionClick(finish);
    346 
    347         /* check if the package folder was created */
     267        // wait for the name change to propagate to enable the finish button
     268        while (!finish.getEnabled()) {
     269            Utility.sleep(this, 100);
     270        }
     271        btester.actionClick(finish);
     272
     273        // check if the package folder was created
    348274        IFolder folder = project.getFolder(name);
    349275        assertTrue("no package folder was created", folder.exists());
    350276
    351         /*
    352          * check that the generated package.mo exists and is sane
    353          */
     277        // check that the generated package.mo exists and is sane
    354278        IFile packageMo = folder.getFile("package.mo");
    355279        assertTrue("package.mo was not created", packageMo.exists());
    356        
    357         boolean same =
    358             Utility.compareContent(packageMo,
    359                 "encapsulated package " + name + "\n"+
    360                 "\n"+
    361                 "end " + name + ";");
     280
     281        String expectedContent = String.format("encapsulated package %s\n\nend %s;", name, name);
     282        boolean same = Utility.compareContent(packageMo, expectedContent);
    362283        assertTrue("unexpected conted created in the package.mo", same);
    363        
    364         /*
    365          * test to create a nested package inside pkg3
    366          */
    367        
    368         openWizardAndFetchWidgets();
    369        
     284
     285        // test to create a nested package inside pkg3
     286        openWizardAndFetchWidgets();
     287
    370288        String subName = "sub_pkg3";
    371        
    372         /*
    373          * fill in the wizard fields
    374          */
     289
     290        // fill in the wizard fields
    375291        ttester.actionEnterText(packageName, subName);
    376292        ttester.actionEnterText(parentPackage, name);
    377293        btester.actionClick(isEncapsulated);
    378294
    379         /*
    380          * wait tops 5 seconds for the name change to propogate
    381          * to enable the finish button
    382          */
     295        // wait tops 5 seconds for the name change to propagate
     296        // to enable the finish button
    383297        long waitUntil = System.currentTimeMillis() + 5000;
    384         while (!finish.getEnabled() && waitUntil > System.currentTimeMillis())
    385         {
     298        while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) {
    386299            Utility.sleep(this, 95);
    387300        }
    388301        btester.actionClick(finish);
    389302
    390         /* check if the package folder was created */
     303        // check if the package folder was created
    391304        folder = folder.getFolder(subName);
    392305        assertTrue("no package folder was created", folder.exists());
    393306
    394         /*
    395          * check that the generated package.mo exists and is sane
    396          */
     307        // check that the generated package.mo exists and is sane
    397308        packageMo = folder.getFile("package.mo");
    398309        assertTrue("package.mo was not created", packageMo.exists());
    399        
    400         same =
    401             Utility.compareContent(packageMo,
    402                 "within " + name + ";\n" +
    403                 "\n" +
    404                 "encapsulated package " + subName + "\n" +
    405                 "\n"+
    406                 "end " + subName + ";");
    407         assertTrue("unexpected conted created in the package.mo", same);
    408     }
    409    
     310
     311        String expectedContentSub = String.format("within %s;\n\nencapsulated package %s\n\nend %s;",
     312                name, subName, subName);
     313        boolean sameSub = Utility.compareContent(packageMo, expectedContentSub);
     314        assertTrue("unexpected conted created in the package.mo", sameSub);
     315    }
     316
    410317    /**
    411318     * create a encapsulated package with description
    412319     */
    413     public void testEncapsulatedCreatePackgeWithDesc()
    414     {
    415         openWizardAndFetchWidgets();
    416        
     320    @Test
     321    public void testEncapsulatedCreatePackgeWithDesc() {
     322        openWizardAndFetchWidgets();
     323
    417324        String name = "pkg4";
    418325        String description = "lebensmittelverpackung mit butter";
    419        
    420         /*
    421          * fill in the wizard fields
    422          */
     326
     327        // fill in the wizard fields
    423328        ttester.actionEnterText(packageName, name);
    424329        btester.actionClick(isEncapsulated);
    425330        ttester.actionEnterText(packageDesc, description);
    426    
    427 
    428         /* wait for the name change to propogate to enable the finish button */
    429         while (!finish.getEnabled()) { Utility.sleep(this, 100); }
    430         btester.actionClick(finish);
    431 
    432         /* check if the package folder was created */
     331
     332        // wait for the name change to propagate to enable the finish button
     333        while (!finish.getEnabled()) {
     334            Utility.sleep(this, 100);
     335        }
     336        btester.actionClick(finish);
     337
     338        // check if the package folder was created
    433339        IFolder folder = project.getFolder(name);
    434340        assertTrue("no package folder was created", folder.exists());
    435341
    436         /*
    437          * check that the generated package.mo exists and is sane
    438          */
     342        // check that the generated package.mo exists and is sane
    439343        IFile packageMo = folder.getFile("package.mo");
    440344        assertTrue("package.mo was not created", packageMo.exists());
    441        
    442         boolean same =
    443             Utility.compareContent(packageMo,
    444                 "encapsulated package " + name + " \"" + description + "\"" + "\n"+
    445                 "\n"+
    446                 "end " + name + ";");
     345
     346        String expectedContent = String.format("encapsulated package %s \"%s\"\n\nend %s;", name, description, name);
     347        boolean same = Utility.compareContent(packageMo, expectedContent);
    447348        assertTrue("unexpected conted created in the package.mo", same);
    448        
    449         /*
    450          * test to create a nested package inside pkg4
    451          */
    452        
    453         openWizardAndFetchWidgets();
    454        
     349
     350        // test to create a nested package inside pkg4
     351        openWizardAndFetchWidgets();
     352
    455353        String subName = "sub_pkg4";
    456354        description = "deutsche, jaaa";
    457355
    458         /*
    459          * fill in the wizard fields
    460          */
     356        // fill in the wizard fields
    461357        ttester.actionEnterText(packageName, subName);
    462358        ttester.actionEnterText(parentPackage, name);
    463359        ttester.actionEnterText(packageDesc, description);
    464360        btester.actionClick(isEncapsulated);
    465        
    466 
    467         /*
    468          * wait tops 5 seconds for the name change to propogate
    469          * to enable the finish button
    470          */
     361
     362        // wait tops 5 seconds for the name change to propagate
     363        // to enable the finish button
    471364        long waitUntil = System.currentTimeMillis() + 5000;
    472         while (!finish.getEnabled() && waitUntil > System.currentTimeMillis())
    473         {
     365        while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) {
    474366            Utility.sleep(this, 95);
    475367        }
    476368        btester.actionClick(finish);
    477369
    478         /* check if the package folder was created */
     370        // check if the package folder was created
    479371        folder = folder.getFolder(subName);
    480372        assertTrue("no package folder was created", folder.exists());
    481373
    482         /*
    483          * check that the generated package.mo exists and is sane
    484          */
     374        // check that the generated package.mo exists and is sane
    485375        packageMo = folder.getFile("package.mo");
    486376        assertTrue("package.mo was not created", packageMo.exists());
    487        
    488         same =
    489             Utility.compareContent(packageMo,
    490                 "within " + name + ";\n" +
    491                 "\n" +
    492                 "encapsulated package " + subName + " \"" + description + "\"" + "\n" +
    493                 "\n"+
    494                 "end " + subName + ";");
    495         assertTrue("unexpected conted created in the package.mo", same);
    496        
     377
     378        String expectedContentSub = String.format("within %s;\n\nencapsulated package %s \"%s\"\n\nend %s;",
     379                name, subName, description, subName);
     380        boolean sameSub = Utility.compareContent(packageMo, expectedContentSub);
     381        assertTrue("unexpected conted created in the package.mo", sameSub);
    497382    }
    498383}
Note: See TracChangeset for help on using the changeset viewer.