Skip to content

Commit

Permalink
#198: Adds prefab values for nio buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jul 4, 2018
1 parent 2424cb5 commit 416fa21
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -65,6 +66,7 @@ private void addJavaClasses() {
addMaps();
addSets();
addQueues();
addNioBuffers();
addAwtClasses();
addJava8ApiClasses();
addJavaFxClasses();
Expand Down Expand Up @@ -281,6 +283,25 @@ public Tuple<DelayQueue> createValues(TypeTag tag, PrefabValues pf, LinkedHashSe
addValues(SynchronousQueue.class, new SynchronousQueue<>(), new SynchronousQueue<>(), new SynchronousQueue<>());
}

private void addNioBuffers() {
addValues(Buffer.class,
ByteBuffer.wrap(new byte[] { 0 }), ByteBuffer.wrap(new byte[] { 1 }), ByteBuffer.wrap(new byte[] { 0 }));
addValues(ByteBuffer.class,
ByteBuffer.wrap(new byte[] { 0 }), ByteBuffer.wrap(new byte[] { 1 }), ByteBuffer.wrap(new byte[] { 0 }));
addValues(CharBuffer.class,
CharBuffer.wrap("a"), CharBuffer.wrap("b"), CharBuffer.wrap("a"));
addValues(DoubleBuffer.class,
DoubleBuffer.wrap(new double[] { 0.0 }), DoubleBuffer.wrap(new double[] { 1.0 }), DoubleBuffer.wrap(new double[] { 0.0 }));
addValues(FloatBuffer.class,
FloatBuffer.wrap(new float[] { 0.0f }), FloatBuffer.wrap(new float[] { 1.0f }), FloatBuffer.wrap(new float[] { 0.0f }));
addValues(IntBuffer.class,
IntBuffer.wrap(new int[] { 0 }), IntBuffer.wrap(new int[] { 1 }), IntBuffer.wrap(new int[] { 0 }));
addValues(LongBuffer.class,
LongBuffer.wrap(new long[] { 0 }), LongBuffer.wrap(new long[] { 1 }), LongBuffer.wrap(new long[] { 0 }));
addValues(ShortBuffer.class,
ShortBuffer.wrap(new short[] { 0 }), ShortBuffer.wrap(new short[] { 1 }), ShortBuffer.wrap(new short[] { 0 }));
}

private void addAwtClasses() {
prefabValues.addLazyFactory("java.awt.Color", new ReflectiveLazyConstantFactory<>("java.awt.Color", "RED", "BLACK"));
prefabValues.addLazyFactory("java.awt.color.ColorSpace", new ReflectiveLazyAwtFactory<>("java.awt.color.ColorSpace"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.net.InetAddress;
import java.nio.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
Expand Down Expand Up @@ -46,6 +47,12 @@ public void succeed_whenClassContainsAMap() {
.verify();
}

@Test
public void succeed_whenClassContainsANioBuffer() {
EqualsVerifier.forClass(NioBufferContainer.class)
.verify();
}

@Test
public void succeed_whenClassContainsACommonJavaApiType() {
EqualsVerifier.forClass(CommonClassesContainer.class)
Expand Down Expand Up @@ -232,6 +239,28 @@ protected void callAbstractMethodsOnInterface() {
}
}

@SuppressWarnings("unused") // because of the use of defaultEquals and defaultHashCode
static final class NioBufferContainer {
private final Buffer buffer;
private final ByteBuffer byteBuffer;
private final CharBuffer charBuffer;
private final DoubleBuffer doubleBuffer;
private final FloatBuffer floatBuffer;
private final IntBuffer intBuffer;
private final LongBuffer longBuffer;
private final ShortBuffer shortBuffer;

// CHECKSTYLE: ignore ParameterNumber for 1 line.
public NioBufferContainer(Buffer buffer, ByteBuffer byteBuffer, CharBuffer charBuffer, DoubleBuffer doubleBuffer,
FloatBuffer floatBuffer, IntBuffer intBuffer, LongBuffer longBuffer, ShortBuffer shortBuffer) {
this.buffer = buffer; this.byteBuffer = byteBuffer; this.charBuffer = charBuffer; this.doubleBuffer = doubleBuffer;
this.floatBuffer = floatBuffer; this.intBuffer = intBuffer; this.longBuffer = longBuffer; this.shortBuffer = shortBuffer;
}

@Override public boolean equals(Object obj) { return defaultEquals(this, obj); }
@Override public int hashCode() { return defaultHashCode(this); }
}

@SuppressWarnings("unused") // because of the use of defaultEquals and defaultHashCode
static final class CommonClassesContainer {
private final String string;
Expand Down

0 comments on commit 416fa21

Please sign in to comment.