|
5 | 5 | */ |
6 | 6 | package org.hyperledger.fabric.contract.routing; |
7 | 7 |
|
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
8 | 9 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
9 | | -import static org.hamcrest.MatcherAssert.assertThat; |
10 | | -import static org.hamcrest.Matchers.equalTo; |
11 | | -import static org.hamcrest.Matchers.startsWith; |
12 | 10 |
|
13 | 11 | import contract.SampleContract; |
14 | 12 | import java.lang.reflect.Method; |
15 | | -import java.security.Permission; |
16 | 13 | import org.hyperledger.fabric.contract.Context; |
17 | 14 | import org.hyperledger.fabric.contract.ContractInterface; |
18 | 15 | import org.hyperledger.fabric.contract.ContractRuntimeException; |
19 | | -import org.hyperledger.fabric.contract.annotation.Contract; |
20 | | -import org.hyperledger.fabric.contract.annotation.Info; |
21 | 16 | import org.hyperledger.fabric.contract.routing.impl.ContractDefinitionImpl; |
22 | 17 | import org.junit.jupiter.api.Test; |
23 | 18 |
|
24 | 19 | final class ContractDefinitionTest { |
25 | 20 | @Test |
26 | | - void constructor() throws NoSuchMethodException, SecurityException { |
| 21 | + void constructor() throws SecurityException { |
27 | 22 |
|
28 | 23 | final ContractDefinition cf = new ContractDefinitionImpl(SampleContract.class); |
29 | | - assertThat(cf.toString(), startsWith("samplecontract:")); |
30 | | - } |
31 | | - |
32 | | - @Contract(name = "", info = @Info()) |
33 | | - public class FailureTestObject {} |
34 | | - |
35 | | - private boolean fail; |
36 | | - private static final int STEP = 1; |
37 | | - |
38 | | - @Test |
39 | | - void unknownRoute() { |
40 | | - |
41 | | - final SecurityManager tmp = new SecurityManager() { |
42 | | - private int count = 0; |
43 | | - |
44 | | - @Override |
45 | | - public void checkPackageAccess(final String pkg) { |
46 | | - |
47 | | - if (pkg.startsWith("org.hyperledger.fabric.contract")) { |
48 | | - if (count >= STEP) { |
49 | | - throw new SecurityException("Sorry I can't do that"); |
50 | | - } |
51 | | - count++; |
52 | | - } |
53 | | - super.checkPackageAccess(pkg); |
54 | | - } |
55 | | - |
56 | | - @Override |
57 | | - public void checkPermission(final Permission perm) {} |
58 | | - }; |
59 | | - |
60 | | - try { |
61 | | - final ContractDefinition cf = new ContractDefinitionImpl(SampleContract.class); |
62 | | - System.setSecurityManager(tmp); |
63 | | - this.fail = true; |
64 | | - |
65 | | - cf.getUnknownRoute(); |
66 | | - } catch (final Exception e) { |
67 | | - assertThat(e.getMessage(), equalTo("Failure to find unknownTransaction method")); |
68 | | - } finally { |
69 | | - System.setSecurityManager(null); |
70 | | - } |
| 24 | + assertThat(cf.toString()).startsWith("samplecontract:"); |
71 | 25 | } |
72 | 26 |
|
73 | 27 | @Test |
|
0 commit comments