Skip to content

Commit

Permalink
Refactored another compound object.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 20, 2016
1 parent 48579e8 commit 63318f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Expand Up @@ -1815,20 +1815,36 @@ class Compound implements Transformer {
/** /**
* The transformers to apply in their application order. * The transformers to apply in their application order.
*/ */
private final Transformer[] transformer; private final List<Transformer> transformers;


/** /**
* Creates a new compound transformer. * Creates a new compound transformer.
* *
* @param transformer The transformers to apply in their application order. * @param transformer The transformers to apply in their application order.
*/ */
public Compound(Transformer... transformer) { public Compound(Transformer... transformer) {
this.transformer = transformer; this(Arrays.asList(transformer));
}

/**
* Creates a new compound transformer.
*
* @param transformers The transformers to apply in their application order.
*/
public Compound(List<? extends Transformer> transformers) {
this.transformers = new ArrayList<Transformer>();
for (Transformer transformer : transformers) {
if (transformer instanceof Compound) {
this.transformers.addAll(((Compound) transformer).transformers);
} else {
this.transformers.add(transformer);
}
}
} }


@Override @Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) { public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) {
for (Transformer transformer : this.transformer) { for (Transformer transformer : transformers) {
builder = transformer.transform(builder, typeDescription, classLoader); builder = transformer.transform(builder, typeDescription, classLoader);
} }
return builder; return builder;
Expand All @@ -1837,18 +1853,18 @@ public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDesc
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass()) return this == other || !(other == null || getClass() != other.getClass())
&& Arrays.equals(transformer, ((Compound) other).transformer); && transformers.equals(((Compound) other).transformers);
} }


@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(transformer); return transformers.hashCode();
} }


@Override @Override
public String toString() { public String toString() {
return "AgentBuilder.Transformer.Compound{" + return "AgentBuilder.Transformer.Compound{" +
"transformer=" + Arrays.toString(transformer) + "transformers=" + transformers +
'}'; '}';
} }
} }
Expand Down
Expand Up @@ -9,6 +9,9 @@
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.mockito.Mock; import org.mockito.Mock;


import java.util.Collections;
import java.util.List;

import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -51,6 +54,11 @@ public void testCompound() throws Exception {
@Test @Test
public void testObjectProperties() throws Exception { public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(AgentBuilder.Transformer.NoOp.class).apply(); ObjectPropertyAssertion.of(AgentBuilder.Transformer.NoOp.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Transformer.Compound.class).apply(); ObjectPropertyAssertion.of(AgentBuilder.Transformer.Compound.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {
@Override
public List<?> create() {
return Collections.singletonList(mock(AgentBuilder.Transformer.class));
}
}).apply();
} }
} }

0 comments on commit 63318f8

Please sign in to comment.