Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package at.tuwien.mnsa.smssender; import java.util.List; import javax.xml.bind.DatatypeConverter; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; /** * * @author Thomas */ public class SMSPDUConverterTest { public SMSPDUConverterTest() { } @Before public void setUp() { } /** * Test of getInstance method, of class SMSPDUConverter. */ @org.junit.Test public void testGetInstance() { } /** * Test of getPDU method, of class SMSPDUConverter. */ @org.junit.Test public void testGetPDU() { SMS s1 = new SMS("436604678660", "$$$"); byte[] b1 = SMSPDUConverter.getInstance().getContent(s1.getText()).message; assertEquals("028100", DatatypeConverter.printHexBinary(b1)); SMS s = new SMS("+436509030464", "SMS Rulz"); byte[] b = SMSPDUConverter.getInstance().getContent(s.getText()).message; assertEquals("D3E61424ADB3F5", DatatypeConverter.printHexBinary(b)); s = new SMS("436604678660", "lo"); b = SMSPDUConverter.getInstance().getContent(s.getText()).message; assertEquals("EC37", DatatypeConverter.printHexBinary(b)); s = new SMS("436604678660", "hellohello"); b = SMSPDUConverter.getInstance().getContent(s.getText()).message; assertEquals("E8329BFD4697D9EC37", DatatypeConverter.printHexBinary(b)); } @Test public void testLengths() { String msg, ret; msg = "1"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 1); assertEquals(ret, "31"); msg = "12"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 2); assertEquals(ret, "3119"); msg = "123"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 3); assertEquals(ret, "31D90C"); msg = "1234"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 4); assertEquals(ret, "31D98C06"); msg = "12345"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 5); assertEquals(ret, "31D98C5603"); msg = "123456"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 6); assertEquals(ret, "31D98C56B301"); msg = "1234567"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 7); assertEquals(ret, "31D98C56B3DD00"); msg = "12345678"; ret = DatatypeConverter.printHexBinary(SMSPDUConverter.getInstance().getContent(msg).message); assertEquals(SMSPDUConverter.getInstance().getContent(msg).len, 8); assertEquals(ret, "31D98C56B3DD70"); } @Test public void testExtendedChars() { SMS s = new SMS("436509030464", "^|{}[]asd"); byte[] b = SMSPDUConverter.getInstance().getContent(s.getText()).message; assertEquals("0011000C913456903040460000AA119BF286B2016E509BD486B7F185E764", s.getMessage().hex); } @Test public void testSpecialCharsConcatenation() { SMS s = new SMS("436604678660", StringUtils.repeat("", 100)); List<SMS.SMSRepresentation> singleSms = s.getMultiMessage(); assertEquals(singleSms.size(), 2); } }