Skip to content

Commit e71db76

Browse files
core: jdk16 module (#1370)
1 parent 9e5bda6 commit e71db76

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed

webtau-core-jdk16/pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023 webtau maintainers
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.testingisdocumenting.webtau</groupId>
25+
<artifactId>webtau-parent</artifactId>
26+
<version>1.51-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>webtau-core-jdk16</artifactId>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.testingisdocumenting.webtau</groupId>
34+
<artifactId>webtau-core</artifactId>
35+
<version>${project.version}</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>junit</groupId>
40+
<artifactId>junit</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>3.10.1</version>
51+
<configuration>
52+
<source>1.16</source>
53+
<target>1.16</target>
54+
<fork>true</fork>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2023 webtau maintainers
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.testingisdocumenting.webtau.data.converters;
18+
19+
import java.lang.reflect.InvocationTargetException;
20+
import java.lang.reflect.RecordComponent;
21+
import java.util.LinkedHashMap;
22+
import java.util.Map;
23+
24+
public class RecordToMapConverter implements ToMapConverter {
25+
@Override
26+
public Map<String, ?> convert(Object v) {
27+
if (!v.getClass().isRecord()) {
28+
return null;
29+
}
30+
31+
RecordComponent[] recordComponents = v.getClass().getRecordComponents();
32+
Map<String, Object> result = new LinkedHashMap<>();
33+
for (RecordComponent component : recordComponents) {
34+
try {
35+
result.put(component.getName(), component.getAccessor().invoke(v));
36+
} catch (IllegalAccessException | InvocationTargetException e) {
37+
throw new RuntimeException(e);
38+
}
39+
}
40+
41+
return result;
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright 2023 webtau maintainers
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
org.testingisdocumenting.webtau.data.converters.RecordToMapConverter
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2023 webtau maintainers
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.testingisdocumenting.webtau.data.converters;
18+
19+
import org.junit.Test;
20+
21+
import static org.testingisdocumenting.webtau.WebTauCore.*;
22+
23+
record Account(String id, String name) {
24+
}
25+
26+
public class RecordToMapConverterTest {
27+
@Test
28+
public void compareRecordAndMap() {
29+
var account = new Account("id1", "name1");
30+
actual(account).should(equal(map("id", "id1", "name", "name2")));
31+
}
32+
}

0 commit comments

Comments
 (0)