1 /*
2 * SPDX-License-Identifier: Apache-2.0
3 * See LICENSE file for details.
4 *
5 * Copyright 2012-2026 hazendaz
6 *
7 * Portions of initial baseline code (getter/setter test) by Rob Dawson (CodeBox)
8 */
9 package com.codebox.bean;
10
11 /**
12 * The Class IdentityEqualsStringBean.
13 *
14 * <p>
15 * A bean whose {@code equals} uses reference equality ({@code ==}) for its {@code String} field. This causes
16 * {@code EqualsVerifier} to fail (it creates non-interned strings), which exercises the {@code AssertionError} catch
17 * block in {@code JavaBeanTesterWorker.processEqualsVerifierSymmetricTest()} (L440-441).
18 *
19 * <p>
20 * The worker's own checks still pass because {@link com.codebox.bean.ValueBuilder} always returns the same interned
21 * {@code "TEST_VALUE"} literal, so two loaded instances share the same {@code String} reference.
22 */
23 public class IdentityEqualsStringBean {
24
25 /** The value. */
26 private String value;
27
28 /**
29 * Gets the value.
30 *
31 * @return the value
32 */
33 public String getValue() {
34 return this.value;
35 }
36
37 /**
38 * Sets the value.
39 *
40 * @param value
41 * the value
42 */
43 public void setValue(final String value) {
44 this.value = value;
45 }
46
47 @Override
48 public boolean equals(final Object o) {
49 if (this == o) {
50 return true;
51 }
52 if (!(o instanceof IdentityEqualsStringBean)) {
53 return false;
54 }
55 // Intentionally uses == (reference equality) instead of Objects.equals to trigger EqualsVerifier failure
56 return this.value == ((IdentityEqualsStringBean) o).value; // NOSONAR
57 }
58
59 @Override
60 public int hashCode() {
61 // Return a non-zero prime when null so the ByteBuddy extension (which multiplies by 31) gets a
62 // different hashCode than the base class, ensuring assertNotEquals(ext, y) passes in the worker tests.
63 return this.value == null ? 31 : this.value.hashCode();
64 }
65
66 }