Stop using deprecated AttributeSetter outside of the deprecated package (#5038)

This commit is contained in:
Nikita Salnikov-Tarnovski 2022-01-07 12:57:39 +02:00 committed by GitHub
parent 0c5812951f
commit 1745e7bb55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 72 deletions

View File

@ -5,17 +5,17 @@
package io.opentelemetry.instrumentation.api.annotation.support; package io.opentelemetry.instrumentation.api.annotation.support;
import io.opentelemetry.instrumentation.api.tracer.AttributeSetter; import io.opentelemetry.api.common.AttributesBuilder;
/** Represents the binding of a method parameter to an attribute of a traced method. */ /** Represents the binding of a method parameter to an attribute of a traced method. */
@FunctionalInterface @FunctionalInterface
public interface AttributeBinding { interface AttributeBinding {
/** /**
* Applies the value of the method argument as an attribute on the span for the traced method. * Applies the value of the method argument as an attribute on the span for the traced method.
* *
* @param setter the {@link AttributeSetter} onto which to add the attribute * @param target the {@link AttributesBuilder} onto which to add the attribute
* @param arg the value of the method argument * @param arg the value of the method argument
*/ */
void apply(AttributeSetter setter, Object arg); void apply(AttributesBuilder target, Object arg);
} }

View File

@ -25,27 +25,27 @@ class AttributeBindingFactory {
// Simple scalar parameter types // Simple scalar parameter types
if (type == String.class) { if (type == String.class) {
AttributeKey<String> key = AttributeKey.stringKey(name); AttributeKey<String> key = AttributeKey.stringKey(name);
return (setter, arg) -> setter.setAttribute(key, (String) arg); return (setter, arg) -> setter.put(key, (String) arg);
} }
if (type == long.class || type == Long.class) { if (type == long.class || type == Long.class) {
AttributeKey<Long> key = AttributeKey.longKey(name); AttributeKey<Long> key = AttributeKey.longKey(name);
return (setter, arg) -> setter.setAttribute(key, (Long) arg); return (setter, arg) -> setter.put(key, (Long) arg);
} }
if (type == double.class || type == Double.class) { if (type == double.class || type == Double.class) {
AttributeKey<Double> key = AttributeKey.doubleKey(name); AttributeKey<Double> key = AttributeKey.doubleKey(name);
return (setter, arg) -> setter.setAttribute(key, (Double) arg); return (setter, arg) -> setter.put(key, (Double) arg);
} }
if (type == boolean.class || type == Boolean.class) { if (type == boolean.class || type == Boolean.class) {
AttributeKey<Boolean> key = AttributeKey.booleanKey(name); AttributeKey<Boolean> key = AttributeKey.booleanKey(name);
return (setter, arg) -> setter.setAttribute(key, (Boolean) arg); return (setter, arg) -> setter.put(key, (Boolean) arg);
} }
if (type == int.class || type == Integer.class) { if (type == int.class || type == Integer.class) {
AttributeKey<Long> key = AttributeKey.longKey(name); AttributeKey<Long> key = AttributeKey.longKey(name);
return (setter, arg) -> setter.setAttribute(key, ((Integer) arg).longValue()); return (setter, arg) -> setter.put(key, ((Integer) arg).longValue());
} }
if (type == float.class || type == Float.class) { if (type == float.class || type == Float.class) {
AttributeKey<Double> key = AttributeKey.doubleKey(name); AttributeKey<Double> key = AttributeKey.doubleKey(name);
return (setter, arg) -> setter.setAttribute(key, ((Float) arg).doubleValue()); return (setter, arg) -> setter.put(key, ((Float) arg).doubleValue());
} }
if (isArrayType(type)) { if (isArrayType(type)) {
@ -74,19 +74,19 @@ class AttributeBindingFactory {
// Simple array attribute types without conversion // Simple array attribute types without conversion
if (type == String[].class) { if (type == String[].class) {
AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name); AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, Arrays.asList((String[]) arg)); return (setter, arg) -> setter.put(key, Arrays.asList((String[]) arg));
} }
if (type == Long[].class) { if (type == Long[].class) {
AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name); AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, Arrays.asList((Long[]) arg)); return (setter, arg) -> setter.put(key, Arrays.asList((Long[]) arg));
} }
if (type == Double[].class) { if (type == Double[].class) {
AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name); AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, Arrays.asList((Double[]) arg)); return (setter, arg) -> setter.put(key, Arrays.asList((Double[]) arg));
} }
if (type == Boolean[].class) { if (type == Boolean[].class) {
AttributeKey<List<Boolean>> key = AttributeKey.booleanArrayKey(name); AttributeKey<List<Boolean>> key = AttributeKey.booleanArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, Arrays.asList((Boolean[]) arg)); return (setter, arg) -> setter.put(key, Arrays.asList((Boolean[]) arg));
} }
if (type == long[].class) { if (type == long[].class) {
@ -118,19 +118,19 @@ class AttributeBindingFactory {
private static AttributeBinding listBinding(String name, Type componentType) { private static AttributeBinding listBinding(String name, Type componentType) {
if (componentType == String.class) { if (componentType == String.class) {
AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name); AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, (List<String>) arg); return (setter, arg) -> setter.put(key, (List<String>) arg);
} }
if (componentType == Long.class) { if (componentType == Long.class) {
AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name); AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, (List<Long>) arg); return (setter, arg) -> setter.put(key, (List<Long>) arg);
} }
if (componentType == Double.class) { if (componentType == Double.class) {
AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name); AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, (List<Double>) arg); return (setter, arg) -> setter.put(key, (List<Double>) arg);
} }
if (componentType == Boolean.class) { if (componentType == Boolean.class) {
AttributeKey<List<Boolean>> key = AttributeKey.booleanArrayKey(name); AttributeKey<List<Boolean>> key = AttributeKey.booleanArrayKey(name);
return (setter, arg) -> setter.setAttribute(key, (List<Boolean>) arg); return (setter, arg) -> setter.put(key, (List<Boolean>) arg);
} }
if (componentType == Integer.class) { if (componentType == Integer.class) {
AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name); AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name);
@ -160,7 +160,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -181,7 +181,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -201,7 +201,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -221,7 +221,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -242,7 +242,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -262,7 +262,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -282,7 +282,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -303,7 +303,7 @@ class AttributeBindingFactory {
return array.length; return array.length;
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -325,7 +325,7 @@ class AttributeBindingFactory {
return list.size(); return list.size();
} }
}; };
setter.setAttribute(key, wrapper); setter.put(key, wrapper);
}; };
} }
@ -336,6 +336,6 @@ class AttributeBindingFactory {
private static AttributeBinding defaultBinding(String name) { private static AttributeBinding defaultBinding(String name) {
AttributeKey<String> key = AttributeKey.stringKey(name); AttributeKey<String> key = AttributeKey.stringKey(name);
return (setter, arg) -> setter.setAttribute(key, arg.toString()); return (setter, arg) -> setter.put(key, arg.toString());
} }
} }

