Skip to content

Commit cfec06f

Browse files
author
mpocwier
committed
RecursionCaseMatchingTest moved to tensorics-core
1 parent 39cc39c commit cfec06f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/test/org/tensorics/core/util/chains/RecursionCaseMatchingTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public String repr(ObjectB b) {
8787

8888
public static class IntRepresenter extends AbstractRecursiveRepresenter<String> {
8989

90+
@SuppressWarnings("unused")
9091
public Integer repr(ObjectA a) {
9192
return null;
9293
}
@@ -95,6 +96,7 @@ public Integer repr(ObjectA a) {
9596

9697
public static class TwoParameterRepresenter extends AbstractRecursiveRepresenter<String> {
9798

99+
@SuppressWarnings("unused")
98100
public String repr(ObjectA a, Object ab) {
99101
return null;
100102
}
@@ -103,6 +105,7 @@ public String repr(ObjectA a, Object ab) {
103105

104106
public static class WrongMethodNameRepresenter extends AbstractRecursiveRepresenter<String> {
105107

108+
@SuppressWarnings("unused")
106109
public String illegalMethodName(ObjectA a) {
107110
return null;
108111
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// @formatter:off
2+
/**
3+
*
4+
* This file is part of streaming pool (http://www.streamingpool.org).
5+
*
6+
* Copyright (c) 2017-present, CERN. All rights reserved.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
*/
21+
// @formatter:on
22+
23+
package org.tensorics.core.util.names;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
import java.util.function.Function;
28+
29+
import org.junit.Test;
30+
import org.tensorics.core.util.chains.Chains;
31+
32+
public class NamesTest {
33+
34+
@Test
35+
public void nonOverriddenStringReturnsNull() {
36+
Function<Object, String> chain = Chains.chainFor(String.class).or(Names::fromOverriddenToString).orElseNull();
37+
String name = chain.apply(new EmptyTestClass());
38+
assertThat(name).isNull();
39+
}
40+
41+
@Test
42+
public void chainOverriddenToStringWithSimpleClassNameReturnsSimpleClassName() {
43+
Function<Object, String> chain = Chains.chainFor(String.class).or(Names::fromOverriddenToString)
44+
.or(Names::fromSimpleClassName).orElseNull();
45+
String name = chain.apply(new EmptyTestClass());
46+
assertThat(name).isEqualTo("EmptyTestClass");
47+
}
48+
49+
@Test
50+
public void anyToStringWillNotBeCalledWhenSimpleClassNameBefore() {
51+
Function<Object, String> chain = Chains.chainFor(String.class).or(Names::fromOverriddenToString)
52+
.or(Names::fromSimpleClassName).or(Names::fromToString).orElseNull();
53+
String name = chain.apply(new EmptyTestClass());
54+
assertThat(name).isEqualTo("EmptyTestClass");
55+
}
56+
57+
private static final class EmptyTestClass {
58+
/* empty on purpose */
59+
}
60+
}

0 commit comments

Comments
 (0)