1
0
Fork 0
mirror of https://github.com/zxing/zxing.git synced 2025-03-05 20:48:51 -08:00

Some style and related stuff I found in code inspection

git-svn-id: https://zxing.googlecode.com/svn/trunk@1921 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-09-19 14:04:25 +00:00
parent e1aab01022
commit a035285f2f
19 changed files with 170 additions and 178 deletions

View file

@ -34,7 +34,6 @@ public interface Writer {
* @param format The barcode format to generate
* @param width The preferred width in pixels
* @param height The preferred height in pixels
* @return The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
*/
BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
throws WriterException;
@ -46,7 +45,6 @@ public interface Writer {
* @param width The preferred width in pixels
* @param height The preferred height in pixels
* @param hints Additional parameters to supply to the encoder
* @return The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
*/
BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints)
throws WriterException;

View file

@ -53,29 +53,20 @@ public class ExpandedProductParsedResult extends ParsedResult {
// For AIS that not exist in this object
private final Hashtable uncommonAIs;
ExpandedProductParsedResult() {
super(ParsedResultType.PRODUCT);
this.productID = "";
this.sscc = "";
this.lotNumber = "";
this.productionDate = "";
this.packagingDate = "";
this.bestBeforeDate = "";
this.expirationDate = "";
this.weight = "";
this.weightType = "";
this.weightIncrement = "";
this.price = "";
this.priceIncrement = "";
this.priceCurrency = "";
this.uncommonAIs = new Hashtable();
}
public ExpandedProductParsedResult(String productID, String sscc,
String lotNumber, String productionDate, String packagingDate,
String bestBeforeDate, String expirationDate, String weight,
String weightType, String weightIncrement, String price,
String priceIncrement, String priceCurrency, Hashtable uncommonAIs) {
public ExpandedProductParsedResult(String productID,
String sscc,
String lotNumber,
String productionDate,
String packagingDate,
String bestBeforeDate,
String expirationDate,
String weight,
String weightType,
String weightIncrement,
String price,
String priceIncrement,
String priceCurrency,
Hashtable uncommonAIs) {
super(ParsedResultType.PRODUCT);
this.productID = productID;
this.sscc = sscc;
@ -100,37 +91,45 @@ public class ExpandedProductParsedResult extends ParsedResult {
ExpandedProductParsedResult other = (ExpandedProductParsedResult)o;
return this.productID.equals( other.productID)
&& this.sscc.equals( other.sscc)
&& this.lotNumber.equals( other.lotNumber)
&& this.productionDate.equals( other.productionDate)
&& this.bestBeforeDate.equals( other.bestBeforeDate)
&& this.expirationDate.equals( other.expirationDate)
&& this.weight.equals( other.weight)
&& this.weightType.equals( other.weightType)
&& this.weightIncrement.equals( other.weightIncrement)
&& this.price.equals( other.price)
&& this.priceIncrement.equals( other.priceIncrement)
&& this.priceCurrency.equals( other.priceCurrency)
&& this.uncommonAIs.equals( other.uncommonAIs);
return equalsOrNull(productID, other.productID)
&& equalsOrNull(sscc, other.sscc)
&& equalsOrNull(lotNumber, other.lotNumber)
&& equalsOrNull(productionDate, other.productionDate)
&& equalsOrNull(bestBeforeDate, other.bestBeforeDate)
&& equalsOrNull(expirationDate, other.expirationDate)
&& equalsOrNull(weight, other.weight)
&& equalsOrNull(weightType, other.weightType)
&& equalsOrNull(weightIncrement, other.weightIncrement)
&& equalsOrNull(price, other.price)
&& equalsOrNull(priceIncrement, other.priceIncrement)
&& equalsOrNull(priceCurrency, other.priceCurrency)
&& equalsOrNull(uncommonAIs, other.uncommonAIs);
}
private static boolean equalsOrNull(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
public int hashCode(){
int hash1 = this.productID.hashCode();
hash1 = 31 * hash1 + this.sscc.hashCode();
hash1 = 31 * hash1 + this.lotNumber.hashCode();
hash1 = 31 * hash1 + this.productionDate.hashCode();
hash1 = 31 * hash1 + this.bestBeforeDate.hashCode();
hash1 = 31 * hash1 + this.expirationDate.hashCode();
hash1 = 31 * hash1 + this.weight.hashCode();
int hash = 0;
hash ^= hashNotNull(productID);
hash ^= hashNotNull(sscc);
hash ^= hashNotNull(lotNumber);
hash ^= hashNotNull(productionDate);
hash ^= hashNotNull(bestBeforeDate);
hash ^= hashNotNull(expirationDate);
hash ^= hashNotNull(weight);
hash ^= hashNotNull(weightType);
hash ^= hashNotNull(weightIncrement);
hash ^= hashNotNull(price);
hash ^= hashNotNull(priceIncrement);
hash ^= hashNotNull(priceCurrency);
hash ^= hashNotNull(uncommonAIs);
return hash;
}
int hash2 = this.weightType.hashCode();
hash2 = 31 * hash2 + this.weightIncrement.hashCode();
hash2 = 31 * hash2 + this.price.hashCode();
hash2 = 31 * hash2 + this.priceIncrement.hashCode();
hash2 = 31 * hash2 + this.priceCurrency.hashCode();
hash2 = 31 * hash2 + this.uncommonAIs.hashCode();
return hash1 ^ hash2;
private static int hashNotNull(Object o) {
return o == null ? 0 : o.hashCode();
}
public String getProductID() {

View file

@ -57,26 +57,26 @@ final class ExpandedProductResultParser extends ResultParser {
return null;
}
String productID = "-";
String sscc = "-";
String lotNumber = "-";
String productionDate = "-";
String packagingDate = "-";
String bestBeforeDate = "-";
String expirationDate = "-";
String weight = "-";
String weightType = "-";
String weightIncrement = "-";
String price = "-";
String priceIncrement = "-";
String priceCurrency = "-";
String productID = null;
String sscc = null;
String lotNumber = null;
String productionDate = null;
String packagingDate = null;
String bestBeforeDate = null;
String expirationDate = null;
String weight = null;
String weightType = null;
String weightIncrement = null;
String price = null;
String priceIncrement = null;
String priceCurrency = null;
Hashtable uncommonAIs = new Hashtable();
int i = 0;
while (i < rawText.length()) {
String ai = findAIvalue(i, rawText);
if ("ERROR".equals(ai)) {
if (ai == null) {
// Error. Code doesn't match with RSS expanded pattern
// ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
return null;
@ -136,10 +136,20 @@ final class ExpandedProductResultParser extends ResultParser {
}
}
return new ExpandedProductParsedResult(productID, sscc, lotNumber,
productionDate, packagingDate, bestBeforeDate, expirationDate,
weight, weightType, weightIncrement, price, priceIncrement,
priceCurrency, uncommonAIs);
return new ExpandedProductParsedResult(productID,
sscc,
lotNumber,
productionDate,
packagingDate,
bestBeforeDate,
expirationDate,
weight,
weightType,
weightIncrement,
price,
priceIncrement,
priceCurrency,
uncommonAIs);
}
private static String findAIvalue(int i, String rawText) {
@ -147,30 +157,19 @@ final class ExpandedProductResultParser extends ResultParser {
char c = rawText.charAt(i);
// First character must be a open parenthesis.If not, ERROR
if (c != '(') {
return "ERROR";
return null;
}
String rawTextAux = rawText.substring(i + 1);
for (int index = 0; index < rawTextAux.length(); index++) {
char currentChar = rawTextAux.charAt(index);
switch (currentChar){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
buf.append(currentChar);
break;
case ')':
return buf.toString();
default:
return "ERROR";
if (currentChar == ')') {
return buf.toString();
} else if (currentChar >= '0' && currentChar <= '9') {
buf.append(currentChar);
} else {
return null;
}
}
return buf.toString();
@ -185,7 +184,7 @@ final class ExpandedProductResultParser extends ResultParser {
if (c == '(') {
// We look for a new AI. If it doesn't exist (ERROR), we coninue
// with the iteration
if ("ERROR".equals(findAIvalue(index, rawTextAux))) {
if (findAIvalue(index, rawTextAux) == null) {
buf.append('(');
} else {
break;

View file

@ -30,7 +30,7 @@ import java.util.Hashtable;
*/
public final class EAN13Writer extends UPCEANWriter {
private static final int codeWidth = 3 + // start guard
private static final int CODE_WIDTH = 3 + // start guard
(7 * 6) + // left bars
5 + // middle guard
(7 * 6) + // right bars
@ -53,7 +53,7 @@ public final class EAN13Writer extends UPCEANWriter {
int firstDigit = Integer.parseInt(contents.substring(0, 1));
int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];
byte[] result = new byte[codeWidth];
byte[] result = new byte[CODE_WIDTH];
int pos = 0;
pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

View file

@ -29,7 +29,7 @@ import java.util.Hashtable;
*/
public final class EAN8Writer extends UPCEANWriter {
private static final int codeWidth = 3 + // start guard
private static final int CODE_WIDTH = 3 + // start guard
(7 * 4) + // left bars
5 + // middle guard
(7 * 4) + // right bars
@ -52,7 +52,7 @@ public final class EAN8Writer extends UPCEANWriter {
"Requested contents should be 8 digits long, but got " + contents.length());
}
byte[] result = new byte[codeWidth];
byte[] result = new byte[CODE_WIDTH];
int pos = 0;
pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

View file

@ -35,16 +35,16 @@ public abstract class AbstractRSSReader extends OneDReader {
protected final int[] evenCounts;
protected AbstractRSSReader(){
decodeFinderCounters = new int[4];
dataCharacterCounters = new int[8];
oddRoundingErrors = new float[4];
evenRoundingErrors = new float[4];
oddCounts = new int[dataCharacterCounters.length / 2];
evenCounts = new int[dataCharacterCounters.length / 2];
decodeFinderCounters = new int[4];
dataCharacterCounters = new int[8];
oddRoundingErrors = new float[4];
evenRoundingErrors = new float[4];
oddCounts = new int[dataCharacterCounters.length / 2];
evenCounts = new int[dataCharacterCounters.length / 2];
}
protected static int parseFinderValue(int[] counters, int [][] finderPatterns) throws NotFoundException {
protected static int parseFinderValue(int[] counters, int[][] finderPatterns) throws NotFoundException {
for (int value = 0; value < finderPatterns.length; value++) {
if (patternMatchVariance(counters, finderPatterns[value], MAX_INDIVIDUAL_VARIANCE) <
MAX_AVG_VARIANCE) {

View file

@ -34,30 +34,30 @@ import com.google.zxing.common.BitArray;
*/
final class AI01392xDecoder extends AI01decoder {
private static final int headerSize = 5 + 1 + 2;
private static final int lastDigitSize = 2;
private static final int HEADER_SIZE = 5 + 1 + 2;
private static final int LAST_DIGIT_SIZE = 2;
AI01392xDecoder(BitArray information) {
super(information);
}
public String parseInformation() throws NotFoundException {
if (this.information.size < headerSize + gtinSize) {
if (this.information.size < HEADER_SIZE + GTIN_SIZE) {
throw NotFoundException.getNotFoundInstance();
}
StringBuffer buf = new StringBuffer();
encodeCompressedGtin(buf, headerSize);
encodeCompressedGtin(buf, HEADER_SIZE);
int lastAIdigit =
this.generalDecoder.extractNumericValueFromBitArray(headerSize + gtinSize, lastDigitSize);
this.generalDecoder.extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
buf.append("(392");
buf.append(lastAIdigit);
buf.append(')');
DecodedInformation decodedInformation =
this.generalDecoder.decodeGeneralPurposeField(headerSize + gtinSize + lastDigitSize, null);
this.generalDecoder.decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, null);
buf.append(decodedInformation.getNewString());
return buf.toString();

View file

@ -33,32 +33,32 @@ import com.google.zxing.common.BitArray;
*/
final class AI01393xDecoder extends AI01decoder {
private static final int headerSize = 5 + 1 + 2;
private static final int lastDigitSize = 2;
private static final int firstThreeDigitsSize = 10;
private static final int HEADER_SIZE = 5 + 1 + 2;
private static final int LAST_DIGIT_SIZE = 2;
private static final int FIRST_THREE_DIGITS_SIZE = 10;
AI01393xDecoder(BitArray information) {
super(information);
}
public String parseInformation() throws NotFoundException {
if(this.information.size < headerSize + gtinSize) {
if(this.information.size < HEADER_SIZE + GTIN_SIZE) {
throw NotFoundException.getNotFoundInstance();
}
StringBuffer buf = new StringBuffer();
encodeCompressedGtin(buf, headerSize);
encodeCompressedGtin(buf, HEADER_SIZE);
int lastAIdigit =
this.generalDecoder.extractNumericValueFromBitArray(headerSize + gtinSize, lastDigitSize);
this.generalDecoder.extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
buf.append("(393");
buf.append(lastAIdigit);
buf.append(')');
int firstThreeDigits =
this.generalDecoder.extractNumericValueFromBitArray(headerSize + gtinSize + lastDigitSize, firstThreeDigitsSize);
this.generalDecoder.extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, FIRST_THREE_DIGITS_SIZE);
if(firstThreeDigits / 100 == 0) {
buf.append('0');
}
@ -68,7 +68,7 @@ final class AI01393xDecoder extends AI01decoder {
buf.append(firstThreeDigits);
DecodedInformation generalInformation =
this.generalDecoder.decodeGeneralPurposeField(headerSize + gtinSize + lastDigitSize + firstThreeDigitsSize, null);
this.generalDecoder.decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE + FIRST_THREE_DIGITS_SIZE, null);
buf.append(generalInformation.getNewString());
return buf.toString();

View file

@ -35,9 +35,9 @@ import com.google.zxing.common.BitArray;
*/
final class AI013x0x1xDecoder extends AI01weightDecoder {
private static final int headerSize = 7 + 1;
private static final int weightSize = 20;
private static final int dateSize = 16;
private static final int HEADER_SIZE = 7 + 1;
private static final int WEIGHT_SIZE = 20;
private static final int DATE_SIZE = 16;
private final String dateCode;
private final String firstAIdigits;
@ -49,21 +49,21 @@ final class AI013x0x1xDecoder extends AI01weightDecoder {
}
public String parseInformation() throws NotFoundException {
if (this.information.size != headerSize + gtinSize + weightSize + dateSize) {
if (this.information.size != HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE + DATE_SIZE) {
throw NotFoundException.getNotFoundInstance();
}
StringBuffer buf = new StringBuffer();
encodeCompressedGtin(buf, headerSize);
encodeCompressedWeight(buf, headerSize + gtinSize, weightSize);
encodeCompressedDate(buf, headerSize + gtinSize + weightSize);
encodeCompressedGtin(buf, HEADER_SIZE);
encodeCompressedWeight(buf, HEADER_SIZE + GTIN_SIZE, WEIGHT_SIZE);
encodeCompressedDate(buf, HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE);
return buf.toString();
}
private void encodeCompressedDate(StringBuffer buf, int currentPos) {
int numericDate = this.generalDecoder.extractNumericValueFromBitArray(currentPos, dateSize);
int numericDate = this.generalDecoder.extractNumericValueFromBitArray(currentPos, DATE_SIZE);
if(numericDate == 38400) {
return;
}

View file

@ -34,22 +34,22 @@ import com.google.zxing.common.BitArray;
*/
abstract class AI013x0xDecoder extends AI01weightDecoder {
private static final int headerSize = 4 + 1;
private static final int weightSize = 15;
private static final int HEADER_SIZE = 4 + 1;
private static final int WEIGHT_SIZE = 15;
AI013x0xDecoder(BitArray information) {
super(information);
}
public String parseInformation() throws NotFoundException {
if (this.information.size != headerSize + gtinSize + weightSize) {
if (this.information.size != HEADER_SIZE + GTIN_SIZE + WEIGHT_SIZE) {
throw NotFoundException.getNotFoundInstance();
}
StringBuffer buf = new StringBuffer();
encodeCompressedGtin(buf, headerSize);
encodeCompressedWeight(buf, headerSize + gtinSize, weightSize);
encodeCompressedGtin(buf, HEADER_SIZE);
encodeCompressedWeight(buf, HEADER_SIZE + GTIN_SIZE, WEIGHT_SIZE);
return buf.toString();
}

View file

@ -34,7 +34,7 @@ import com.google.zxing.common.BitArray;
*/
abstract class AI01decoder extends AbstractExpandedDecoder {
protected static final int gtinSize = 40;
protected static final int GTIN_SIZE = 40;
AI01decoder(BitArray information) {
super(information);

View file

@ -35,14 +35,8 @@ final class BlockParsedResult {
private final DecodedInformation decodedInformation;
private final boolean finished;
BlockParsedResult() {
this.finished = true;
this.decodedInformation = null;
}
BlockParsedResult(boolean finished) {
this.finished = finished;
this.decodedInformation = null;
this(null, finished);
}
BlockParsedResult(DecodedInformation information, boolean finished) {

View file

@ -191,7 +191,7 @@ final class FieldParser {
static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFoundException{
if(rawInformation.length() == 0) {
return "";
return null;
}
// Processing 2-digit AIs
@ -267,7 +267,9 @@ final class FieldParser {
String field = rawInformation.substring(aiSize, aiSize + fieldSize);
String remaining = rawInformation.substring(aiSize + fieldSize);
return '(' + ai + ')' + field + parseFieldsInGeneralPurpose(remaining);
String result = '(' + ai + ')' + field;
String parsedAI = parseFieldsInGeneralPurpose(remaining);
return parsedAI == null ? result : result + parsedAI;
}
private static String processVariableAI(int aiSize, int variableFieldSize, String rawInformation) throws NotFoundException {
@ -280,6 +282,8 @@ final class FieldParser {
}
String field = rawInformation.substring(aiSize, maxSize);
String remaining = rawInformation.substring(maxSize);
return '(' + ai + ')' + field + parseFieldsInGeneralPurpose(remaining);
String result = '(' + ai + ')' + field;
String parsedAI = parseFieldsInGeneralPurpose(remaining);
return parsedAI == null ? result : result + parsedAI;
}
}

View file

@ -49,7 +49,9 @@ final class GeneralAppIdDecoder {
do{
DecodedInformation info = this.decodeGeneralPurposeField(currentPosition, remaining);
String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
buff.append(parsedFields);
if (parsedFields != null) {
buff.append(parsedFields);
}
if(info.isRemaining()) {
remaining = String.valueOf(info.getRemainingValue());
} else {

View file

@ -29,6 +29,8 @@ import com.google.zxing.common.BitMatrix;
*/
final class BitMatrixParser {
private static final int[] NO_ERRORS = new int[0];
private static final int MAX_ROW_DIFFERENCE = 6;
private static final int MAX_ROWS = 90;
//private static final int MAX_COLUMNS = 30;
@ -43,7 +45,7 @@ final class BitMatrixParser {
private int leftColumnECData = 0;
private int rightColumnECData = 0;
private int eraseCount = 0;
private int[] erasures = null;
private int[] erasures;
private int ecLevel = -1;
BitMatrixParser(BitMatrix bitMatrix) {
@ -80,8 +82,7 @@ final class BitMatrixParser {
if (rowNumber >= MAX_ROWS) {
// Something is wrong, since we have exceeded
// the maximum rows in the specification.
// TODO Maybe return error code
return null;
throw FormatException.getFormatInstance();
}
int rowDifference = 0;
// Scan a line of modules and check the
@ -117,8 +118,7 @@ final class BitMatrixParser {
if (next == -1) {
// Something is wrong, since we have exceeded
// the maximum columns in the specification.
// TODO Maybe return error code
return null;
throw FormatException.getFormatInstance();
}
// Reinitialize the row counters.
for (int j = 0; j < rowCounters.length; j++) {
@ -138,8 +138,7 @@ final class BitMatrixParser {
if (rowNumber >= MAX_ROWS) {
// Something is wrong, since we have exceeded
// the maximum rows in the specification.
// TODO Maybe return error code
return null;
throw FormatException.getFormatInstance();
}
next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);
rowNumber++;
@ -157,15 +156,15 @@ final class BitMatrixParser {
* @return the new trimmed array
*/
private static int[] trimArray(int[] array, int size) {
if (size > 0) {
int[] a = new int[size];
for (int i = 0; i < size; i++) {
a[i] = array[i];
}
return a;
} else {
return null;
if (size < 0) {
throw new IllegalArgumentException();
}
if (size == 0) {
return NO_ERRORS;
}
int[] a = new int[size];
System.arraycopy(array, 0, a, 0, size);
return a;
}
/**
@ -311,8 +310,7 @@ final class BitMatrixParser {
* @return the codeword corresponding to the symbol.
*/
private static int getCodeword(long symbol) {
long sym = symbol;
sym &= 0x3ffff;
long sym = symbol & 0x3FFFF;
int i = findCodewordIndex(sym);
if (i == -1) {
return -1;

View file

@ -31,10 +31,10 @@ public final class Mode {
public static final Mode ALPHANUMERIC = new Mode(new int[]{9, 11, 13}, 0x02, "ALPHANUMERIC");
public static final Mode STRUCTURED_APPEND = new Mode(new int[]{0, 0, 0}, 0x03, "STRUCTURED_APPEND"); // Not supported
public static final Mode BYTE = new Mode(new int[]{8, 16, 16}, 0x04, "BYTE");
public static final Mode ECI = new Mode(null, 0x07, "ECI"); // character counts don't apply
public static final Mode ECI = new Mode(new int[]{0, 0, 0}, 0x07, "ECI"); // character counts don't apply
public static final Mode KANJI = new Mode(new int[]{8, 10, 12}, 0x08, "KANJI");
public static final Mode FNC1_FIRST_POSITION = new Mode(null, 0x05, "FNC1_FIRST_POSITION");
public static final Mode FNC1_SECOND_POSITION = new Mode(null, 0x09, "FNC1_SECOND_POSITION");
public static final Mode FNC1_FIRST_POSITION = new Mode(new int[]{0, 0, 0}, 0x05, "FNC1_FIRST_POSITION");
public static final Mode FNC1_SECOND_POSITION = new Mode(new int[]{0, 0, 0}, 0x09, "FNC1_SECOND_POSITION");
/** See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. */
public static final Mode HANZI = new Mode(new int[]{8, 10, 12}, 0x0D, "HANZI");

View file

@ -43,12 +43,12 @@ public final class ExpandedProductParsedResultTestCase extends Assert {
public void test_RSSExpanded() {
String text = "(01)66546(13)001205(3932)4455(3102)6544(123)544654";
String productID = "66546";
String sscc = "-";
String lotNumber = "-";
String productionDate = "-";
String sscc = null;
String lotNumber = null;
String productionDate = null;
String packagingDate = "001205";
String bestBeforeDate = "-";
String expirationDate = "-";
String bestBeforeDate = null;
String expirationDate = null;
String weight = "6544";
String weightType = "KG";
String weightIncrement = "2";

View file

@ -63,7 +63,9 @@ public final class RSSExpandedImage2resultTestCase extends Assert {
// (01)90012345678908(3103)001750
String path = "test/data/blackbox/rssexpanded-1/2.jpg";
ExpandedProductParsedResult expected =
new ExpandedProductParsedResult("90012345678908", "-", "-", "-", "-", "-", "-", "001750", ExpandedProductParsedResult.KILOGRAM, "3", "-", "-", "-", new Hashtable());
new ExpandedProductParsedResult("90012345678908", null, null, null, null, null, null,
"001750", ExpandedProductParsedResult.KILOGRAM, "3",
null, null, null, new Hashtable());
assertCorrectImage2result(path, expected);
}

View file

@ -38,18 +38,14 @@ public final class QRCodeWriterTestCase extends Assert {
private static final String BASE_IMAGE_PATH = "test/data/golden/qrcode/";
private static BufferedImage loadImage(String fileName) {
try {
File file = new File(BASE_IMAGE_PATH + fileName);
if (!file.exists()) {
// try starting with 'core' since the test base is often given as the project root
file = new File("core/" + BASE_IMAGE_PATH + fileName);
}
assertTrue("Please run from the 'core' directory", file.exists());
return ImageIO.read(file);
} catch (IOException e) {
return null;
private static BufferedImage loadImage(String fileName) throws IOException {
File file = new File(BASE_IMAGE_PATH + fileName);
if (!file.exists()) {
// try starting with 'core' since the test base is often given as the project root
file = new File("core/" + BASE_IMAGE_PATH + fileName);
}
assertTrue("Please run from the 'core' directory", file.exists());
return ImageIO.read(file);
}
// In case the golden images are not monochromatic, convert the RGB values to greyscale.
@ -104,7 +100,7 @@ public final class QRCodeWriterTestCase extends Assert {
}
private static void compareToGoldenFile(String contents, ErrorCorrectionLevel ecLevel,
int resolution, String fileName) throws WriterException {
int resolution, String fileName) throws WriterException, IOException {
BufferedImage image = loadImage(fileName);
assertNotNull(image);
@ -126,7 +122,7 @@ public final class QRCodeWriterTestCase extends Assert {
// and cell phones. We expect pixel-perfect results, because the error correction level is known,
// and the pixel dimensions matches exactly.
@Test
public void testRegressionTest() throws WriterException {
public void testRegressionTest() throws Exception {
compareToGoldenFile("http://www.google.com/", ErrorCorrectionLevel.M, 99,
"renderer-test-01.png");