View File

@ -5,10 +5,10 @@
package io.opentelemetry.instrumentation.api.annotation.support; package io.opentelemetry.instrumentation.api.annotation.support;
import io.opentelemetry.instrumentation.api.tracer.AttributeSetter; import io.opentelemetry.api.common.AttributesBuilder;
/** Represents the bindings of method parameters to attributes of a traced method. */ /** Represents the bindings of method parameters to attributes of a traced method. */
public interface AttributeBindings { interface AttributeBindings {
/** /**
* Indicates that the traced method has no parameters bound to attributes. * Indicates that the traced method has no parameters bound to attributes.
@ -20,8 +20,8 @@ public interface AttributeBindings {
/** /**
* Applies the values of the method arguments as attributes on the span for the traced method. * Applies the values of the method arguments as attributes on the span for the traced method.
* *
* @param setter the {@link AttributeSetter} for setting the attribute on the span * @param target the {@link AttributesBuilder} on which to set the attribute
* @param args the method arguments * @param args the method arguments
*/ */
void apply(AttributeSetter setter, Object[] args); void apply(AttributesBuilder target, Object[] args);
} }

View File

@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.api.annotation.support;
import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.cache.Cache; import io.opentelemetry.instrumentation.api.cache.Cache;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.tracer.AttributeSetter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Parameter; import java.lang.reflect.Parameter;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -51,7 +50,7 @@ public final class MethodSpanAttributesExtractor<REQUEST, RESPONSE>
AttributeBindings bindings = cache.computeIfAbsent(method, this::bind); AttributeBindings bindings = cache.computeIfAbsent(method, this::bind);
if (!bindings.isEmpty()) { if (!bindings.isEmpty()) {
Object[] args = methodArgumentsExtractor.extract(request); Object[] args = methodArgumentsExtractor.extract(request);
bindings.apply(attributes::put, args); bindings.apply(attributes, args);
} }
} }
@ -108,7 +107,7 @@ public final class MethodSpanAttributesExtractor<REQUEST, RESPONSE>
} }
@Override @Override
public void apply(AttributeSetter setter, Object[] args) {} public void apply(AttributesBuilder target, Object[] args) {}
} }
private static final class CombinedAttributeBindings implements AttributeBindings { private static final class CombinedAttributeBindings implements AttributeBindings {
@ -129,12 +128,12 @@ public final class MethodSpanAttributesExtractor<REQUEST, RESPONSE>
} }
@Override @Override
public void apply(AttributeSetter setter, Object[] args) { public void apply(AttributesBuilder target, Object[] args) {
parent.apply(setter, args); parent.apply(target, args);
if (args != null && args.length > index) { if (args != null && args.length > index) {
Object arg = args[index]; Object arg = args[index];
if (arg != null) { if (arg != null) {
binding.apply(setter, arg); binding.apply(target, arg);
} }
} }
} }

