home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (MessageTest.java)

This example Java source code file (MessageTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

exception, list, message, messagetest, object, string, testcase, this, util

The MessageTest.java Java example source code

package com.google.inject.spi;

import com.google.common.collect.Lists;
import junit.framework.TestCase;

import java.util.List;

/**
 * Tests for {@link Message}.
 */
public class MessageTest extends TestCase {

  public void testMessageHashCodeVariesWithSource() {
    String innerMessage = "This is the message.";
    Message firstMessage = new Message(1, innerMessage);
    Message secondMessage = new Message(2, innerMessage);
    assertFalse(firstMessage.hashCode() == secondMessage.hashCode());
  }

  public void testMessageHashCodeVariesWithCause() {
    String innerMessage = "This is the message.";
    List<Object> sourceList = Lists.newArrayList(new Object());
    // the throwable argument of each Message below do not have value equality
    Message firstMessage = new Message(sourceList, innerMessage, new Exception(innerMessage));
    Message secondMessage = new Message(sourceList, innerMessage, new Exception(innerMessage));
    assertFalse(firstMessage.hashCode() == secondMessage.hashCode());
  }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java MessageTest.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.