JAVA的Record类型实现Record对象嵌套测试------JAVA

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.2.2</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>demo</description>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<excludes>
						<exclude>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>3.2.2</version>
       <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>demo</description>
    <properties>
       <java.version>17</java.version>
    </properties>
    <dependencies>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
       <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
       </dependency>
       <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <optional>true</optional>
       </dependency>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
       </dependency>
    </dependencies>

    <build>
       <plugins>
          <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
                <excludes>
                   <exclude>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                   </exclude>
                </excludes>
             </configuration>
          </plugin>
       </plugins>
    </build>

</project>
package com.example.demo;

public record Address(String city,String address,String zipcode) {
}
package com.example.demo;

public record Address(String city,String address,String zipcode) {
}
package com.example.demo;

public record Customer(String id,String name,PhoneNumber phoneNumber,Address address) {
}
package com.example.demo;

public record Customer(String id,String name,PhoneNumber phoneNumber,Address address) {
}
package com.example.demo;

public record PhoneNumber(String areaCode,String number) {
}
package com.example.demo;

public record PhoneNumber(String areaCode,String number) {
}
package com.example.demo;

import org.junit.Test;

import java.util.ArrayList;

/**
 * Unit test for simple App.
 */
public class StudentTest {
    @Test
    public void Test01(){
//        创建Record对象
//        这里也会先执行紧凑的构造方法
        Student Rose = new Student(1001,"Rose","abc",15);
        System.out.println(Rose.toString());
        Integer age = Rose.age();
        System.out.println(age);
        String name = Rose.name();
        System.out.println(name);
        String email = Rose.email();
        System.out.println(email);
        System.out.println("哈哈");
        System.out.println(Rose.concat());
        System.out.println(Student.emailToUpperCase("Dasd"));
        Student jack = new Student(2001, "Jack");
        System.out.println(jack);
    }
    @Test
    public void Test02(){
        ProductRecord record = new ProductRecord(1,"手机",200);
        record.print();
        ArrayList<Object> objects = new ArrayList<>();
        System.out.println(objects.get(1));
    }
    @Test
    public void Test03(){
//        定义java的Record
        record SaleRecord(String saleId,String productName,Double money){}
        SaleRecord saleRecord = new SaleRecord("S001","显示器",3000.1);
        System.out.println(saleRecord);
    }

    @Test
    public void Test04() {
        Address address = new Address("北京","大兴区凉水河二街八号10栋3层","100176");
        PhoneNumber phoneNumber = new PhoneNumber("010","400-8080-105");
        Customer customer = new Customer("c101","Jack",phoneNumber,address);
        System.out.println(customer);
    }
}
package com.example.demo;

import org.junit.Test;

import java.util.ArrayList;

/**
 * Unit test for simple App.
 */
public class StudentTest {
    @Test
    public void Test01(){
//        创建Record对象
//        这里也会先执行紧凑的构造方法
        Student Rose = new Student(1001,"Rose","abc",15);
        System.out.println(Rose.toString());
        Integer age = Rose.age();
        System.out.println(age);
        String name = Rose.name();
        System.out.println(name);
        String email = Rose.email();
        System.out.println(email);
        System.out.println("哈哈");
        System.out.println(Rose.concat());
        System.out.println(Student.emailToUpperCase("Dasd"));
        Student jack = new Student(2001, "Jack");
        System.out.println(jack);
    }
    @Test
    public void Test02(){
        ProductRecord record = new ProductRecord(1,"手机",200);
        record.print();
        ArrayList<Object> objects = new ArrayList<>();
        System.out.println(objects.get(1));
    }
    @Test
    public void Test03(){
//        定义java的Record
        record SaleRecord(String saleId,String productName,Double money){}
        SaleRecord saleRecord = new SaleRecord("S001","显示器",3000.1);
        System.out.println(saleRecord);
    }

    @Test
    public void Test04() {
        Address address = new Address("北京","大兴区凉水河二街八号10栋3层","100176");
        PhoneNumber phoneNumber = new PhoneNumber("010","400-8080-105");
        Customer customer = new Customer("c101","Jack",phoneNumber,address);
        System.out.println(customer);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值