Optimize RocketMQObjectMessageTest and ROcketMQTextMessageTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/commit/29f534fb Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/tree/29f534fb Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/diff/29f534fb Branch: refs/heads/jms-dev-1.1.0 Commit: 29f534fbe3b63a8788382b658226099f6c21930c Parents: 551d332 Author: zhangke <zhangke_beij...@qq.com> Authored: Tue Feb 21 07:18:56 2017 +0800 Committer: zhangke <zhangke_beij...@qq.com> Committed: Tue Feb 21 07:18:56 2017 +0800 ---------------------------------------------------------------------- .../rocketmq/jms/msg/RocketMQMessage.java | 1 + .../rocketmq/jms/msg/ObjectMessageTest.java | 93 -------------------- .../jms/msg/RocketMQObjectMessageTest.java | 73 +++++++++++++++ .../jms/msg/RocketMQTextMessageTest.java | 41 +++++++++ .../rocketmq/jms/msg/TextMessageTest.java | 51 ----------- 5 files changed, 115 insertions(+), 144 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/29f534fb/core/src/main/java/org/apache/rocketmq/jms/msg/RocketMQMessage.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/rocketmq/jms/msg/RocketMQMessage.java b/core/src/main/java/org/apache/rocketmq/jms/msg/RocketMQMessage.java index 474e646..29fe00b 100644 --- a/core/src/main/java/org/apache/rocketmq/jms/msg/RocketMQMessage.java +++ b/core/src/main/java/org/apache/rocketmq/jms/msg/RocketMQMessage.java @@ -30,6 +30,7 @@ import org.apache.rocketmq.jms.Constant; import org.apache.rocketmq.jms.support.JmsHelper; import org.apache.rocketmq.jms.support.TypeConverter; +//todo: add unit test after finishing JMS Properties public class RocketMQMessage implements javax.jms.Message { protected Map<String, Object> properties = Maps.newHashMap(); http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/29f534fb/core/src/test/java/org/apache/rocketmq/jms/msg/ObjectMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/ObjectMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/ObjectMessageTest.java deleted file mode 100644 index 3026286..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/ObjectMessageTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.jms.msg; - -import org.junit.Assert; -import org.junit.Test; - -import javax.jms.JMSException; -import java.io.Serializable; - -public class ObjectMessageTest { - - @Test - public void testGetObject() { - RocketMQObjectMessage jmsRocketMQObjectMessage = new RocketMQObjectMessage(new User("jack", 20)); - try { - Assert.assertEquals(jmsRocketMQObjectMessage.getObject(), new User("jack", 20)); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetBody() { - RocketMQObjectMessage jmsRocketMQObjectMessage = new RocketMQObjectMessage(new User("jack", 20)); - - try { - User user = (User) jmsRocketMQObjectMessage.getBody(Object.class); - System.out.println(user.getName() + ": " + user.getAge()); - Assert.assertEquals(jmsRocketMQObjectMessage.getBody(Object.class), jmsRocketMQObjectMessage.getObject()); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - - private class User implements Serializable { - private String name; - private int age; - - private User(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - - User user = (User)obj; - if (age != user.getAge()) - return false; - if (name != null ? !name.equals(user.getName()) : user.getName() != null) - return false; - return true; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/29f534fb/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java new file mode 100644 index 0000000..5291acf --- /dev/null +++ b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQObjectMessageTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.jms.msg; + +import java.io.Serializable; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class RocketMQObjectMessageTest { + + @Test + public void testGetObject() throws Exception { + final User user = new User("jack", 20); + RocketMQObjectMessage msg = new RocketMQObjectMessage(user); + assertThat((User)msg.getObject(), is(user)); + } + + @Test + public void testGetBody() throws Exception { + final User user = new User("jack", 20); + RocketMQObjectMessage msg = new RocketMQObjectMessage(user); + assertThat((User)msg.getBody(Object.class), is((User)msg.getObject())); + } + + private class User implements Serializable { + private String name; + private int age; + + private User(String name, int age) { + this.name = name; + this.age = age; + } + + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/29f534fb/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java new file mode 100644 index 0000000..f5a23e2 --- /dev/null +++ b/core/src/test/java/org/apache/rocketmq/jms/msg/RocketMQTextMessageTest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.jms.msg; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class RocketMQTextMessageTest { + private String text = "jmsRocketMQTextMessage test"; + + @Test + public void testGetBody() throws Exception { + RocketMQTextMessage msg = new RocketMQTextMessage(text); + assertThat(msg.getBody(String.class), is(text)); + } + + @Test + public void testSetText() throws Exception { + RocketMQTextMessage msg = new RocketMQTextMessage(); + msg.setText(text); + assertThat(msg.getText(), is(text)); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/29f534fb/core/src/test/java/org/apache/rocketmq/jms/msg/TextMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/TextMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/TextMessageTest.java deleted file mode 100644 index 8ae9f42..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/TextMessageTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.jms.msg; - -import javax.jms.JMSException; - -import org.junit.Assert; -import org.junit.Test; - -public class TextMessageTest { - private String text = "jmsRocketMQTextMessage test"; - - @Test - public void testGetBody() { - RocketMQTextMessage jmsRocketMQTextMessage = new RocketMQTextMessage(text); - try { - Assert.assertEquals(jmsRocketMQTextMessage.getBody(String.class), text); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - - @Test - public void testSetGetText() { - RocketMQTextMessage jmsRocketMQTextMessage = new RocketMQTextMessage(); - jmsRocketMQTextMessage.setText(text); - try { - Assert.assertEquals(jmsRocketMQTextMessage.getText(), text); - } - catch (JMSException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file