View File

@ -6,19 +6,19 @@
package io.opentelemetry.instrumentation.api.annotation.support package io.opentelemetry.instrumentation.api.annotation.support
import io.opentelemetry.api.common.AttributeType import io.opentelemetry.api.common.AttributeType
import io.opentelemetry.instrumentation.api.tracer.AttributeSetter import io.opentelemetry.api.common.AttributesBuilder
import spock.lang.Specification import spock.lang.Specification
class AttributeBindingFactoryTest extends Specification { class AttributeBindingFactoryTest extends Specification {
AttributeSetter setter = Mock() AttributesBuilder setter = Mock()
def "creates attribute binding for String"() { def "creates attribute binding for String"() {
when: when:
AttributeBindingFactory.createBinding("key", String).apply(setter, "value") AttributeBindingFactory.createBinding("key", String).apply(setter, "value")
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING && it.getKey() == "key" }, "value") 1 * setter.put({ it.getType() == AttributeType.STRING && it.getKey() == "key" }, "value")
} }
def "creates attribute binding for int"() { def "creates attribute binding for int"() {
@ -26,7 +26,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", int).apply(setter, 1234) AttributeBindingFactory.createBinding("key", int).apply(setter, 1234)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L) 1 * setter.put({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L)
} }
def "creates attribute binding for Integer"() { def "creates attribute binding for Integer"() {
@ -34,7 +34,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Integer).apply(setter, 1234) AttributeBindingFactory.createBinding("key", Integer).apply(setter, 1234)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L) 1 * setter.put({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L)
} }
def "creates attribute binding for long"() { def "creates attribute binding for long"() {
@ -42,7 +42,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", long).apply(setter, 1234L) AttributeBindingFactory.createBinding("key", long).apply(setter, 1234L)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L) 1 * setter.put({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L)
} }
def "creates attribute binding for Long"() { def "creates attribute binding for Long"() {
@ -50,7 +50,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Long).apply(setter, 1234L) AttributeBindingFactory.createBinding("key", Long).apply(setter, 1234L)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L) 1 * setter.put({ it.getType() == AttributeType.LONG && it.getKey() == "key" }, 1234L)
} }
def "creates attribute binding for float"() { def "creates attribute binding for float"() {
@ -58,7 +58,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", float).apply(setter, 1234.0F) AttributeBindingFactory.createBinding("key", float).apply(setter, 1234.0F)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, 1234.0) 1 * setter.put({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, 1234.0)
} }
def "creates attribute binding for Float"() { def "creates attribute binding for Float"() {
@ -66,7 +66,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Float).apply(setter, 1234.0F) AttributeBindingFactory.createBinding("key", Float).apply(setter, 1234.0F)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, 1234.0) 1 * setter.put({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, 1234.0)
} }
def "creates attribute binding for double"() { def "creates attribute binding for double"() {
@ -74,7 +74,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", double).apply(setter, Double.valueOf(1234.0)) AttributeBindingFactory.createBinding("key", double).apply(setter, Double.valueOf(1234.0))
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, Double.valueOf(1234.0)) 1 * setter.put({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, Double.valueOf(1234.0))
} }
def "creates attribute binding for Double"() { def "creates attribute binding for Double"() {
@ -82,7 +82,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Double).apply(setter, Double.valueOf(1234.0)) AttributeBindingFactory.createBinding("key", Double).apply(setter, Double.valueOf(1234.0))
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, Double.valueOf(1234.0)) 1 * setter.put({ it.getType() == AttributeType.DOUBLE && it.getKey() == "key" }, Double.valueOf(1234.0))
} }
def "creates attribute binding for boolean"() { def "creates attribute binding for boolean"() {
@ -90,7 +90,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", boolean).apply(setter, true) AttributeBindingFactory.createBinding("key", boolean).apply(setter, true)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.BOOLEAN && it.getKey() == "key" }, true) 1 * setter.put({ it.getType() == AttributeType.BOOLEAN && it.getKey() == "key" }, true)
} }
def "creates attribute binding for Boolean"() { def "creates attribute binding for Boolean"() {
@ -98,7 +98,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Boolean).apply(setter, true) AttributeBindingFactory.createBinding("key", Boolean).apply(setter, true)
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.BOOLEAN && it.getKey() == "key" }, true) 1 * setter.put({ it.getType() == AttributeType.BOOLEAN && it.getKey() == "key" }, true)
} }
def "creates attribute binding for String[]"() { def "creates attribute binding for String[]"() {
@ -106,7 +106,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", String[]).apply(setter, ["x", "y", "z", null] as String[]) AttributeBindingFactory.createBinding("key", String[]).apply(setter, ["x", "y", "z", null] as String[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["x", "y", "z", null]) 1 * setter.put({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["x", "y", "z", null])
} }
def "creates attribute binding for int[]"() { def "creates attribute binding for int[]"() {
@ -114,7 +114,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", int[]).apply(setter, [1, 2, 3] as int[]) AttributeBindingFactory.createBinding("key", int[]).apply(setter, [1, 2, 3] as int[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L])
} }
def "creates attribute binding for Integer[]"() { def "creates attribute binding for Integer[]"() {
@ -122,7 +122,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Integer[]).apply(setter, [1, 2, 3, null] as Integer[]) AttributeBindingFactory.createBinding("key", Integer[]).apply(setter, [1, 2, 3, null] as Integer[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L, null]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L, null])
} }
def "creates attribute binding for long[]"() { def "creates attribute binding for long[]"() {
@ -130,7 +130,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", long[]).apply(setter, [1L, 2L, 3L] as long[]) AttributeBindingFactory.createBinding("key", long[]).apply(setter, [1L, 2L, 3L] as long[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L])
} }
def "creates attribute binding for Long[]"() { def "creates attribute binding for Long[]"() {
@ -138,7 +138,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Long[]).apply(setter, [1L, 2L, 3L, null] as Long[]) AttributeBindingFactory.createBinding("key", Long[]).apply(setter, [1L, 2L, 3L, null] as Long[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L, null]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L, null])
} }
def "creates attribute binding for float[]"() { def "creates attribute binding for float[]"() {
@ -146,7 +146,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", float[]).apply(setter, [1.0F, 2.0F, 3.0F] as float[]) AttributeBindingFactory.createBinding("key", float[]).apply(setter, [1.0F, 2.0F, 3.0F] as float[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0] as List<Double>) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0] as List<Double>)
} }
def "creates attribute binding for Float[]"() { def "creates attribute binding for Float[]"() {
@ -154,7 +154,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Float[]).apply(setter, [1.0F, 2.0F, 3.0F, null] as Float[]) AttributeBindingFactory.createBinding("key", Float[]).apply(setter, [1.0F, 2.0F, 3.0F, null] as Float[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0, null] as List<Double>) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0, null] as List<Double>)
} }
def "creates attribute binding for double[]"() { def "creates attribute binding for double[]"() {
@ -162,7 +162,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", double[]).apply(setter, [1.0, 2.0, 3.0] as double[]) AttributeBindingFactory.createBinding("key", double[]).apply(setter, [1.0, 2.0, 3.0] as double[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0] as List<Double>) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0] as List<Double>)
} }
def "creates attribute binding for Double[]"() { def "creates attribute binding for Double[]"() {
@ -170,7 +170,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Double[]).apply(setter, [1.0, 2.0, 3.0, null] as Double[]) AttributeBindingFactory.createBinding("key", Double[]).apply(setter, [1.0, 2.0, 3.0, null] as Double[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0, null] as List<Double>) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0, null] as List<Double>)
} }
def "creates attribute binding for boolean[]"() { def "creates attribute binding for boolean[]"() {
@ -178,7 +178,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", boolean[]).apply(setter, [true, false] as boolean[]) AttributeBindingFactory.createBinding("key", boolean[]).apply(setter, [true, false] as boolean[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false] as List<Boolean>) 1 * setter.put({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false] as List<Boolean>)
} }
def "creates attribute binding for Boolean[]"() { def "creates attribute binding for Boolean[]"() {
@ -186,7 +186,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", Boolean[]).apply(setter, [true, false, null] as Boolean[]) AttributeBindingFactory.createBinding("key", Boolean[]).apply(setter, [true, false, null] as Boolean[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false, null] as List<Boolean>) 1 * setter.put({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false, null] as List<Boolean>)
} }
def "creates default attribute binding"() { def "creates default attribute binding"() {
@ -194,7 +194,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", TestClass).apply(setter, new TestClass("foo")) AttributeBindingFactory.createBinding("key", TestClass).apply(setter, new TestClass("foo"))
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING && it.getKey() == "key" }, "TestClass{value = foo}") 1 * setter.put({ it.getType() == AttributeType.STRING && it.getKey() == "key" }, "TestClass{value = foo}")
} }
def "creates default attribute binding for array"() { def "creates default attribute binding for array"() {
@ -202,7 +202,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", TestClass[]).apply(setter, [new TestClass("foo"), new TestClass("bar"), null] as TestClass[]) AttributeBindingFactory.createBinding("key", TestClass[]).apply(setter, [new TestClass("foo"), new TestClass("bar"), null] as TestClass[])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["TestClass{value = foo}", "TestClass{value = bar}", null]) 1 * setter.put({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["TestClass{value = foo}", "TestClass{value = bar}", null])
} }
def "creates attribute binding for List<String>"() { def "creates attribute binding for List<String>"() {
@ -211,7 +211,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, ["x", "y", "z"]) AttributeBindingFactory.createBinding("key", type).apply(setter, ["x", "y", "z"])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["x", "y", "z"]) 1 * setter.put({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["x", "y", "z"])
} }
def "creates attribute binding for List<Integer>"() { def "creates attribute binding for List<Integer>"() {
@ -220,7 +220,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [1, 2, 3]) AttributeBindingFactory.createBinding("key", type).apply(setter, [1, 2, 3])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L])
} }
def "creates attribute binding for List<Long>"() { def "creates attribute binding for List<Long>"() {
@ -229,7 +229,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [1L, 2L, 3L]) AttributeBindingFactory.createBinding("key", type).apply(setter, [1L, 2L, 3L])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L])
} }
def "creates attribute binding for List<Float>"() { def "creates attribute binding for List<Float>"() {
@ -238,7 +238,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [1.0F, 2.0F, 3.0F]) AttributeBindingFactory.createBinding("key", type).apply(setter, [1.0F, 2.0F, 3.0F])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0]) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0])
} }
def "creates attribute binding for List<Double>"() { def "creates attribute binding for List<Double>"() {
@ -247,7 +247,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [1.0, 2.0, 3.0]) AttributeBindingFactory.createBinding("key", type).apply(setter, [1.0, 2.0, 3.0])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0]) 1 * setter.put({ it.getType() == AttributeType.DOUBLE_ARRAY && it.getKey() == "key" }, [1.0, 2.0, 3.0])
} }
def "creates attribute binding for List<Boolean>"() { def "creates attribute binding for List<Boolean>"() {
@ -256,7 +256,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [true, false, null]) AttributeBindingFactory.createBinding("key", type).apply(setter, [true, false, null])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false, null]) 1 * setter.put({ it.getType() == AttributeType.BOOLEAN_ARRAY && it.getKey() == "key" }, [true, false, null])
} }
def "creates attribute binding for List<?>"() { def "creates attribute binding for List<?>"() {
@ -265,7 +265,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [new TestClass("foo"), new TestClass("bar")]) AttributeBindingFactory.createBinding("key", type).apply(setter, [new TestClass("foo"), new TestClass("bar")])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["TestClass{value = foo}", "TestClass{value = bar}"]) 1 * setter.put({ it.getType() == AttributeType.STRING_ARRAY && it.getKey() == "key" }, ["TestClass{value = foo}", "TestClass{value = bar}"])
} }
def "creates attribute binding for ArrayList<Long>"() { def "creates attribute binding for ArrayList<Long>"() {
@ -274,7 +274,7 @@ class AttributeBindingFactoryTest extends Specification {
AttributeBindingFactory.createBinding("key", type).apply(setter, [1L, 2L, 3L]) AttributeBindingFactory.createBinding("key", type).apply(setter, [1L, 2L, 3L])
then: then:
1 * setter.setAttribute({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L]) 1 * setter.put({ it.getType() == AttributeType.LONG_ARRAY && it.getKey() == "key" }, [1L, 2L, 3L])
} }
class TestClass { class TestClass {