jtulach@77
|
1 |
package impl;
|
jtulach@77
|
2 |
|
jtulach@77
|
3 |
import java.util.Collections;
|
jtulach@77
|
4 |
import java.util.List;
|
jtulach@77
|
5 |
import java.util.Map;
|
jtulach@77
|
6 |
|
jtulach@77
|
7 |
public class Impl {
|
jtulach@77
|
8 |
public static void main(String[] args) {
|
jtulach@78
|
9 |
System.err.println("showUsageOfAbstractClassAPI:");
|
jtulach@78
|
10 |
showUsageOfAbstractClassAPI();
|
jtulach@78
|
11 |
System.err.println("showUsageOfRequestResponseAPI:");
|
jtulach@78
|
12 |
showUsageOfRequestResponseAPI();
|
jtulach@78
|
13 |
}
|
jtulach@78
|
14 |
|
jtulach@78
|
15 |
private static void assertEquals(String msg, int expected, int real) {
|
jtulach@78
|
16 |
System.err.println(" " + msg + " expected: " + expected + " was: " + real);
|
jtulach@78
|
17 |
assert expected == real;
|
jtulach@78
|
18 |
}
|
jtulach@78
|
19 |
|
jtulach@78
|
20 |
private static void showUsageOfAbstractClassAPI() {
|
jtulach@78
|
21 |
class ProviderWrittenAgainstVersion1 extends api.classes.Compute {
|
jtulach@77
|
22 |
@Override
|
jtulach@77
|
23 |
public List<String> getData() {
|
jtulach@77
|
24 |
return Collections.singletonList("Hello");
|
jtulach@77
|
25 |
}
|
jtulach@77
|
26 |
}
|
jtulach@78
|
27 |
int index1 = api.classes.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
|
jtulach@78
|
28 |
assertEquals("Hello was found", 0, index1);
|
jtulach@78
|
29 |
int index2 = api.classes.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
|
jtulach@78
|
30 |
assertEquals("Unknown was not found", -1, index2);
|
jtulach@77
|
31 |
|
jtulach@78
|
32 |
class ProviderWrittenAgainstVersion2 extends api.classes.Compute {
|
jtulach@77
|
33 |
@Override
|
jtulach@77
|
34 |
public List<String> getData() {
|
jtulach@77
|
35 |
return Collections.singletonList("Hello");
|
jtulach@77
|
36 |
}
|
jtulach@77
|
37 |
|
jtulach@77
|
38 |
@Override
|
jtulach@77
|
39 |
public Map<String, String> getDataAndDescription() {
|
jtulach@77
|
40 |
return Collections.singletonMap("Hello", "Says hello");
|
jtulach@77
|
41 |
}
|
jtulach@77
|
42 |
}
|
jtulach@77
|
43 |
|
jtulach@78
|
44 |
int index3 = api.classes.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
|
jtulach@78
|
45 |
assertEquals("Found by description", 0, index3);
|
jtulach@78
|
46 |
}
|
jtulach@78
|
47 |
|
jtulach@78
|
48 |
|
jtulach@78
|
49 |
|
jtulach@78
|
50 |
private static void showUsageOfRequestResponseAPI() {
|
jtulach@78
|
51 |
class ProviderWrittenAgainstVersion1 implements api.request.response.Compute {
|
jtulach@78
|
52 |
public void computeData(Request request, Response response) {
|
jtulach@78
|
53 |
response.add("Hello");
|
jtulach@78
|
54 |
}
|
jtulach@78
|
55 |
}
|
jtulach@78
|
56 |
int index1 = api.request.response.Support.searchByDescription("Hello", new ProviderWrittenAgainstVersion1());
|
jtulach@78
|
57 |
assertEquals("Hello found", 0, index1);
|
jtulach@78
|
58 |
int index2 = api.request.response.Support.searchByDescription("Unknown", new ProviderWrittenAgainstVersion1());
|
jtulach@78
|
59 |
assertEquals("Unknown not found", -1, index2);
|
jtulach@78
|
60 |
|
jtulach@78
|
61 |
class ProviderWrittenAgainstVersion2 implements api.request.response.Compute {
|
jtulach@78
|
62 |
public void computeData(Request request, Response response) {
|
jtulach@78
|
63 |
response.add("Hello", "Says hello");
|
jtulach@78
|
64 |
}
|
jtulach@78
|
65 |
}
|
jtulach@78
|
66 |
|
jtulach@78
|
67 |
int index3 = api.request.response.Support.searchByDescription("Says hello", new ProviderWrittenAgainstVersion2());
|
jtulach@78
|
68 |
assertEquals("Description found", 0, index3);
|
jtulach@77
|
69 |
assert index3 == 0;
|
jtulach@77
|
70 |
}
|
jtulach@77
|
71 |
}
|