|
| 1 | +// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved. |
| 2 | +// |
| 3 | +// This software, the RabbitMQ Java client library, is triple-licensed under the |
| 4 | +// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2 |
| 5 | +// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see |
| 6 | +// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL, |
| 7 | +// please see LICENSE-APACHE2. |
| 8 | +// |
| 9 | +// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, |
| 10 | +// either express or implied. See the LICENSE file for specific language governing |
| 11 | +// rights and limitations of this software. |
| 12 | +// |
| 13 | +// If you have any questions regarding licensing, please contact us at |
| 14 | + |
| 15 | + |
| 16 | +package com.rabbitmq.client.test; |
| 17 | + |
| 18 | +import com.rabbitmq.client.AMQP; |
| 19 | +import com.rabbitmq.client.impl.AMQImpl; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import java.util.Calendar; |
| 23 | +import java.util.Date; |
| 24 | + |
| 25 | +import static java.util.Collections.singletonMap; |
| 26 | +import static org.junit.Assert.assertEquals; |
| 27 | +import static org.junit.Assert.assertNotEquals; |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + */ |
| 32 | +public class GeneratedClassesTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void amqpPropertiesEqualsHashCode() { |
| 36 | + checkEquals( |
| 37 | + new AMQP.BasicProperties.Builder().correlationId("one").build(), |
| 38 | + new AMQP.BasicProperties.Builder().correlationId("one").build() |
| 39 | + ); |
| 40 | + checkNotEquals( |
| 41 | + new AMQP.BasicProperties.Builder().correlationId("one").build(), |
| 42 | + new AMQP.BasicProperties.Builder().correlationId("two").build() |
| 43 | + ); |
| 44 | + Date date = Calendar.getInstance().getTime(); |
| 45 | + checkEquals( |
| 46 | + new AMQP.BasicProperties.Builder() |
| 47 | + .deliveryMode(1) |
| 48 | + .headers(singletonMap("one", "two")) |
| 49 | + .correlationId("123") |
| 50 | + .expiration("later") |
| 51 | + .priority(10) |
| 52 | + .replyTo("me") |
| 53 | + .contentType("text/plain") |
| 54 | + .contentEncoding("UTF-8") |
| 55 | + .userId("jdoe") |
| 56 | + .appId("app1") |
| 57 | + .clusterId("cluster1") |
| 58 | + .messageId("message123") |
| 59 | + .timestamp(date) |
| 60 | + .type("type") |
| 61 | + .build(), |
| 62 | + new AMQP.BasicProperties.Builder() |
| 63 | + .deliveryMode(1) |
| 64 | + .headers(singletonMap("one", "two")) |
| 65 | + .correlationId("123") |
| 66 | + .expiration("later") |
| 67 | + .priority(10) |
| 68 | + .replyTo("me") |
| 69 | + .contentType("text/plain") |
| 70 | + .contentEncoding("UTF-8") |
| 71 | + .userId("jdoe") |
| 72 | + .appId("app1") |
| 73 | + .clusterId("cluster1") |
| 74 | + .messageId("message123") |
| 75 | + .timestamp(date) |
| 76 | + .type("type") |
| 77 | + .build() |
| 78 | + ); |
| 79 | + checkNotEquals( |
| 80 | + new AMQP.BasicProperties.Builder() |
| 81 | + .deliveryMode(1) |
| 82 | + .headers(singletonMap("one", "two")) |
| 83 | + .correlationId("123") |
| 84 | + .expiration("later") |
| 85 | + .priority(10) |
| 86 | + .replyTo("me") |
| 87 | + .contentType("text/plain") |
| 88 | + .contentEncoding("UTF-8") |
| 89 | + .userId("jdoe") |
| 90 | + .appId("app1") |
| 91 | + .clusterId("cluster1") |
| 92 | + .messageId("message123") |
| 93 | + .timestamp(date) |
| 94 | + .type("type") |
| 95 | + .build(), |
| 96 | + new AMQP.BasicProperties.Builder() |
| 97 | + .deliveryMode(2) |
| 98 | + .headers(singletonMap("one", "two")) |
| 99 | + .correlationId("123") |
| 100 | + .expiration("later") |
| 101 | + .priority(10) |
| 102 | + .replyTo("me") |
| 103 | + .contentType("text/plain") |
| 104 | + .contentEncoding("UTF-8") |
| 105 | + .userId("jdoe") |
| 106 | + .appId("app1") |
| 107 | + .clusterId("cluster1") |
| 108 | + .messageId("message123") |
| 109 | + .timestamp(date) |
| 110 | + .type("type") |
| 111 | + .build() |
| 112 | + ); |
| 113 | + |
| 114 | + } |
| 115 | + |
| 116 | + @Test public void amqImplEqualsHashCode() { |
| 117 | + checkEquals( |
| 118 | + new AMQImpl.Basic.Deliver("tag", 1L, false, "amq.direct","rk"), |
| 119 | + new AMQImpl.Basic.Deliver("tag", 1L, false, "amq.direct","rk") |
| 120 | + ); |
| 121 | + checkNotEquals( |
| 122 | + new AMQImpl.Basic.Deliver("tag", 1L, false, "amq.direct","rk"), |
| 123 | + new AMQImpl.Basic.Deliver("tag", 2L, false, "amq.direct","rk") |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + private void checkEquals(Object o1, Object o2) { |
| 128 | + assertEquals(o1, o2); |
| 129 | + assertEquals(o1.hashCode(), o2.hashCode()); |
| 130 | + } |
| 131 | + |
| 132 | + private void checkNotEquals(Object o1, Object o2) { |
| 133 | + assertNotEquals(o1, o2); |
| 134 | + } |
| 135 | +} |
0 commit comments