import org.hamcrest.Matchers; import org.junit.Test; import static org.junit.Assert.assertThat; public class ColorTest { @Test public void testColorGreen() { Color myColor = new Color(0, 255, 0); assertThat("Color should be green", myColor, Matchers.ensureGreen()); } }
import org.hamcrest.Matchers; import org.junit.Test; import static org.junit.Assert.assertThat; public class ButtonTest { @Test public void testButtonGreen() { Button myButton = new Button("Green"); assertThat("Button should be green", myButton.getColor(), Matchers.ensureGreen()); } }In this example, we are testing if the color of the button object myButton is green using the ensureGreen method. The org.hamcrest.Matchers ensureGreen method belongs to the org.hamcrest package library. It is commonly used in unit testing to verify that a particular color is green.