Skip to content

Commit

Permalink
SimpleConfiguration is now Serializable
Browse files Browse the repository at this point in the history
It also properly implements equals, hashCode and toString
  • Loading branch information
ar committed Jan 14, 2017
1 parent ab85f61 commit a5b1049
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
25 changes: 24 additions & 1 deletion jpos/src/main/java/org/jpos/core/SimpleConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;

/**
* @author [email protected]
* @version $Id$
* @since jPOS 1.1
*/
public class SimpleConfiguration implements Configuration {
public class SimpleConfiguration implements Configuration, Serializable {
private Properties props;

public SimpleConfiguration () {
Expand Down Expand Up @@ -152,4 +153,26 @@ public synchronized void put (String name, Object value) {
public Set<String> keySet() {
return props.stringPropertyNames();
}

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

@Override
public int hashCode() {
return Objects.hash(props);
}

@Override
public String toString() {
return "SimpleConfiguration{" +
"props=" + props +
'}';
}

private static final long serialVersionUID = -6361797037366246968L;
}
13 changes: 13 additions & 0 deletions jpos/src/test/java/org/jpos/core/SimpleConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.jpos.core;

import static org.jpos.util.Serializer.serialize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
Expand All @@ -31,6 +32,8 @@

// import junitx.util.PrivateAccessor;

import org.jpos.iso.ISOUtil;
import org.jpos.util.Serializer;
import org.junit.Test;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -446,4 +449,14 @@ public void testPutThrowsNullPointerException() throws Throwable {
assertNull("ex.getMessage()", ex.getMessage());
}
}

@Test
public void testSerializable() throws Throwable {
SimpleConfiguration cfg = new SimpleConfiguration();
cfg.put ("A", "The Quick Brown Fox Jumps Over The Lazy Dog");
byte[] b = Serializer.serialize (cfg);
Configuration cfg1 = (Configuration) Serializer.deserialize(b);
assertEquals("cfg.A should equal cfg1.A", cfg.get("A"), cfg1.get("A"));
assertEquals ("cfg should equal cfg1", cfg, cfg1);
}
}

0 comments on commit a5b1049

Please sign in to comment.