File: AutotestTest.java

package info (click to toggle)
jython 2.7.2%2Brepack1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,676 kB
  • sloc: python: 640,908; java: 306,458; xml: 1,984; sh: 522; ansic: 126; makefile: 76
file content (78 lines) | stat: -rw-r--r-- 2,635 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.python.util.install.driver;

import java.io.File;

import org.python.util.install.InstallerCommandLine;

import junit.framework.TestCase;

public class AutotestTest extends TestCase {

    private Autotest _autotest;

    protected void setUp() throws Exception {
        InstallerCommandLine commandLine = new InstallerCommandLine();
        commandLine.setArgs(new String[0]);
        _autotest = new SilentAutotest(commandLine);
    }

    public void testCreateDirectories() {
        File rootDir = Autotest.getRootDir();
        File targetDir = _autotest.getTargetDir();
        assertNotNull(rootDir);
        verifyDir(rootDir, false);
        assertNotNull(targetDir);
        verifyDir(targetDir, true);
        assertEquals(rootDir, targetDir.getParentFile());
    }

    public void testCommandLineArgs() {
        String[] args = new String[] { "-x", "-y", "-z" };
        _autotest.setCommandLineArgs(args);
        int len = _autotest.getCommandLineArgs().length;
        assertEquals(args.length, len);
        for (int i = 0; i < args.length; i++) {
            assertEquals(args[i], _autotest.getCommandLineArgs()[i]);
        }
    }

    public void testAddArgument() {
        String[] args = new String[] { "-x", "-y", "-z" };
        _autotest.setCommandLineArgs(args);
        _autotest.addArgument("-u");
        assertEquals(args.length + 1, _autotest.getCommandLineArgs().length);
        for (int i = 0; i < args.length; i++) {
            assertEquals(args[i], _autotest.getCommandLineArgs()[i]);
        }
        assertEquals("-u", _autotest.getCommandLineArgs()[args.length]);
    }

    public void testVerify() throws Exception {
        TestVerifier testVerifier = new TestVerifier();
        _autotest.setVerifier(testVerifier);
        assertNotNull(_autotest.getVerifier());
        assertNotNull(_autotest.getVerifier().getTargetDir());
        assertEquals(_autotest.getTargetDir(), testVerifier.getTargetDir());
        try {
            _autotest.getVerifier().verify();
            fail("should have thrown");
        } catch (DriverException de) {
        }

    }

    private void verifyDir(File dir, boolean ensureEmpty) {
        assertTrue(dir.exists());
        assertTrue(dir.isDirectory());
        if (ensureEmpty) {
            assertTrue(dir.listFiles().length <= 0);
        }
    }

    private static class TestVerifier extends NormalVerifier {
        public void verify() throws DriverException {
            throw new DriverException("test verification failure");
        }
    }

}