content: package com.alibaba.fastjson2.spring;
  
  import com.alibaba.fastjson2.JSONB;
  import com.alibaba.fastjson2.support.config.FastJsonConfig;
  import com.alibaba.fastjson2.support.spring.messaging.converter.MappingFastJsonJSONBMessageConverter;
  import org.junit.jupiter.api.Test;
  import org.springframework.messaging.Message;
  import org.springframework.messaging.MessageHeaders;
  
  import static org.junit.jupiter.api.Assertions.*;
  
  public class MappingFastJsonJSONBMessageConverterTest {
      @Test
      public void test_1() throws Exception {
          MappingFastJsonJSONBMessageConverter converter = new MappingFastJsonJSONBMessageConverter();
  
          assertNotNull(converter.getFastJsonConfig());
          converter.setFastJsonConfig(new FastJsonConfig());
  
          VO p = new VO();
          p.setId(1);
  
          byte[] bytes = JSONB.toBytes(p);
  
          BytesMessage message = new BytesMessage(bytes);
  
          // test fromMessage/convertFromInternal
          VO vo = (VO) converter.fromMessage(message, VO.class);
          assertEquals(1, vo.getId());
  
          // test toMessage/convertToInternal
          Message message1 = converter.toMessage(vo, null);
          assertEquals("{\"id\":1}", JSONB.parseObject((byte[]) message1.getPayload()).toString());
  
          // test toMessage/convertToInternal
          Message message2 = converter.toMessage("{\"id\":1}", null);
          assertEquals("{\"id\":1}", JSONB.parseObject((byte[]) message2.getPayload()).toString());
  
          assertThrows(IllegalArgumentException.class, () -> converter.setSerializedPayloadClass(String.class));
      }
  
      public static class BytesMessage
              implements Message<byte[]> {
          private byte[] payload;
  
          public BytesMessage(byte[] payload) {
              this.payload = payload;
          }
  
          @Override
          public byte[] getPayload() {
              return payload;
          }
  
          @Override
          public MessageHeaders getHeaders() {
              return null;
          }
      }
  
      public static class VO {
          private int id;
  
          public int getId() {
              return id;
          }
  
          public void setId(int id) {
              this.id = id;
          }
      }
  }
  