1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ancientprogramming.fixedformat4j.issues;
17
18 import com.ancientprogramming.fixedformat4j.annotation.Align;
19 import com.ancientprogramming.fixedformat4j.annotation.Field;
20 import com.ancientprogramming.fixedformat4j.annotation.Record;
21 import com.ancientprogramming.fixedformat4j.format.FixedFormatManager;
22 import com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl;
23 import junit.framework.TestCase;
24 import org.junit.Test;
25
26
27
28
29
30
31
32 public class TestIssue9 extends TestCase {
33
34 FixedFormatManager fixedFormatManager = new FixedFormatManagerImpl();
35
36 @Test
37 public void testLastColumnIsIgnored() {
38 String text21 = "1234567890some ";
39 String text20 = "1234567890some ";
40 String text19 = "1234567890some ";
41 String text11 = "1234567890x";
42 String text10 = "1234567890";
43 String text9 = "123456789";
44
45 assertText(1234567890, "some", fixedFormatManager.load(Issue9.class, text21));
46 assertText(1234567890, "some", fixedFormatManager.load(Issue9.class, text20));
47 assertText(1234567890, "some", fixedFormatManager.load(Issue9.class, text19));
48 assertText(1234567890, "x", fixedFormatManager.load(Issue9.class, text11));
49 assertText(1234567890, null, fixedFormatManager.load(Issue9.class, text10));
50 assertText(123456789, null, fixedFormatManager.load(Issue9.class, text9));
51
52 }
53
54 private void assertText(int expectedNumber, String expectedString, Issue9 actual) {
55 assertEquals(expectedNumber, actual.getNumber());
56 assertEquals(expectedString, actual.getString());
57 }
58
59
60 @Record
61 public static class Issue9 {
62
63 private int number;
64 private String string;
65
66
67
68 @Field(offset = 1, length = 10, align = Align.RIGHT, paddingChar = '0')
69 public int getNumber() {
70 return number;
71 }
72
73 public void setNumber(int number) {
74 this.number = number;
75 }
76
77
78 @Field(offset = 11, length = 10)
79 public String getString() {
80 return string;
81 }
82
83 public void setString(String string) {
84 this.string = string;
85 }
86 }
87 }