import com.msb.enums.DirEnum; import org.junit.Assert; import org.junit.Test; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Random; /** * @Author bingor * @Date 2022-10-01 10:48 * @Description: com.msb.test * @Version: 1.0 */ public class CommonTest { @Test public void testReadImage() throws IOException { BufferedImage bufferedImage = ImageIO.read(new File("E:\\myfile\\msb_马士兵教育体系\\课程下载的资源\\MCA高级构架师\\73-坦克大战(一期)\\images\\tankD.gif")); Assert.assertNotNull(bufferedImage); BufferedImage image = ImageIO.read(CommonTest.class.getClassLoader().getResourceAsStream("images/tankD.gif")); Assert.assertNotNull(image); } @Test public void testEnum() { Random random = new Random(); System.out.println(DirEnum.valueOf(random.nextInt(3))); System.out.println(DirEnum.valueOf(random.nextInt(3))); System.out.println(DirEnum.valueOf(random.nextInt(3))); System.out.println(DirEnum.valueOf(random.nextInt(3))); } @Test public void testCommon() { boolean bool = xh(); System.out.println(bool); } public boolean xh() { int [] indexs = {1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (int index : indexs) { if(index == 5) return false; System.out.println(index); } return true; } @Test public void testString() { String s1 = "abc"; String s2 = "abc"; String s3 = new String("abc"); String s4 = new String("abc"); System.out.println(s1 == s2); //true, 因为都是从字符串常量池取出的,指向的是同一个对象 System.out.println(s1 == s3); //false 因为两个对象地址不一样 System.out.println(s3 == s4); //false 因为两个对象地址不一样 System.out.println(s3.intern() == s1); //true s3.intern() 指的是该地址指向内部指向常量池的对象 System.out.println(s3.intern() == s4.intern()); //true } }