summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/test/KeyGeneratorTest.java
blob: 93273caba4d378a24dc0c640b0a34fb3e64ac656 (plain)
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
package cz.crcs.ectester.standalone.test;

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

/**
 * @author Jan Jancar johny@neuromancer.sk
 */
public class KeyGeneratorTest extends SimpleTest<KeyGeneratorTestable> {
    private KeyGeneratorTest(KeyGeneratorTestable kg, TestCallback<KeyGeneratorTestable> callback) {
        super(kg, callback);
    }

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

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

    @Override
    public String getDescription() {
        return "KeyPairGenerator " + testable.getKpg().getAlgorithm();
    }

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