aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/test/KeyGenerationTest.java
blob: 0ec4741246603763e2102495ffb5a5075ec838d7 (plain) (blame)
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
package cz.crcs.ectester.standalone.test;

import cz.crcs.ectester.common.test.Result;
import cz.crcs.ectester.common.test.Test;
import cz.crcs.ectester.common.test.TestCallback;
import cz.crcs.ectester.common.test.TestException;

/**
 * @author Jan Jancar johny@neuromancer.sk
 */
public class KeyGenerationTest extends Test {
    private KeyGenerationTestable kg;
    private TestCallback<KeyGenerationTestable> callback;

    private KeyGenerationTest(KeyGenerationTestable kg, TestCallback<KeyGenerationTestable> callback) {
        this.kg = kg;
        this.callback = callback;
    }

    public static KeyGenerationTest expect(KeyGenerationTestable kg, Result.ExpectedValue expected) {
        return new KeyGenerationTest(kg, new TestCallback<KeyGenerationTestable>() {
            @Override
            public Result apply(KeyGenerationTestable keyGenerationTestable) {
                return new Result(Result.Value.fromExpected(expected, keyGenerationTestable.ok(), keyGenerationTestable.error()));
            }
        });
    }

    public static KeyGenerationTest function(KeyGenerationTestable ka, TestCallback<KeyGenerationTestable> callback) {
        return new KeyGenerationTest(ka, callback);
    }

    @Override
    public String getDescription() {
        return null;
    }

    @Override
    public void run() throws TestException {
        kg.run();
        result = callback.apply(kg);
        hasRun = true;
    }
}