-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
574497c
commit cc31ff1
Showing
3 changed files
with
154 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
barcode4j/src/test/java/org/krysalis/barcode4j/impl/codabar/CodabarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.krysalis.barcode4j.impl.codabar; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.krysalis.barcode4j.impl.MockClassicBarcodeLogicHandler; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author Samael Bate (singingbush) | ||
* created on 12/10/2024 | ||
*/ | ||
class CodabarTest { | ||
|
||
@Test | ||
void testBeanType() { | ||
final Codabar impl = new Codabar(); | ||
|
||
assertEquals(CodabarBean.class, impl.getCodabarBean().getClass()); | ||
} | ||
|
||
@Test | ||
void testIllegalArguments() { | ||
final Codabar impl = new Codabar(); | ||
|
||
// due to @NotNull on args, can be one of two exceptions depending on how tests are run | ||
assertThrows(RuntimeException.class, | ||
() -> impl.generateBarcode(null, null), | ||
"Expected a NullPointerException or IllegalArgumentException"); | ||
} | ||
|
||
@Test | ||
void testLogic() { | ||
final StringBuffer sb = new StringBuffer(); | ||
final CodabarLogicImpl logic = new CodabarLogicImpl(); | ||
logic.generateBarcodeLogic(new MockClassicBarcodeLogicHandler(sb), "123"); | ||
|
||
final String expected = "<BC>" + | ||
"<SBG:msg-char:1>B1W1B1W1B2W2B1</SBG>W1<SBG:msg-char:2>B1W1B1W2B1W1B2</SBG>W1<SBG:msg-char:3>B2W2B1W1B1W1B1</SBG>" + | ||
"</BC>"; | ||
|
||
assertEquals(expected, sb.toString()); | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
barcode4j/src/test/java/org/krysalis/barcode4j/impl/pdf417/PDF417Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.krysalis.barcode4j.impl.pdf417; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.krysalis.barcode4j.BarGroup; | ||
import org.krysalis.barcode4j.TwoDimBarcodeLogicHandler; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* @author Samael Bate (singingbush) | ||
* created on 12/10/2024 | ||
*/ | ||
class PDF417Test { | ||
|
||
@Test | ||
void testBeanType() { | ||
final PDF417 impl = new PDF417(); | ||
|
||
assertEquals(PDF417Bean.class, impl.getPDF417Bean().getClass()); | ||
} | ||
|
||
@Test | ||
void testIllegalArguments() { | ||
final PDF417 impl = new PDF417(); | ||
|
||
// due to @NotNull on args, can be one of two exceptions depending on how tests are run | ||
assertThrows(RuntimeException.class, | ||
() -> impl.generateBarcode(null, null), | ||
"Expected a NullPointerException or IllegalArgumentException"); | ||
} | ||
|
||
@Test | ||
void testLogic() { | ||
final PDF417Bean bean = new PDF417Bean(); | ||
final TwoDimBarcodeLogicHandler handler = new MockTwoDimBarcodeLogicHandler(); | ||
|
||
final PDF417LogicImpl logic = new PDF417LogicImpl(); | ||
logic.generateBarcodeLogic(handler, "123", bean); | ||
|
||
final String expected = "<BC>" + | ||
"<row><SBG:start-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:stop-char:null></SBG></row><row><SBG:start-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:stop-char:null></SBG></row><row><SBG:start-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:msg-char:null></SBG><SBG:stop-char:null></SBG></row>" + | ||
"</BC>"; | ||
|
||
assertEquals(expected, handler.toString()); | ||
} | ||
|
||
private static final class MockTwoDimBarcodeLogicHandler implements TwoDimBarcodeLogicHandler { | ||
private final StringBuffer sb; | ||
|
||
public MockTwoDimBarcodeLogicHandler() { | ||
this.sb = new StringBuffer(); | ||
} | ||
|
||
@Override | ||
public void startRow() { | ||
sb.append("<row>"); | ||
} | ||
|
||
@Override | ||
public void endRow() { | ||
sb.append("</row>"); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public void startBarGroup(BarGroup type, String submsg) { | ||
sb.append("<SBG:"); | ||
sb.append(type.getName()); | ||
sb.append(":"); | ||
sb.append(submsg); | ||
sb.append(">"); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public void addBar(boolean black, int weight) { | ||
// NO-OP | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public void endBarGroup() { | ||
sb.append("</SBG>"); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public void startBarcode(String msg, String formattedMsg) { | ||
sb.append("<BC>"); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public void endBarcode() { | ||
sb.append("</BC>"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return sb.toString(); | ||
} | ||
} | ||
|
||
} |