Skip to content

Commit

Permalink
+New test for persistent byte[] Issue #72
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSchankin committed Jul 26, 2021
1 parent 5ff22ec commit 920df5e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public abstract class SamplerAspectTest {
private static final TestBean TEST_BEAN_B = new TestBean();
public static final String MY_ECHO_PARAMS = "MY ECHO PARAMS";
public static final String NO_RETURN_VALUE_SAMPLE_ID = "NoReturnValue";
public static final byte[] SOME_BYTES = {1, 2, 3, 4};


/**
Expand Down Expand Up @@ -528,6 +529,30 @@ public void samplesCanBeRecordedAndLoaded() throws IOException {
Files.delete(Paths.get(pathToFile));
}

@Test
public void byteArrayCanBeRecordedAndLoaded() throws IOException {
Sampler.clear();

final TestService testServiceSampler = Sampler.prepare(TestService.class);
Sample.of(testServiceSampler.echoParameter(any(TestBeanWithBytes.class)));

getTestService().echoParameter(new TestBeanWithBytes(SOME_BYTES));
final String pathToFile = "./record/byteArrayCanBeRecordedAndLoaded.json";
final PersistentSampleManager source = PersistentSampler.source(JsonSourceManager.builder().buildWithFile(pathToFile));
source.record();

assertFalse(SampleRepository.getInstance().isEmpty());
Sampler.clear();
assertTrue(SampleRepository.getInstance().isEmpty());

Sample.of(testServiceSampler.echoParameter(any(TestBeanWithBytes.class)));
source.load();

assertFalse(SampleRepository.getInstance().isEmpty());
assertArrayEquals(SOME_BYTES , getTestService().echoParameter(new TestBeanWithBytes(SOME_BYTES)).getSomeBytes());
Files.delete(Paths.get(pathToFile));
}

@Test
public void voidMethodsCanBeRecordedAndLoaded() throws IOException {
Sampler.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/

package de.ppi.deepsampler.provider.common;

import java.util.Arrays;
import java.util.Objects;

/**
* A very simple Bean that represents non primitive types in TestCases containing a byte[].
*/
public class TestBeanWithBytes {

private byte[] someBytes;

public TestBeanWithBytes() {
}

public TestBeanWithBytes(byte[] someBytes) {
this.someBytes = someBytes;
}

public byte[] getSomeBytes() {
return someBytes;
}

public void setSomeBytes(byte[] someBytes) {
this.someBytes = someBytes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TestBeanWithBytes that = (TestBeanWithBytes) o;
return Arrays.equals(someBytes, that.someBytes);
}

@Override
public int hashCode() {
return Arrays.hashCode(someBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public TestBeanWithoutEquals echoParameter(final TestBeanWithoutEquals someObjec
return someObjectWithoutEquals;
}

/**
* This method returns a non primitive parameter containing a byte[] if the method is not mocked.
* This Method is intended to be used in positive and negative tests.
*
* @param someObject The parameter that will be returned unchanged
* @return the unchanged parameter value
*/
public TestBeanWithBytes echoParameter(final TestBeanWithBytes someObject) {
return someObject;
}

/**
* This method is needed to test whether calls of void methods can be verified or not.
*
Expand Down Expand Up @@ -181,4 +192,6 @@ public Map<Integer, Integer> getMapOfIntegers() {

return map;
}


}

0 comments on commit 920df5e

Please sign in to comment.