public Statement apply()

in commons-testing-junit4/src/main/java/org/apache/commons/testing/junit4/net/AvailableServerPortSystemPropertyTestRule.java [42:60]


    public Statement apply(final Statement base, final Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                final String oldValue = System.getProperty(name);
                try {
                    port = AvailableServerPortFinder.getNextAvailable();
                    System.setProperty(name, Integer.toString(port));
                    base.evaluate();
                } finally {
                    // Restore if previously set
                    if (oldValue != null) {
                        System.setProperty(name, oldValue);
                    }
                }
            }
        };
    }