mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-01 00:00:02 -04:00
Compare commits
368 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fb443a768 | |||
| b302b4f0d1 | |||
| 29dcf83c47 | |||
| d54d84371d | |||
| 4de2a38dd8 | |||
| 5b4fa64dc0 | |||
| 2ad522a9fa | |||
| 20af575fbd | |||
| 02a6ed1ac1 | |||
| 146d5926bb | |||
| 561b25022c | |||
| 4cd6b893de | |||
| dabff3abce | |||
| 1b889b1b4b | |||
| 29a3bd591d | |||
| cd79ef4409 | |||
| a604cb83fb | |||
| eb1735ab33 | |||
| 357eeb2236 | |||
| d634b9d93f | |||
| 7e3241d64b | |||
| b86d82720d | |||
| 47e90a657a | |||
| bdd8b2f1fb | |||
| 8d08c9565b | |||
| c11f61d132 | |||
| e6b38cb547 | |||
| e11d888809 | |||
| 46a399ff02 | |||
| a09629be32 | |||
| 57fb1ca1bb | |||
| c9063ca02d | |||
| 340e79eb8a | |||
| 355a916225 | |||
| 8da45b5f05 | |||
| 6c8b0cdc2f | |||
| 8af219e669 | |||
| 7e10b9242d | |||
| 36103046a5 | |||
| 95787449ea | |||
| 3223743f2c | |||
| 234c7f59d4 | |||
| 1cb0da2967 | |||
| d1525828fa | |||
| 194fd5a446 | |||
| 21e5a465b9 | |||
| 6309bc5765 | |||
| 5011e98184 | |||
| a9aa5cc66e | |||
| ac107196eb | |||
| 489a419df1 | |||
| 51891b45ea | |||
| 90e60f509d | |||
| 53e5eff0c9 | |||
| 8670e1fd8a | |||
| 6395fd33e9 | |||
| 0834a2b1be | |||
| 6c75661ab4 | |||
| 9c25c962cc | |||
| 1328dbf763 | |||
| 8bccdef371 | |||
| 2d6f7d89fa | |||
| 1afa35ccd6 | |||
| 5b184a2a8a | |||
| 39bd218085 | |||
| 87af2f6212 | |||
| 598ea1e486 | |||
| 93180e7a2d | |||
| 2cc6d1d28e | |||
| 8ea9d6f318 | |||
| 029fa843f6 | |||
| 2cb4c0a661 | |||
| bf40c81123 | |||
| 78a90fab95 | |||
| b03f7a5582 | |||
| 96470c3897 | |||
| 365b19998f | |||
| b1846e1aed | |||
| ec63fbbd85 | |||
| fbea929bc5 | |||
| 18372944f1 | |||
| 488608b312 | |||
| b3ae8a8ba6 | |||
| fc3455d2c6 | |||
| f653279c62 | |||
| 0eff483d72 | |||
| 9c044b132b | |||
| 1ec4088e49 | |||
| 5ac415d019 | |||
| 133eafc8c2 | |||
| 85346a82e1 | |||
| e718e58b65 | |||
| 13a64ed3bb | |||
| 3c6df6ad1b | |||
| 9abe154ed3 | |||
| 0e752a2d2c | |||
| 867a46d281 | |||
| 9972f966f7 | |||
| f066a48d55 | |||
| 5af87372aa | |||
| defadbbbcd | |||
| 66363f8d09 | |||
| 1bef35daba | |||
| 0be5efc534 | |||
| 35da57dfcf | |||
| 5d09bb664e | |||
| 5590072cc7 | |||
| 31117c7cea | |||
| ae0899fe76 | |||
| df51ef340d | |||
| 71d8295042 | |||
| a8f77a9a45 | |||
| eb3176b447 | |||
| 20e308dd8f | |||
| 9fa9bc5fe0 | |||
| 4da3e2e441 | |||
| 4516d84e54 | |||
| a815e5f180 | |||
| 35658a888f | |||
| 6cd6b6113d | |||
| f8b919ee58 | |||
| 8989ba07d8 | |||
| bc38ec1034 | |||
| e37c1fbb50 | |||
| 75b6de7102 | |||
| 22a16db463 | |||
| 3e93753073 | |||
| ad3cbbd86d | |||
| 076e417010 | |||
| 0b84a99954 | |||
| e2f4241a99 | |||
| 6eedaa129d | |||
| f5dbc0c2f4 | |||
| 7d79185fb2 | |||
| c885ed6dbb | |||
| e116c98db2 | |||
| be9493af20 | |||
| 5ffe3087ad | |||
| ffc7dad821 | |||
| 2a4ff2aa12 | |||
| 1e9669d6c3 | |||
| caca51d5ce | |||
| 015728a57d | |||
| 4272c6c8ed | |||
| b5582e32f6 | |||
| 76045ab0d9 | |||
| 4fc8f28cc6 | |||
| 7198a92a2e | |||
| e2fbd80c36 | |||
| 6b28cbe4a1 | |||
| 76198b0655 | |||
| f81b14df71 | |||
| da3f79f0c9 | |||
| d39418eca2 | |||
| cbbc2bc6fe | |||
| b0b423de4f | |||
| 1c4ec8d20e | |||
| ec99a8ce1f | |||
| c49a887cd3 | |||
| 14af75d191 | |||
| 0ce205638e | |||
| fe4119ca1c | |||
| c927f4c1ec | |||
| 161368084a | |||
| d958aba69e | |||
| 931429724c | |||
| dcd21db2ef | |||
| 7a3022ebf2 | |||
| 274886b1d9 | |||
| 0cf784ee60 | |||
| a797f1ea26 | |||
| baff849b6c | |||
| 408977d896 | |||
| d78e6373a8 | |||
| 9610256ddb | |||
| 34c9b9b4b5 | |||
| 9d5823d982 | |||
| 10e824df36 | |||
| 3bc90bfad1 | |||
| 543acce8a3 | |||
| a67fdd4b80 | |||
| 9c936d3f11 | |||
| fb2bff1404 | |||
| 3c605f8796 | |||
| 7817af91a3 | |||
| 1ed1076714 | |||
| a90d375422 | |||
| 815007ab2b | |||
| b3c8f53512 | |||
| d2977a18ac | |||
| 7e5e905d18 | |||
| 0fcba279f1 | |||
| d7d9552216 | |||
| e48a78aa77 | |||
| bf351c01a6 | |||
| 9bd4389142 | |||
| 984383bd56 | |||
| 77247772d0 | |||
| ae482bc7e5 | |||
| 119700487b | |||
| 5e5d530498 | |||
| 3dfc0850cc | |||
| 8f285327fc | |||
| 734b90863a | |||
| 18f31f2dd4 | |||
| a7294af89c | |||
| ea63a5bdc1 | |||
| 2cc50bbdad | |||
| f4a5f57d52 | |||
| 7fc47a338c | |||
| f8311164af | |||
| 84c10ed96d | |||
| 9c8ae4ac3e | |||
| aab7b6f7f5 | |||
| 3c01071452 | |||
| 4fc9c3513b | |||
| 59b08bfc79 | |||
| 743f1f9356 | |||
| d90b1c984c | |||
| 1160be4995 | |||
| 2978c901ae | |||
| e4b465a0d4 | |||
| 297a27c5be | |||
| 9d9593dba2 | |||
| 66683a2ead | |||
| 4be4f4e2b6 | |||
| 7f59d41b2a | |||
| a060c105e1 | |||
| f3318ee818 | |||
| afa306a787 | |||
| ed032b6c7a | |||
| 894e5dc30a | |||
| 8e02fb36e9 | |||
| 88a2e226ca | |||
| 203ad0258f | |||
| 2a1ecf80fa | |||
| 4239ce5e31 | |||
| 61ca2fc3e0 | |||
| 9e502899ac | |||
| 16fd8d1453 | |||
| 81ae64b65c | |||
| b0d5480445 | |||
| 9e989680c6 | |||
| dd174c7f7e | |||
| 72ef50b677 | |||
| a7349278b2 | |||
| 858f519f0b | |||
| d797ff0bb3 | |||
| fef4c4dd7a | |||
| a99762b5de | |||
| c7d0c902db | |||
| e8e2026d48 | |||
| f1dc50c276 | |||
| 0e615192e7 | |||
| d9b82f80ef | |||
| 41f316e621 | |||
| 5f2b0c0ccf | |||
| ee7d4ba724 | |||
| f7d4557c57 | |||
| 20d8c34dae | |||
| eaee82f3e7 | |||
| a0d87ec6d8 | |||
| ac5d4a02a9 | |||
| a26932cd70 | |||
| 7b8e5433dd | |||
| 1471af3e68 | |||
| 4f0dd84cf6 | |||
| 143e25c39c | |||
| 3d0ba82422 | |||
| 34f626914a | |||
| d6587ad292 | |||
| 46eaa72a13 | |||
| b3d48bdc50 | |||
| 981d2da1e6 | |||
| cf40b5f4a0 | |||
| 34128c66a4 | |||
| 1aa02477a7 | |||
| fa49dd93a7 | |||
| 83cff35076 | |||
| 93e3ae5ef8 | |||
| d8857c2997 | |||
| 7b119ce7dc | |||
| 3e7ad05973 | |||
| 1e574ca429 | |||
| dce193b113 | |||
| 05517e1fed | |||
| d707793211 | |||
| 39cfeedc6b | |||
| 1dcbbc39e3 | |||
| c933dbf69f | |||
| 5fc7dc1963 | |||
| f42d5e0a32 | |||
| d1c3a9bacb | |||
| 21ad54b820 | |||
| e11fc63730 | |||
| 2a70e744e0 | |||
| 60550ba8a8 | |||
| d3b16cdd35 | |||
| add7b06fa4 | |||
| b99391854d | |||
| a22188bd72 | |||
| d5f5f295f5 | |||
| d95de31908 | |||
| 4fda5af141 | |||
| b54827ae1b | |||
| 2762b9705a | |||
| 2d6248e293 | |||
| 8a43e4539c | |||
| 8ecf203263 | |||
| 8e50af2804 | |||
| 58e31aebd1 | |||
| b8e3e7825c | |||
| 155e9850fb | |||
| 0c4adf36ba | |||
| fd32bc9089 | |||
| 6ad010dc44 | |||
| c9b14ea4af | |||
| f162c873ed | |||
| c21b971655 | |||
| d1b0247055 | |||
| 6d3605c080 | |||
| a188dcf9fd | |||
| 08938c6b4d | |||
| 016ef952ce | |||
| 2844c396c8 | |||
| 2f95716b8a | |||
| cf7fce647d | |||
| 4014ae4644 | |||
| 4e46e81e3f | |||
| ec43410fa6 | |||
| 721fc5b5a5 | |||
| 0c71981158 | |||
| ac0ed5ed8f | |||
| d1b11ee1d1 | |||
| 210eeccb39 | |||
| e07e7c3685 | |||
| 611cb6cb4d | |||
| 54d9feef94 | |||
| 54b4ded602 | |||
| e360ed2a6a | |||
| 2325cef5a3 | |||
| 465eb09dd3 | |||
| feae2a0f79 | |||
| 860cb32a58 | |||
| b9bd19b950 | |||
| 3742e6ef08 | |||
| 52aa582ccd | |||
| adda52053b | |||
| 6501321fac | |||
| 57d9bfda59 | |||
| 1226375ba6 | |||
| 9c2d3058fd | |||
| e89cadd95f | |||
| 0ec299c2e6 | |||
| b91d02a562 | |||
| 2b5f897841 | |||
| e65078bdb7 | |||
| 36d8555172 | |||
| 80e3170820 | |||
| 90bc04b030 | |||
| dcba9b0667 | |||
| dc755c4c3c | |||
| 6e4f1e0739 | |||
| 7117cd1fd6 | |||
| 2b954c1067 | |||
| 77a1745106 | |||
| 0378f504e7 | |||
| 1d3a7fe812 |
@@ -5,9 +5,13 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
cooldown:
|
||||
default-days: 7
|
||||
open-pull-requests-limit: 10
|
||||
# GitHub actions updates
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/.github/workflows"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
cooldown:
|
||||
default-days: 7
|
||||
|
||||
+59
-18
@@ -17,13 +17,16 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
java: [ 8, 11, 17, 21 ]
|
||||
java: [ 8, 11, 17, 21, 25 ]
|
||||
exclude:
|
||||
- os: macos-latest
|
||||
java: 8
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
checks: write
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
@@ -32,13 +35,35 @@ jobs:
|
||||
- name: Run Tests
|
||||
run: mvn --batch-mode --no-transfer-progress test
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@0831a82caad2465c31c6dd929978f640cb42556c # v4.0.3
|
||||
uses: mikepenz/action-junit-report@74626db7353a25a20a72816467ebf035f674c5f8 # v5
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
report_paths: "**/target/surefire-reports/TEST*.xml"
|
||||
check_name: Unit Test Results for OpenJDK ${{ matrix.java }} on ${{ matrix.os }}
|
||||
|
||||
test_oracle:
|
||||
test-jdk8-macos:
|
||||
name: Test OpenJDK 8 on macos-14
|
||||
runs-on: macos-14
|
||||
permissions:
|
||||
checks: write
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '8'
|
||||
java-package: jdk
|
||||
cache: 'maven'
|
||||
- name: Run Tests
|
||||
run: mvn --batch-mode --no-transfer-progress test
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@74626db7353a25a20a72816467ebf035f674c5f8 # v5
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
report_paths: "**/target/surefire-reports/TEST*.xml"
|
||||
check_name: Unit Test Results for OpenJDK ${{ matrix.java }} on ${{ matrix.os }}
|
||||
|
||||
test-oracle:
|
||||
name: Test Oracle JDK 8 with KCMS=${{ matrix.kcms }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
@@ -47,11 +72,11 @@ jobs:
|
||||
matrix:
|
||||
kcms: [ true, false ]
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- run: |
|
||||
download_url="https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245038_d3c52aa6bfa54d3ca74e617f18309292"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
|
||||
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
@@ -66,37 +91,53 @@ jobs:
|
||||
- name: Run Tests
|
||||
run: mvn --batch-mode --no-transfer-progress test
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@0831a82caad2465c31c6dd929978f640cb42556c # v4.0.3
|
||||
uses: mikepenz/action-junit-report@74626db7353a25a20a72816467ebf035f674c5f8 # v5
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
report_paths: "**/target/surefire-reports/TEST*.xml"
|
||||
check_name: Unit Test Results for Oracle JDK 8 with KCMS=${{ matrix.kcms }}
|
||||
|
||||
javadoc:
|
||||
name: Build JavaDoc on OpenJDK ${{ matrix.java }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [8, 11, 25 ] # We only need a few versions here
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
java-package: jdk
|
||||
cache: 'maven'
|
||||
- name: Create JavaDoc
|
||||
run: mvn --batch-mode --no-transfer-progress -DskipTests package javadoc:javadoc
|
||||
|
||||
release:
|
||||
name: Deploy
|
||||
needs: [ test, test_oracle ]
|
||||
needs: [ test, test-jdk8-macos, test-oracle, javadoc ]
|
||||
if: github.ref == 'refs/heads/master' # only perform on latest master
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Set up Maven Central
|
||||
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
|
||||
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
||||
with: # running setup-java again overwrites the settings.xml
|
||||
distribution: 'temurin'
|
||||
java-version: '8'
|
||||
java-package: jdk
|
||||
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-id: central # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_CENTRAL_USERNAME # env variable for username in deploy (1)
|
||||
server-password: MAVEN_CENTRAL_PASSWORD # env variable for token in deploy (2)
|
||||
gpg-private-key: ${{ secrets.GPG_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_CENTRAL_GPG_PASSPHRASE # env variable for GPG private key passphrase (3)
|
||||
- name: Get Project Version
|
||||
run: |
|
||||
echo "PROJECT_VERSION=$(mvn --batch-mode help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
|
||||
- name: Publish to Maven Central
|
||||
if: ${{ endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }}
|
||||
run: mvn --batch-mode --no-transfer-progress deploy -P release -DskipTests
|
||||
run: mvn --batch-mode --no-transfer-progress deploy -P release -DskipTests -Dgpg.signer=bc
|
||||
env:
|
||||
MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} # must be the same env variable name as (1)
|
||||
MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} # must be the same env variable name as (2)
|
||||
MAVEN_CENTRAL_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} # must be the same env variable name as (3)
|
||||
MAVEN_CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} # must be the same env variable name as (1)
|
||||
MAVEN_CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} # must be the same env variable name as (2)
|
||||
MAVEN_GPG_KEY: ${{ secrets.GPG_KEY }} # Value of the GPG private key to import
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
|
||||
|
||||
@@ -33,11 +33,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
|
||||
uses: github/codeql-action/init@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
|
||||
uses: github/codeql-action/autobuild@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
@@ -64,6 +64,6 @@ jobs:
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
|
||||
uses: github/codeql-action/analyze@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
|
||||
@@ -26,12 +26,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
|
||||
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
|
||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -57,6 +57,6 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
|
||||
uses: github/codeql-action/upload-sarif@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[](https://www.bestpractices.dev/projects/7900)
|
||||
|
||||
[](https://search.maven.org/search?q=g:com.twelvemonkeys.imageio)
|
||||
[](https://oss.sonatype.org/content/repositories/snapshots/com/twelvemonkeys/)
|
||||
[](https://central.sonatype.com/repository/maven-snapshots/com/twelvemonkeys/imageio/imageio/maven-metadata.xml)
|
||||
[](https://stackoverflow.com/questions/tagged/twelvemonkeys)
|
||||
[](https://paypal.me/haraldk76/100)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
TwelveMonkeys ImageIO provides extended image file format support for the Java platform, through plugins for the `javax.imageio.*` package.
|
||||
|
||||
The main goal of this project is to provide support for formats not covered by the JRE itself.
|
||||
The main goal of this project is to provide support for file formats not covered by the JDK.
|
||||
Support for these formats is important, to be able to read data found
|
||||
"in the wild", as well as to maintain access to data in legacy formats.
|
||||
As there is lots of legacy data out there, we see the need for open implementations of readers for popular formats.
|
||||
@@ -29,7 +29,8 @@ As there is lots of legacy data out there, we see the need for open implementati
|
||||
| | WMF | MS Windows Metafile | âś” | - | - | Requires [Batik](https://xmlgraphics.apache.org/batik/) |
|
||||
| [BMP](https://github.com/haraldk/TwelveMonkeys/wiki/BMP-Plugin) | **BMP** | MS Windows and IBM OS/2 Device Independent Bitmap | âś” | âś” | [Native](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/bmp_metadata.html), [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
||||
| | CUR | MS Windows Cursor Format | âś” | - | - |
|
||||
| | ICO | MS Windows Icon Format | âś” | âś” | - |
|
||||
| | ICO | MS Windows Icon Format | âś” | âś” | - |
|
||||
| [DDS](https://github.com/haraldk/TwelveMonkeys/wiki/DDS-Plugin) | DDS | MS Direct Draw Surface Format | âś” | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
||||
| [HDR](https://github.com/haraldk/TwelveMonkeys/wiki/HDR-Plugin) | HDR | Radiance High Dynamic Range RGBE Format | âś” | - | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
||||
| [ICNS](https://github.com/haraldk/TwelveMonkeys/wiki/ICNS-Plugin) | ICNS | Apple Icon Image | âś” | âś” | - |
|
||||
| [IFF](https://github.com/haraldk/TwelveMonkeys/wiki/IFF-Plugin) | IFF | Commodore Amiga/Electronic Arts Interchange File Format | âś” | âś” | [Standard](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html) |
|
||||
@@ -222,6 +223,43 @@ BufferedImageOp ditherer = new DiffusionDither();
|
||||
BufferedImage output = ditherer.filter(input, null);
|
||||
```
|
||||
|
||||
#### Working with damaged images
|
||||
|
||||
When using the normal patterns for loading images, trying to load a damaged image will result in an `IOException` being thrown.
|
||||
|
||||
```java
|
||||
BufferedImage image = null;
|
||||
try {
|
||||
image = ImageIO.read(file);
|
||||
} catch (IOException exception) {
|
||||
// Handle, log a warning/error etc
|
||||
}
|
||||
```
|
||||
|
||||
In this scenario, if the image is damaged, and `ImageIO.read` throws an exception, `image` is still `null` - it's not possible for a function to both return a value and throw an exception.
|
||||
|
||||
However, in some cases it may be possible to get usable image data from a damaged image. The way to do this is use an `ImageReadParam` to set a `BufferedImage` as a destination.
|
||||
|
||||
```java
|
||||
int width = reader.getWidth(0);
|
||||
int height = reader.getHeight(0);
|
||||
ImageTypeSpecifier imageType = reader.getRawImageType(0);
|
||||
BufferedImage image = imageType.createBufferedImage(width, height);
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setDestination(image);
|
||||
|
||||
try {
|
||||
reader.read(0, param);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Handle, log a warning/error etc
|
||||
}
|
||||
```
|
||||
|
||||
In theory this should work for all plugins, but the result is very much plugin/implementation specific. With some formats and some forms of damaged file, you may get an image that is mostly useful.
|
||||
However, you should be prepared for the possibility this just gives a blank or empty image.
|
||||
|
||||
## Building
|
||||
|
||||
Download the project (using [Git](https://git-scm.com/downloads)):
|
||||
@@ -278,12 +316,12 @@ To depend on the JPEG and TIFF plugin using Maven, add the following to your POM
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-jpeg</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-tiff</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
@@ -293,7 +331,7 @@ To depend on the JPEG and TIFF plugin using Maven, add the following to your POM
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||
<artifactId>servlet</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
@@ -302,7 +340,7 @@ To depend on the JPEG and TIFF plugin using Maven, add the following to your POM
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||
<artifactId>servlet</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.13.1</version>
|
||||
<classifier>jakarta</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -312,18 +350,18 @@ To depend on the JPEG and TIFF plugin using Maven, add the following to your POM
|
||||
|
||||
To depend on the JPEG and TIFF plugin in your IDE or program, add all of the following JARs to your class path:
|
||||
|
||||
twelvemonkeys-common-lang-3.10.1.jar
|
||||
twelvemonkeys-common-io-3.10.1.jar
|
||||
twelvemonkeys-common-image-3.10.1.jar
|
||||
twelvemonkeys-imageio-core-3.10.1.jar
|
||||
twelvemonkeys-imageio-metadata-3.10.1.jar
|
||||
twelvemonkeys-imageio-jpeg-3.10.1.jar
|
||||
twelvemonkeys-imageio-tiff-3.10.1.jar
|
||||
twelvemonkeys-common-lang-3.13.1.jar
|
||||
twelvemonkeys-common-io-3.13.1.jar
|
||||
twelvemonkeys-common-image-3.13.1.jar
|
||||
twelvemonkeys-imageio-core-3.13.1.jar
|
||||
twelvemonkeys-imageio-metadata-3.13.1.jar
|
||||
twelvemonkeys-imageio-jpeg-3.13.1.jar
|
||||
twelvemonkeys-imageio-tiff-3.13.1.jar
|
||||
|
||||
#### Deploying the plugins in a web app
|
||||
|
||||
Because the `ImageIO` plugin registry (the `IIORegistry`) is "VM global", it doesn't by default work well with
|
||||
servlet contexts. This is especially evident if you load plugins from the `WEB-INF/lib` or `classes` folder.
|
||||
Because the `ImageIO` plugin registry (the `IIORegistry`) is "VM global", it does not work well with
|
||||
servlet contexts as-is. This is especially evident if you load plugins from the `WEB-INF/lib` or `classes` folder.
|
||||
Unless you add `ImageIO.scanForPlugins()` somewhere in your code, the plugins might never be available at all.
|
||||
|
||||
In addition, servlet contexts dynamically loads and unloads classes (using a new class loader per context).
|
||||
@@ -359,6 +397,16 @@ or other ImageIO plugins as well.
|
||||
|
||||
Another safe option, is to place the JAR files in the application server's shared or common lib folder.
|
||||
|
||||
##### Jakarta Servlet Support
|
||||
|
||||
For those transitioning from the old `javax.servlet` to the new `jakarta.servlet` package, there is a separate
|
||||
dependency available. It contains exactly the same servlet classes as mentioned above, but built against the new Jakarta EE
|
||||
packages. The dependency has the same group name and identifier as before, but a `jakarta` *classifier* appended, to
|
||||
distinguish it from the non-Jakarta package.
|
||||
|
||||
See the [Maven dependency example](#maven-dependency-example) for how to enable it with Maven.
|
||||
Gradle or other build tools will have similar options.
|
||||
|
||||
#### Including the plugins in a "fat" JAR
|
||||
|
||||
The recommended way to use the plugins, is just to include the JARs as-is in your project, through a Maven dependency or similar.
|
||||
@@ -384,44 +432,46 @@ Other "fat" JAR bundlers will probably have similar mechanisms to merge entries
|
||||
|
||||
### Links to prebuilt binaries
|
||||
|
||||
##### Latest version (3.10.1)
|
||||
##### Latest version (3.13.1)
|
||||
|
||||
The latest version that will run on Java 7 is 3.9.4. Later versions will require Java 8 or later.
|
||||
|
||||
Common dependencies
|
||||
* [common-lang-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.10.1/common-lang-3.10.1.jar)
|
||||
* [common-io-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.10.1/common-io-3.10.1.jar)
|
||||
* [common-image-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.10.1/common-image-3.10.1.jar)
|
||||
* [common-lang-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-lang/3.13.1/common-lang-3.13.1.jar)
|
||||
* [common-io-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-io/3.13.1/common-io-3.13.1.jar)
|
||||
* [common-image-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/common/common-image/3.13.1/common-image-3.13.1.jar)
|
||||
|
||||
ImageIO dependencies
|
||||
* [imageio-core-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.10.1/imageio-core-3.10.1.jar)
|
||||
* [imageio-metadata-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.10.1/imageio-metadata-3.10.1.jar)
|
||||
* [imageio-core-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-core/3.13.1/imageio-core-3.13.1.jar)
|
||||
* [imageio-metadata-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-metadata/3.13.1/imageio-metadata-3.13.1.jar)
|
||||
|
||||
ImageIO plugins
|
||||
* [imageio-bmp-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-bmp/3.10.1/imageio-bmp-3.10.1.jar)
|
||||
* [imageio-hdr-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-hdr/3.10.1/imageio-hdr-3.10.1.jar)
|
||||
* [imageio-icns-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.10.1/imageio-icns-3.10.1.jar)
|
||||
* [imageio-iff-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.10.1/imageio-iff-3.10.1.jar)
|
||||
* [imageio-jpeg-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.10.1/imageio-jpeg-3.10.1.jar)
|
||||
* [imageio-pcx-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pcx/3.10.1/imageio-pcx-3.10.1.jar)
|
||||
* [imageio-pict-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.10.1/imageio-pict-3.10.1.jar)
|
||||
* [imageio-pnm-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pnm/3.10.1/imageio-pnm-3.10.1.jar)
|
||||
* [imageio-psd-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.10.1/imageio-psd-3.10.1.jar)
|
||||
* [imageio-sgi-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-sgi/3.10.1/imageio-sgi-3.10.1.jar)
|
||||
* [imageio-tga-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tga/3.10.1/imageio-tga-3.10.1.jar)
|
||||
* [imageio-thumbsdb-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.10.1/imageio-thumbsdb-3.10.1.jar)
|
||||
* [imageio-tiff-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.10.1/imageio-tiff-3.10.1.jar)
|
||||
* [imageio-webp-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-webp/3.10.1/imageio-webp-3.10.1.jar)
|
||||
* [imageio-xwd-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-xwd/3.10.1/imageio-xwd-3.10.1.jar)
|
||||
* [imageio-bmp-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-bmp/3.13.1/imageio-bmp-3.13.1.jar)
|
||||
* [imageio-dds-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-dds/3.13.1/imageio-dds-3.13.1.jar)
|
||||
* [imageio-hdr-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-hdr/3.13.1/imageio-hdr-3.13.1.jar)
|
||||
* [imageio-icns-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-icns/3.13.1/imageio-icns-3.13.1.jar)
|
||||
* [imageio-iff-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-iff/3.13.1/imageio-iff-3.13.1.jar)
|
||||
* [imageio-jpeg-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-jpeg/3.13.1/imageio-jpeg-3.13.1.jar)
|
||||
* [imageio-pcx-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pcx/3.13.1/imageio-pcx-3.13.1.jar)
|
||||
* [imageio-pict-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pict/3.13.1/imageio-pict-3.13.1.jar)
|
||||
* [imageio-pnm-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-pnm/3.13.1/imageio-pnm-3.13.1.jar)
|
||||
* [imageio-psd-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-psd/3.13.1/imageio-psd-3.13.1.jar)
|
||||
* [imageio-sgi-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-sgi/3.13.1/imageio-sgi-3.13.1.jar)
|
||||
* [imageio-tga-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tga/3.13.1/imageio-tga-3.13.1.jar)
|
||||
* [imageio-thumbsdb-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-thumbsdb/3.13.1/imageio-thumbsdb-3.13.1.jar)
|
||||
* [imageio-tiff-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-tiff/3.13.1/imageio-tiff-3.13.1.jar)
|
||||
* [imageio-webp-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-webp/3.13.1/imageio-webp-3.13.1.jar)
|
||||
* [imageio-xwd-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-xwd/3.13.1/imageio-xwd-3.13.1.jar)
|
||||
|
||||
ImageIO plugins requiring 3rd party libs
|
||||
* [imageio-batik-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.10.1/imageio-batik-3.10.1.jar)
|
||||
* [imageio-batik-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-batik/3.13.1/imageio-batik-3.13.1.jar)
|
||||
|
||||
Photoshop Path support for ImageIO
|
||||
* [imageio-clippath-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-clippath/3.10.1/imageio-clippath-3.10.1.jar)
|
||||
* [imageio-clippath-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/imageio/imageio-clippath/3.13.1/imageio-clippath-3.13.1.jar)
|
||||
|
||||
Servlet support
|
||||
* [servlet-3.10.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.10.1/servlet-3.10.1.jar)
|
||||
* [servlet-3.13.1.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.13.1/servlet-3.13.1.jar) for legacy Java EE (javax.servlet)
|
||||
* [servlet-3.13.1-jakarta.jar](https://search.maven.org/remotecontent?filepath=com/twelvemonkeys/servlet/servlet/3.13.1/servlet-3.13.1-jakrta.jar) for Jakarta EE (jakarta.servlet)
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+6
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys</groupId>
|
||||
<artifactId>twelvemonkeys</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.twelvemonkeys.bom</groupId>
|
||||
@@ -63,6 +63,11 @@
|
||||
<artifactId>imageio-hdr</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-dds</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-icns</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.common</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>common-image</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -28,13 +28,6 @@
|
||||
<artifactId>common-io</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jmagick</groupId>
|
||||
<artifactId>jmagick</artifactId>
|
||||
<version>6.6.9</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -47,10 +47,10 @@ import java.util.Random;
|
||||
* |3|5|1|
|
||||
* - - -->
|
||||
* </p>
|
||||
* <table border="1" cellpadding="4" cellspacing="0">
|
||||
* <table border="1">
|
||||
* <caption>Floyd-Steinberg error-diffusion weights</caption>
|
||||
* <tr><td bgcolor="#000000"> </td><td class="TableHeadingColor"
|
||||
* align="center">x</td><td>7/16</td></tr>
|
||||
* <tr><td style="background:#000000"> </td><td class="TableHeadingColor"
|
||||
* style="text-align:center">x</td><td>7/16</td></tr>
|
||||
* <tr><td>3/16</td><td>5/16</td><td>1/16</td></tr>
|
||||
* </table>
|
||||
* <p>
|
||||
|
||||
@@ -162,7 +162,7 @@ public final class ImageUtil {
|
||||
|
||||
/**
|
||||
* The sharpen kernel. Uses the following 3 by 3 matrix:
|
||||
* <table border="1" cellspacing="0">
|
||||
* <table border="1">
|
||||
* <caption>Sharpen Kernel Matrix</caption>
|
||||
* <tr><td>0.0</td><td>-0.3</td><td>0.0</td></tr>
|
||||
* <tr><td>-0.3</td><td>2.2</td><td>-0.3</td></tr>
|
||||
@@ -1078,7 +1078,7 @@ public final class ImageUtil {
|
||||
/**
|
||||
* Sharpens an image using a convolution matrix.
|
||||
* The sharpen kernel used, is defined by the following 3 by 3 matrix:
|
||||
* <table border="1" cellspacing="0">
|
||||
* <table border="1">
|
||||
* <caption>Sharpen Kernel Matrix</caption>
|
||||
* <tr><td>0.0</td><td>-0.3</td><td>0.0</td></tr>
|
||||
* <tr><td>-0.3</td><td>2.2</td><td>-0.3</td></tr>
|
||||
@@ -1100,7 +1100,7 @@ public final class ImageUtil {
|
||||
/**
|
||||
* Sharpens an image using a convolution matrix.
|
||||
* The sharpen kernel used, is defined by the following 3 by 3 matrix:
|
||||
* <table border="1" cellspacing="0">
|
||||
* <table border="1">
|
||||
* <caption>Sharpen Kernel Matrix</caption>
|
||||
* <tr><td>0.0</td><td>-{@code pAmount}</td><td>0.0</td></tr>
|
||||
* <tr><td>-{@code pAmount}</td>
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import com.twelvemonkeys.lang.SystemUtil;
|
||||
import magick.MagickImage;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
|
||||
/**
|
||||
* This class accelerates certain graphics operations, using
|
||||
* JMagick and ImageMagick, if available.
|
||||
* If those libraries are not installed, this class silently does nothing.
|
||||
* <p>
|
||||
* Set the system property {@code "com.twelvemonkeys.image.accel"} to
|
||||
* {@code false}, to disable, even if JMagick is installed.
|
||||
* Set the system property {@code "com.twelvemonkeys.image.magick.debug"} to
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/MagickAccelerator.java#3 $
|
||||
*/
|
||||
final class MagickAccelerator {
|
||||
|
||||
private static final boolean DEBUG = Magick.DEBUG;
|
||||
private static final boolean USE_MAGICK = useMagick();
|
||||
|
||||
private static final int RESAMPLE_OP = 0;
|
||||
|
||||
private static Class[] nativeOp = new Class[1];
|
||||
|
||||
static {
|
||||
try {
|
||||
nativeOp[RESAMPLE_OP] = Class.forName("com.twelvemonkeys.image.ResampleOp");
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
System.err.println("Could not find class: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean useMagick() {
|
||||
try {
|
||||
boolean available = SystemUtil.isClassAvailable("magick.MagickImage");
|
||||
|
||||
if (DEBUG && !available) {
|
||||
System.err.print("ImageMagick bindings not available.");
|
||||
}
|
||||
|
||||
boolean useMagick =
|
||||
available && !"FALSE".equalsIgnoreCase(System.getProperty("com.twelvemonkeys.image.accel"));
|
||||
|
||||
if (DEBUG) {
|
||||
System.err.println(
|
||||
useMagick
|
||||
? "Will use ImageMagick bindings to accelerate image resampling operations."
|
||||
: "Will not use ImageMagick to accelerate image resampling operations."
|
||||
);
|
||||
}
|
||||
|
||||
return useMagick;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// Most probably in case of a SecurityManager
|
||||
System.err.println("Could not enable ImageMagick bindings: " + t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getNativeOpIndex(Class pOpClass) {
|
||||
for (int i = 0; i < nativeOp.length; i++) {
|
||||
if (pOpClass == nativeOp[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static BufferedImage filter(BufferedImageOp pOperation, BufferedImage pInput, BufferedImage pOutput) {
|
||||
if (!USE_MAGICK) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BufferedImage result = null;
|
||||
switch (getNativeOpIndex(pOperation.getClass())) {
|
||||
case RESAMPLE_OP:
|
||||
ResampleOp resample = (ResampleOp) pOperation;
|
||||
result = resampleMagick(pInput, resample.width, resample.height, resample.filterType);
|
||||
|
||||
// NOTE: If output parameter is non-null, we have to return that
|
||||
// image, instead of result
|
||||
if (pOutput != null) {
|
||||
//pOutput.setData(result.getRaster()); // Fast, but less compatible
|
||||
// NOTE: For some reason, this is sometimes super-slow...?
|
||||
ImageUtil.drawOnto(pOutput, result);
|
||||
result = pOutput;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// Simply fall through, allowing acceleration to be added later
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BufferedImage resampleMagick(BufferedImage pSrc, int pWidth, int pHeight, int pFilterType) {
|
||||
// Convert to Magick, scale and convert back
|
||||
MagickImage image = null;
|
||||
MagickImage scaled = null;
|
||||
try {
|
||||
image = MagickUtil.toMagick(pSrc);
|
||||
|
||||
long start = 0;
|
||||
if (DEBUG) {
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// NOTE: setFilter affects zoomImage, NOT scaleImage
|
||||
image.setFilter(pFilterType);
|
||||
scaled = image.zoomImage(pWidth, pHeight);
|
||||
//scaled = image.scaleImage(pWidth, pHeight); // AREA_AVERAGING
|
||||
|
||||
if (DEBUG) {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
System.out.println("Filtered: " + time + " ms");
|
||||
}
|
||||
|
||||
return MagickUtil.toBuffered(scaled);
|
||||
}
|
||||
//catch (MagickException e) {
|
||||
catch (Exception e) {
|
||||
// NOTE: Stupid workaround: If MagickException is caught, a
|
||||
// NoClassDefFoundError is thrown, when MagickException class is
|
||||
// unavailable...
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
|
||||
throw new ImageConversionException(e.getMessage(), e);
|
||||
}
|
||||
finally {
|
||||
// NOTE: ImageMagick might be unstable after a while, if image data
|
||||
// is not deallocated. The GC/finalize method handles this, but in
|
||||
// special circumstances, it's not triggered often enough.
|
||||
if (image != null) {
|
||||
image.destroyImages();
|
||||
}
|
||||
if (scaled != null) {
|
||||
scaled.destroyImages();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,621 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Harald Kuhr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import magick.ImageType;
|
||||
import magick.MagickException;
|
||||
import magick.MagickImage;
|
||||
import magick.PixelPacket;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
* Utility for converting JMagick {@code MagickImage}s to standard Java
|
||||
* {@code BufferedImage}s and back.
|
||||
* <p>
|
||||
* <em>NOTE: This class is considered an implementation detail and not part of
|
||||
* the public API. This class is subject to change without further notice.
|
||||
* You have been warned. :-)</em>
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/MagickUtil.java#4 $
|
||||
*/
|
||||
public final class MagickUtil {
|
||||
// IMPORTANT NOTE: Disaster happens if any of these constants are used outside this class
|
||||
// because you then have a dependency on MagickException (this is due to Java class loading
|
||||
// and initialization magic).
|
||||
// Do not use outside this class. If the constants need to be shared, move to Magick or ImageUtil.
|
||||
|
||||
/** Color Model usesd for bilevel (B/W) */
|
||||
private static final IndexColorModel CM_MONOCHROME = MonochromeColorModel.getInstance();
|
||||
|
||||
/** Color Model usesd for raw ABGR */
|
||||
private static final ColorModel CM_COLOR_ALPHA =
|
||||
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8, 8},
|
||||
true, true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
|
||||
|
||||
/** Color Model usesd for raw BGR */
|
||||
private static final ColorModel CM_COLOR_OPAQUE =
|
||||
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8},
|
||||
false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
|
||||
|
||||
/** Color Model usesd for raw RGB */
|
||||
//private static final ColorModel CM_COLOR_RGB = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
|
||||
|
||||
/** Color Model usesd for raw GRAY + ALPHA */
|
||||
private static final ColorModel CM_GRAY_ALPHA =
|
||||
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
|
||||
true, true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
|
||||
|
||||
/** Color Model usesd for raw GRAY */
|
||||
private static final ColorModel CM_GRAY_OPAQUE =
|
||||
new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
|
||||
false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
|
||||
|
||||
/** Band offsets for raw ABGR */
|
||||
private static final int[] BAND_OFF_TRANS = new int[] {3, 2, 1, 0};
|
||||
|
||||
/** Band offsets for raw BGR */
|
||||
private static final int[] BAND_OFF_OPAQUE = new int[] {2, 1, 0};
|
||||
|
||||
/** The point at {@code 0, 0} */
|
||||
private static final Point LOCATION_UPPER_LEFT = new Point(0, 0);
|
||||
|
||||
private static final boolean DEBUG = Magick.DEBUG;
|
||||
|
||||
// Only static members and methods
|
||||
private MagickUtil() {}
|
||||
|
||||
/**
|
||||
* Converts a {@code MagickImage} to a {@code BufferedImage}.
|
||||
* <p>
|
||||
* The conversion depends on {@code pImage}'s {@code ImageType}:
|
||||
* </p>
|
||||
* <dl>
|
||||
* <dt>{@code ImageType.BilevelType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_BYTE_BINARY}</dd>
|
||||
*
|
||||
* <dt>{@code ImageType.GrayscaleType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_BYTE_GRAY}</dd>
|
||||
* <dt>{@code ImageType.GrayscaleMatteType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_USHORT_GRAY}</dd>
|
||||
*
|
||||
* <dt>{@code ImageType.PaletteType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_BYTE_BINARY} (for images
|
||||
* with a palette of <= 16 colors) or {@code TYPE_BYTE_INDEXED}</dd>
|
||||
* <dt>{@code ImageType.PaletteMatteType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_BYTE_BINARY} (for images
|
||||
* with a palette of <= 16 colors) or {@code TYPE_BYTE_INDEXED}</dd>
|
||||
*
|
||||
* <dt>{@code ImageType.TrueColorType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_3BYTE_BGR}</dd>
|
||||
* <dt>{@code ImageType.TrueColorPaletteType}</dt>
|
||||
* <dd>{@code BufferedImage} of type {@code TYPE_4BYTE_ABGR}</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws IllegalArgumentException if {@code pImage} is {@code null}
|
||||
* or if the {@code ImageType} is not one mentioned above.
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
public static BufferedImage toBuffered(MagickImage pImage) throws MagickException {
|
||||
if (pImage == null) {
|
||||
throw new IllegalArgumentException("image == null");
|
||||
}
|
||||
|
||||
long start = 0L;
|
||||
if (DEBUG) {
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
BufferedImage image = null;
|
||||
try {
|
||||
switch (pImage.getImageType()) {
|
||||
case ImageType.BilevelType:
|
||||
image = bilevelToBuffered(pImage);
|
||||
break;
|
||||
case ImageType.GrayscaleType:
|
||||
image = grayToBuffered(pImage, false);
|
||||
break;
|
||||
case ImageType.GrayscaleMatteType:
|
||||
image = grayToBuffered(pImage, true);
|
||||
break;
|
||||
case ImageType.PaletteType:
|
||||
image = paletteToBuffered(pImage, false);
|
||||
break;
|
||||
case ImageType.PaletteMatteType:
|
||||
image = paletteToBuffered(pImage, true);
|
||||
break;
|
||||
case ImageType.TrueColorType:
|
||||
image = rgbToBuffered(pImage, false);
|
||||
break;
|
||||
case ImageType.TrueColorMatteType:
|
||||
image = rgbToBuffered(pImage, true);
|
||||
break;
|
||||
case ImageType.ColorSeparationType:
|
||||
image = cmykToBuffered(pImage, false);
|
||||
break;
|
||||
case ImageType.ColorSeparationMatteType:
|
||||
image = cmykToBuffered(pImage, true);
|
||||
break;
|
||||
case ImageType.OptimizeType:
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown JMagick image type: " + pImage.getImageType());
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
if (DEBUG) {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
System.out.println("Converted JMagick image type: " + pImage.getImageType() + " to BufferedImage: " + image);
|
||||
System.out.println("Conversion to BufferedImage: " + time + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@code BufferedImage} to a {@code MagickImage}.
|
||||
* <p>
|
||||
* The conversion depends on {@code pImage}'s {@code ColorModel}:
|
||||
* </p>
|
||||
* <dl>
|
||||
* <dt>{@code IndexColorModel} with 1 bit b/w</dt>
|
||||
* <dd>{@code MagickImage} of type {@code ImageType.BilevelType}</dd>
|
||||
* <dt>{@code IndexColorModel} > 1 bit,</dt>
|
||||
* <dd>{@code MagickImage} of type {@code ImageType.PaletteType}
|
||||
* or {@code MagickImage} of type {@code ImageType.PaletteMatteType}
|
||||
* depending on <tt>ColorModel.getAlpha()</tt></dd>
|
||||
*
|
||||
* <dt>{@code ColorModel.getColorSpace().getType() == ColorSpace.TYPE_GRAY}</dt>
|
||||
* <dd>{@code MagickImage} of type {@code ImageType.GrayscaleType}
|
||||
* or {@code MagickImage} of type {@code ImageType.GrayscaleMatteType}
|
||||
* depending on <tt>ColorModel.getAlpha()</tt></dd>
|
||||
*
|
||||
* <dt>{@code ColorModel.getColorSpace().getType() == ColorSpace.TYPE_RGB}</dt>
|
||||
* <dd>{@code MagickImage} of type {@code ImageType.TrueColorType}
|
||||
* or {@code MagickImage} of type {@code ImageType.TrueColorPaletteType}</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @param pImage the original {@code BufferedImage}
|
||||
* @return a new {@code MagickImage}
|
||||
*
|
||||
* @throws IllegalArgumentException if {@code pImage} is {@code null}
|
||||
* or if the {@code ColorModel} is not one mentioned above.
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
public static MagickImage toMagick(BufferedImage pImage) throws MagickException {
|
||||
if (pImage == null) {
|
||||
throw new IllegalArgumentException("image == null");
|
||||
}
|
||||
|
||||
long start = 0L;
|
||||
if (DEBUG) {
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
try {
|
||||
ColorModel cm = pImage.getColorModel();
|
||||
if (cm instanceof IndexColorModel) {
|
||||
// Handles both BilevelType, PaletteType and PaletteMatteType
|
||||
return indexedToMagick(pImage, (IndexColorModel) cm, cm.hasAlpha());
|
||||
}
|
||||
|
||||
switch (cm.getColorSpace().getType()) {
|
||||
case ColorSpace.TYPE_GRAY:
|
||||
// Handles GrayType and GrayMatteType
|
||||
return grayToMagick(pImage, cm.hasAlpha());
|
||||
case ColorSpace.TYPE_RGB:
|
||||
// Handles TrueColorType and TrueColorMatteType
|
||||
return rgbToMagic(pImage, cm.hasAlpha());
|
||||
case ColorSpace.TYPE_CMY:
|
||||
case ColorSpace.TYPE_CMYK:
|
||||
case ColorSpace.TYPE_HLS:
|
||||
case ColorSpace.TYPE_HSV:
|
||||
// Other types not supported yet
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown buffered image type: " + pImage);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (DEBUG) {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
System.out.println("Conversion to MagickImage: " + time + " ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MagickImage rgbToMagic(BufferedImage pImage, boolean pAlpha) throws MagickException {
|
||||
MagickImage image = new MagickImage();
|
||||
|
||||
BufferedImage buffered = ImageUtil.toBuffered(pImage, pAlpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
// Need to get data of sub raster, not the full data array, this is
|
||||
// just a convenient way
|
||||
Raster raster;
|
||||
if (buffered.getRaster().getParent() != null) {
|
||||
raster = buffered.getData(new Rectangle(buffered.getWidth(), buffered.getHeight()));
|
||||
}
|
||||
else {
|
||||
raster = buffered.getRaster();
|
||||
}
|
||||
|
||||
image.constituteImage(buffered.getWidth(), buffered.getHeight(), pAlpha ? "ABGR" : "BGR",
|
||||
((DataBufferByte) raster.getDataBuffer()).getData());
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private static MagickImage grayToMagick(BufferedImage pImage, boolean pAlpha) throws MagickException {
|
||||
MagickImage image = new MagickImage();
|
||||
|
||||
// TODO: Make a fix for TYPE_USHORT_GRAY
|
||||
// The code below does not seem to work (JMagick issues?)...
|
||||
/*
|
||||
if (pImage.getType() == BufferedImage.TYPE_USHORT_GRAY) {
|
||||
short[] data = ((DataBufferUShort) pImage.getRaster().getDataBuffer()).getData();
|
||||
int[] intData = new int[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
intData[i] = (data[i] & 0xffff) * 0xffff;
|
||||
}
|
||||
image.constituteImage(pImage.getWidth(), pImage.getHeight(), "I", intData);
|
||||
|
||||
System.out.println("storageClass: " + image.getStorageClass());
|
||||
System.out.println("depth: " + image.getDepth());
|
||||
System.out.println("imageType: " + image.getImageType());
|
||||
}
|
||||
else {
|
||||
*/
|
||||
BufferedImage buffered = ImageUtil.toBuffered(pImage, pAlpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
// Need to get data of sub raster, not the full data array, this is
|
||||
// just a convenient way
|
||||
Raster raster;
|
||||
if (buffered.getRaster().getParent() != null) {
|
||||
raster = buffered.getData(new Rectangle(buffered.getWidth(), buffered.getHeight()));
|
||||
}
|
||||
else {
|
||||
raster = buffered.getRaster();
|
||||
}
|
||||
|
||||
image.constituteImage(buffered.getWidth(), buffered.getHeight(), pAlpha ? "ABGR" : "I", ((DataBufferByte) raster.getDataBuffer()).getData());
|
||||
//}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private static MagickImage indexedToMagick(BufferedImage pImage, IndexColorModel pColorModel, boolean pAlpha) throws MagickException {
|
||||
MagickImage image = rgbToMagic(pImage, pAlpha);
|
||||
|
||||
int mapSize = pColorModel.getMapSize();
|
||||
image.setNumberColors(mapSize);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/*
|
||||
public static MagickImage toMagick(BufferedImage pImage) throws MagickException {
|
||||
if (pImage == null) {
|
||||
throw new IllegalArgumentException("image == null");
|
||||
}
|
||||
|
||||
final int width = pImage.getWidth();
|
||||
final int height = pImage.getHeight();
|
||||
|
||||
// int ARGB -> byte RGBA conversion
|
||||
// NOTE: This is ImageMagick Q16 compatible raw RGBA format with 16 bits/sample...
|
||||
// For a Q8 build, we could probably go with half the space...
|
||||
// NOTE: This is close to insanity, as it wastes extreme ammounts of memory
|
||||
final int[] argb = new int[width];
|
||||
final byte[] raw16 = new byte[width * height * 8];
|
||||
for (int y = 0; y < height; y++) {
|
||||
// Fetch one line of ARGB data
|
||||
pImage.getRGB(0, y, width, 1, argb, 0, width);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixel = (x + (y * width)) * 8;
|
||||
raw16[pixel ] = (byte) ((argb[x] >> 16) & 0xff); // R
|
||||
raw16[pixel + 2] = (byte) ((argb[x] >> 8) & 0xff); // G
|
||||
raw16[pixel + 4] = (byte) ((argb[x] ) & 0xff); // B
|
||||
raw16[pixel + 6] = (byte) ((argb[x] >> 24) & 0xff); // A
|
||||
}
|
||||
}
|
||||
|
||||
// Create magick image
|
||||
ImageInfo info = new ImageInfo();
|
||||
info.setMagick("RGBA"); // Raw RGBA samples
|
||||
info.setSize(width + "x" + height); // String?!?
|
||||
|
||||
MagickImage image = new MagickImage(info);
|
||||
image.setImageAttribute("depth", "8");
|
||||
|
||||
// Set pixel data in 16 bit raw RGBA format
|
||||
image.blobToImage(info, raw16);
|
||||
|
||||
return image;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a bi-level {@code MagickImage} to a {@code BufferedImage}, of
|
||||
* type {@code TYPE_BYTE_BINARY}.
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
private static BufferedImage bilevelToBuffered(MagickImage pImage) throws MagickException {
|
||||
// As there is no way to get the binary representation of the image,
|
||||
// convert to gray, and the create a binary image from it
|
||||
BufferedImage temp = grayToBuffered(pImage, false);
|
||||
|
||||
BufferedImage image = new BufferedImage(temp.getWidth(), temp.getHeight(), BufferedImage.TYPE_BYTE_BINARY, CM_MONOCHROME);
|
||||
|
||||
ImageUtil.drawOnto(image, temp);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a gray {@code MagickImage} to a {@code BufferedImage}, of
|
||||
* type {@code TYPE_USHORT_GRAY} or {@code TYPE_BYTE_GRAY}.
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @param pAlpha keep alpha channel
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
private static BufferedImage grayToBuffered(MagickImage pImage, boolean pAlpha) throws MagickException {
|
||||
Dimension size = pImage.getDimension();
|
||||
int length = size.width * size.height;
|
||||
int bands = pAlpha ? 2 : 1;
|
||||
byte[] pixels = new byte[length * bands];
|
||||
|
||||
// TODO: Make a fix for 16 bit TYPE_USHORT_GRAY?!
|
||||
// Note: The ordering AI or I corresponds to BufferedImage
|
||||
// TYPE_CUSTOM and TYPE_BYTE_GRAY respectively
|
||||
pImage.dispatchImage(0, 0, size.width, size.height, pAlpha ? "AI" : "I", pixels);
|
||||
|
||||
// Init databuffer with array, to avoid allocation of empty array
|
||||
DataBuffer buffer = new DataBufferByte(pixels, pixels.length);
|
||||
|
||||
int[] bandOffsets = pAlpha ? new int[] {1, 0} : new int[] {0};
|
||||
|
||||
WritableRaster raster =
|
||||
Raster.createInterleavedRaster(buffer, size.width, size.height,
|
||||
size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT);
|
||||
|
||||
return new BufferedImage(pAlpha ? CM_GRAY_ALPHA : CM_GRAY_OPAQUE, raster, pAlpha, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a palette-based {@code MagickImage} to a
|
||||
* {@code BufferedImage}, of type {@code TYPE_BYTE_BINARY} (for images
|
||||
* with a palette of <= 16 colors) or {@code TYPE_BYTE_INDEXED}.
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @param pAlpha keep alpha channel
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
private static BufferedImage paletteToBuffered(MagickImage pImage, boolean pAlpha) throws MagickException {
|
||||
// Create indexcolormodel for the image
|
||||
IndexColorModel cm;
|
||||
|
||||
try {
|
||||
cm = createIndexColorModel(pImage.getColormap(), pAlpha);
|
||||
}
|
||||
catch (MagickException e) {
|
||||
// NOTE: Some MagickImages incorrecly (?) reports to be paletteType,
|
||||
// but does not have a colormap, this is a workaround.
|
||||
return rgbToBuffered(pImage, pAlpha);
|
||||
}
|
||||
|
||||
// As there is no way to get the indexes of an indexed image, convert to
|
||||
// RGB, and the create an indexed image from it
|
||||
BufferedImage temp = rgbToBuffered(pImage, pAlpha);
|
||||
|
||||
BufferedImage image;
|
||||
if (cm.getMapSize() <= 16) {
|
||||
image = new BufferedImage(temp.getWidth(), temp.getHeight(), BufferedImage.TYPE_BYTE_BINARY, cm);
|
||||
}
|
||||
else {
|
||||
image = new BufferedImage(temp.getWidth(), temp.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, cm);
|
||||
}
|
||||
|
||||
// Create transparent background for images containing alpha
|
||||
if (pAlpha) {
|
||||
Graphics2D g = image.createGraphics();
|
||||
try {
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.fillRect(0, 0, temp.getWidth(), temp.getHeight());
|
||||
}
|
||||
finally {
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: This is (surprisingly) much faster than using g2d.drawImage()..
|
||||
// (Tests shows 20-30ms, vs. 600-700ms on the same image)
|
||||
BufferedImageOp op = new CopyDither(cm);
|
||||
op.filter(temp, image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code IndexColorModel} from an array of
|
||||
* {@code PixelPacket}s.
|
||||
*
|
||||
* @param pColormap the original colormap as a {@code PixelPacket} array
|
||||
* @param pAlpha keep alpha channel
|
||||
*
|
||||
* @return a new {@code IndexColorModel}
|
||||
*/
|
||||
public static IndexColorModel createIndexColorModel(PixelPacket[] pColormap, boolean pAlpha) {
|
||||
int[] colors = new int[pColormap.length];
|
||||
|
||||
// TODO: Verify if this is correct for alpha...?
|
||||
int trans = pAlpha ? colors.length - 1 : -1;
|
||||
|
||||
//for (int i = 0; i < pColormap.length; i++) {
|
||||
for (int i = pColormap.length - 1; i != 0; i--) {
|
||||
PixelPacket color = pColormap[i];
|
||||
if (pAlpha) {
|
||||
colors[i] = (0xff - (color.getOpacity() & 0xff)) << 24 |
|
||||
(color.getRed() & 0xff) << 16 |
|
||||
(color.getGreen() & 0xff) << 8 |
|
||||
(color.getBlue() & 0xff);
|
||||
}
|
||||
else {
|
||||
colors[i] = (color.getRed() & 0xff) << 16 |
|
||||
(color.getGreen() & 0xff) << 8 |
|
||||
(color.getBlue() & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
return new InverseColorMapIndexColorModel(8, colors.length, colors, 0, pAlpha, trans, DataBuffer.TYPE_BYTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an (A)RGB {@code MagickImage} to a {@code BufferedImage}, of
|
||||
* type {@code TYPE_4BYTE_ABGR} or {@code TYPE_3BYTE_BGR}.
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @param pAlpha keep alpha channel
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
private static BufferedImage rgbToBuffered(MagickImage pImage, boolean pAlpha) throws MagickException {
|
||||
Dimension size = pImage.getDimension();
|
||||
int length = size.width * size.height;
|
||||
int bands = pAlpha ? 4 : 3;
|
||||
byte[] pixels = new byte[length * bands];
|
||||
|
||||
// TODO: If we do multiple dispatches (one per line, typically), we could provide listener
|
||||
// feedback. But it's currently a lot slower than fetching all the pixels in one go.
|
||||
|
||||
// Note: The ordering ABGR or BGR corresponds to BufferedImage
|
||||
// TYPE_4BYTE_ABGR and TYPE_3BYTE_BGR respectively
|
||||
pImage.dispatchImage(0, 0, size.width, size.height, pAlpha ? "ABGR" : "BGR", pixels);
|
||||
|
||||
// Init databuffer with array, to avoid allocation of empty array
|
||||
DataBuffer buffer = new DataBufferByte(pixels, pixels.length);
|
||||
|
||||
int[] bandOffsets = pAlpha ? BAND_OFF_TRANS : BAND_OFF_OPAQUE;
|
||||
|
||||
WritableRaster raster =
|
||||
Raster.createInterleavedRaster(buffer, size.width, size.height,
|
||||
size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT);
|
||||
|
||||
return new BufferedImage(pAlpha ? CM_COLOR_ALPHA : CM_COLOR_OPAQUE, raster, pAlpha, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts an {@code MagickImage} to a {@code BufferedImage} which holds an CMYK ICC profile
|
||||
*
|
||||
* @param pImage the original {@code MagickImage}
|
||||
* @param pAlpha keep alpha channel
|
||||
* @return a new {@code BufferedImage}
|
||||
*
|
||||
* @throws MagickException if an exception occurs during conversion
|
||||
*
|
||||
* @see BufferedImage
|
||||
*/
|
||||
private static BufferedImage cmykToBuffered(MagickImage pImage, boolean pAlpha) throws MagickException {
|
||||
Dimension size = pImage.getDimension();
|
||||
int length = size.width * size.height;
|
||||
|
||||
// Retreive the ICC profile
|
||||
ICC_Profile profile = ICC_Profile.getInstance(pImage.getColorProfile().getInfo());
|
||||
ColorSpace cs = new ICC_ColorSpace(profile);
|
||||
|
||||
int bands = cs.getNumComponents() + (pAlpha ? 1 : 0);
|
||||
|
||||
int[] bits = new int[bands];
|
||||
for (int i = 0; i < bands; i++) {
|
||||
bits[i] = 8;
|
||||
}
|
||||
|
||||
ColorModel cm = pAlpha ?
|
||||
new ComponentColorModel(cs, bits, true, true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE) :
|
||||
new ComponentColorModel(cs, bits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
|
||||
|
||||
byte[] pixels = new byte[length * bands];
|
||||
|
||||
// TODO: If we do multiple dispatches (one per line, typically), we could provide listener
|
||||
// feedback. But it's currently a lot slower than fetching all the pixels in one go.
|
||||
// TODO: handle more generic cases if profile is not CMYK
|
||||
// TODO: Test "ACMYK"
|
||||
pImage.dispatchImage(0, 0, size.width, size.height, pAlpha ? "ACMYK" : "CMYK", pixels);
|
||||
|
||||
// Init databuffer with array, to avoid allocation of empty array
|
||||
DataBuffer buffer = new DataBufferByte(pixels, pixels.length);
|
||||
|
||||
// TODO: build array from bands variable, here it just works for CMYK
|
||||
// The values has not been tested with an alpha picture actually...
|
||||
int[] bandOffsets = pAlpha ? new int[] {0, 1, 2, 3, 4} : new int[] {0, 1, 2, 3};
|
||||
|
||||
WritableRaster raster =
|
||||
Raster.createInterleavedRaster(buffer, size.width, size.height,
|
||||
size.width * bands, bands, bandOffsets, LOCATION_UPPER_LEFT);
|
||||
|
||||
return new BufferedImage(cm, raster, pAlpha, null);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,7 @@
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
@@ -103,15 +101,6 @@ import java.awt.image.*;
|
||||
* BufferedImage scaled = new ResampleOp(w, h).filter(temp, null);
|
||||
* </pre></blockquote>
|
||||
* <p>
|
||||
* For maximum performance, this class will use native code, through
|
||||
* <a href="http://www.yeo.id.au/jmagick/">JMagick</a>, when available.
|
||||
* Otherwise, the class will silently fall back to pure Java mode.
|
||||
* Native code may be disabled globally, by setting the system property
|
||||
* {@code com.twelvemonkeys.image.accel} to {@code false}.
|
||||
* To allow debug of the native code, set the system property
|
||||
* {@code com.twelvemonkeys.image.magick.debug} to {@code true}.
|
||||
* </p>
|
||||
* <p>
|
||||
* This {@code BufferedImageOp} is based on C example code found in
|
||||
* <a href="http://www.acm.org/tog/GraphicsGems/">Graphics Gems III</a>,
|
||||
* Filtered Image Rescaling, by Dale Schumacher (with additional improvments by
|
||||
@@ -139,9 +128,6 @@ import java.awt.image.*;
|
||||
// TODO: Consider using AffineTransformOp for more operations!?
|
||||
public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
|
||||
|
||||
// NOTE: These MUST correspond to ImageMagick filter types, for the
|
||||
// MagickAccelerator to work consistently (see magick.FilterType).
|
||||
|
||||
/**
|
||||
* Undefined interpolation, filter method will use default filter.
|
||||
*/
|
||||
@@ -295,11 +281,10 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
|
||||
new Value(KEY_RESAMPLE_INTERPOLATION, "Blackman-Sinc", FILTER_BLACKMAN_SINC);
|
||||
|
||||
// Member variables
|
||||
// Package access, to allow access from MagickAccelerator
|
||||
int width;
|
||||
int height;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
int filterType;
|
||||
private final int filterType;
|
||||
|
||||
/**
|
||||
* RendereingHints.Key implementation, works only with Value values.
|
||||
@@ -547,16 +532,6 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
|
||||
// Fall through
|
||||
}
|
||||
|
||||
// Try to use native ImageMagick code
|
||||
BufferedImage result = MagickAccelerator.filter(this, input, output);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Otherwise, continue in pure Java mode
|
||||
|
||||
// TODO: What if output != null and wrong size? Create new? Render on only a part? Document?
|
||||
|
||||
// If filter type != POINT or BOX and input has IndexColorModel, convert
|
||||
// to true color, with alpha reflecting that of the original color model.
|
||||
BufferedImage temp;
|
||||
@@ -571,7 +546,7 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
|
||||
|
||||
// Create or convert output to a suitable image
|
||||
// TODO: OPTIMIZE: Don't really need to convert all types to same as input
|
||||
result = output != null && temp.getType() != BufferedImage.TYPE_CUSTOM ? /*output*/ ImageUtil.toBuffered(output, temp.getType()) : createCompatibleDestImage(temp, null);
|
||||
BufferedImage result = output != null && temp.getType() != BufferedImage.TYPE_CUSTOM ? /*output*/ ImageUtil.toBuffered(output, temp.getType()) : createCompatibleDestImage(temp, null);
|
||||
|
||||
resample(temp, result, filter);
|
||||
|
||||
@@ -1280,12 +1255,12 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
|
||||
/*
|
||||
* image rescaling routine
|
||||
*/
|
||||
class Contributor {
|
||||
static class Contributor {
|
||||
int pixel;
|
||||
double weight;
|
||||
}
|
||||
|
||||
class ContributorList {
|
||||
static class ContributorList {
|
||||
int n;/* number of contributors (may be < p.length) */
|
||||
Contributor[] p;/* pointer to list of contributions */
|
||||
}
|
||||
|
||||
+24
-26
@@ -31,9 +31,7 @@
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@@ -49,7 +47,7 @@ import java.util.List;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* AffineTransformOpTest.
|
||||
@@ -146,12 +144,12 @@ public class AffineTransformOpTest {
|
||||
BufferedImage jreResult = jreOp.filter(image, null);
|
||||
BufferedImage tmResult = tmOp.filter(image, null);
|
||||
|
||||
assertNotNull("No result!", tmResult);
|
||||
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
|
||||
assertNotNull(tmResult, "No result!");
|
||||
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +162,7 @@ public class AffineTransformOpTest {
|
||||
BufferedImage image = spec.createBufferedImage(width, height);
|
||||
|
||||
BufferedImage tmResult = tmOp.filter(image, null);
|
||||
assertNotNull("No result!", tmResult);
|
||||
assertNotNull(tmResult, "No result!");
|
||||
|
||||
BufferedImage jreResult = null;
|
||||
|
||||
@@ -176,18 +174,18 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Bad type", jreResult.getType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel());
|
||||
assertEquals(jreResult.getType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(jreResult.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Bad type", spec.getBufferedImageType(), tmResult.getType());
|
||||
assertEquals("Incorrect color model", spec.getColorModel(), tmResult.getColorModel());
|
||||
assertEquals(spec.getBufferedImageType(), tmResult.getType(), "Bad type");
|
||||
assertEquals(spec.getColorModel(), tmResult.getColorModel(), "Incorrect color model");
|
||||
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,12 +234,12 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,12 +275,12 @@ public class AffineTransformOpTest {
|
||||
}
|
||||
|
||||
if (jreResult != null) {
|
||||
assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth());
|
||||
assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight());
|
||||
assertEquals(jreResult.getWidth(), tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(jreResult.getHeight(), tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
else {
|
||||
assertEquals("Incorrect width", height, tmResult.getWidth());
|
||||
assertEquals("Incorrect height", width, tmResult.getHeight());
|
||||
assertEquals(height, tmResult.getWidth(), "Incorrect width");
|
||||
assertEquals(width, tmResult.getHeight(), "Incorrect height");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
-31
@@ -30,17 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.color.*;
|
||||
import java.awt.image.*;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BufferedImageFactoryTestCase
|
||||
@@ -50,50 +49,58 @@ import static org.junit.Assert.assertTrue;
|
||||
* @version $Id: BufferedImageFactoryTestCase.java,v 1.0 May 7, 2010 12:40:08 PM haraldk Exp$
|
||||
*/
|
||||
public class BufferedImageFactoryTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullImage() {
|
||||
new BufferedImageFactory((Image) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory((Image) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullProducer() {
|
||||
new BufferedImageFactory((ImageProducer) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory((ImageProducer) null);
|
||||
});
|
||||
}
|
||||
|
||||
// NPE in Toolkit, ok
|
||||
@Test(expected = RuntimeException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceByteArray() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
|
||||
|
||||
new BufferedImageFactory(source);
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((byte[]) null);
|
||||
new BufferedImageFactory(source);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceImageProducer() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((ImageProducer) null);
|
||||
|
||||
new BufferedImageFactory(source);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new BufferedImageFactory(source);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: This is a quite serious bug, however, the bug is in the Toolkit, allowing such images in the first place...
|
||||
// In any case, there's not much we can do, except until someone is bored and kills the app/thread... :-P
|
||||
@Ignore("Bug in Toolkit")
|
||||
@Test(timeout = 1000, expected = ImageConversionException.class)
|
||||
@Disabled("Bug in Toolkit")
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceString() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
factory.getBufferedImage();
|
||||
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
assertThrows(ImageConversionException.class, factory::getBufferedImage);
|
||||
});
|
||||
}
|
||||
|
||||
// This is a little random, and it would be nicer if we could throw an IllegalArgumentException on create.
|
||||
// Unfortunately, the API doesn't allow this...
|
||||
@Test(timeout = 1000, expected = ImageConversionException.class)
|
||||
@Test
|
||||
public void testGetBufferedImageErrorSourceURL() {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/META-INF/MANIFEST.MF"));
|
||||
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
factory.getBufferedImage();
|
||||
assertTimeoutPreemptively(Duration.ofMillis(1000), () -> {
|
||||
Image source = Toolkit.getDefaultToolkit().createImage((String) null);
|
||||
BufferedImageFactory factory = new BufferedImageFactory(source);
|
||||
assertThrows(ImageConversionException.class, factory::getBufferedImage);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +172,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
assertEquals(3, colorModel.getNumColorComponents());
|
||||
assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace());
|
||||
assertTrue(colorModel instanceof IndexColorModel);
|
||||
assertInstanceOf(IndexColorModel.class, colorModel);
|
||||
|
||||
assertTrue(colorModel.hasAlpha());
|
||||
assertEquals(4, colorModel.getNumComponents());
|
||||
@@ -196,7 +203,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(x * 2, y * 2), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x * 2, y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +226,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x, 40 + y), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(40 + x, 40 + y), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,7 +250,7 @@ public class BufferedImageFactoryTest {
|
||||
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
assertEquals("RGB[" + x + ", " + y + "]", original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y));
|
||||
assertEquals(original.getRGB(40 + x * 2, 40 + y * 2), image.getRGB(x, y), "RGB[" + x + ", " + y + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -39,7 +39,7 @@ import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ImageUtilTest {
|
||||
|
||||
@@ -116,8 +116,8 @@ public class ImageUtilTest {
|
||||
public void testImageIsNotBufferedImage() {
|
||||
// Should not be a buffered image
|
||||
assertFalse(
|
||||
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too.",
|
||||
scaled instanceof BufferedImage
|
||||
scaled instanceof BufferedImage,
|
||||
"FOR SOME IMPLEMENTATIONS THIS MIGHT FAIL!\nIn that case, testToBufferedImage() will fail too."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class ImageUtilTest {
|
||||
if (original != notContrasted) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 constrast should not change image", original.getRGB(x, y), notContrasted.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notContrasted.getRGB(x, y), "0 constrast should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,24 +275,24 @@ public class ImageUtilTest {
|
||||
|
||||
// RED
|
||||
if (oR < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oR >= cR && cR >= dR);
|
||||
assertTrue(oR >= cR && cR >= dR, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oR <= cR && cR <= dR);
|
||||
assertTrue(oR <= cR && cR <= dR, "Contrast should be increased or same");
|
||||
}
|
||||
// GREEN
|
||||
if (oG < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oG >= cG && cG >= dG);
|
||||
assertTrue(oG >= cG && cG >= dG, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oG <= cG && cG <= dG);
|
||||
assertTrue(oG <= cG && cG <= dG, "Contrast should be increased or same");
|
||||
}
|
||||
// BLUE
|
||||
if (oB < 127) {
|
||||
assertTrue("Contrast should be decreased or same", oB >= cB && cB >= dB);
|
||||
assertTrue(oB >= cB && cB >= dB, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oB <= cB && cB <= dB);
|
||||
assertTrue(oB <= cB && cB <= dB, "Contrast should be increased or same");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,9 +304,9 @@ public class ImageUtilTest {
|
||||
int r = rgb >> 16 & 0xFF;
|
||||
int g = rgb >> 8 & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
assertTrue("Max contrast should only produce primary colors", r == 0 || r == 255);
|
||||
assertTrue("Max contrast should only produce primary colors", g == 0 || g == 255);
|
||||
assertTrue("Max contrast should only produce primary colors", b == 0 || b == 255);
|
||||
assertTrue(r == 0 || r == 255, "Max contrast should only produce primary colors");
|
||||
assertTrue(g == 0 || g == 255, "Max contrast should only produce primary colors");
|
||||
assertTrue(b == 0 || b == 255, "Max contrast should only produce primary colors");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,24 +327,24 @@ public class ImageUtilTest {
|
||||
|
||||
// RED
|
||||
if (oR >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oR >= cR);
|
||||
assertTrue(oR >= cR, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oR <= cR);
|
||||
assertTrue(oR <= cR, "Contrast should be increased or same");
|
||||
}
|
||||
// GREEN
|
||||
if (oG >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oG >= cG);
|
||||
assertTrue(oG >= cG, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oG <= cG);
|
||||
assertTrue(oG <= cG, "Contrast should be increased or same");
|
||||
}
|
||||
// BLUE
|
||||
if (oB >= 127) {
|
||||
assertTrue("Contrast should be decreased or same", oB >= cB);
|
||||
assertTrue(oB >= cB, "Contrast should be decreased or same");
|
||||
}
|
||||
else {
|
||||
assertTrue("Contrast should be increased or same", oB <= cB);
|
||||
assertTrue(oB <= cB, "Contrast should be increased or same");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public class ImageUtilTest {
|
||||
int r = rgb >> 16 & 0xFF;
|
||||
int g = rgb >> 8 & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
assertTrue("Minimum contrast should be all gray", r == 127 && g == 127 && b == 127);
|
||||
assertTrue(r == 127 && g == 127 && b == 127, "Minimum contrast should be all gray");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class ImageUtilTest {
|
||||
if (original != notSharpened) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 sharpen should not change image", original.getRGB(x, y), notSharpened.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notSharpened.getRGB(x, y), "0 sharpen should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,13 +446,13 @@ public class ImageUtilTest {
|
||||
}
|
||||
|
||||
// assertEquals("Difference should not change", diffOriginal, diffSharpened);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffSharpened);
|
||||
assertTrue(absDiffOriginal < absDiffSharpened, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffDefault);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffDefault);
|
||||
assertTrue(absDiffOriginal < absDiffDefault, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffMore);
|
||||
assertTrue("Abs difference should increase", absDiffOriginal < absDiffMore);
|
||||
assertTrue(absDiffOriginal < absDiffMore, "Abs difference should increase");
|
||||
// assertEquals("Difference should not change", diffSharpened, diffMore);
|
||||
assertTrue("Abs difference should increase", absDiffSharpened < absDiffMore);
|
||||
assertTrue(absDiffSharpened < absDiffMore, "Abs difference should increase");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +466,7 @@ public class ImageUtilTest {
|
||||
if (original != notBlurred) { // Don't care to test if images are same
|
||||
for (int y = 0; y < original.getHeight(); y++) {
|
||||
for (int x = 0; x < original.getWidth(); x++) {
|
||||
assertEquals("0 blur should not change image", original.getRGB(x, y), notBlurred.getRGB(x, y));
|
||||
assertEquals(original.getRGB(x, y), notBlurred.getRGB(x, y), "0 blur should not change image");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -512,13 +512,13 @@ public class ImageUtilTest {
|
||||
}
|
||||
|
||||
// assertEquals("Difference should not change", diffOriginal, diffBlurred);
|
||||
assertTrue(String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred), absDiffOriginal > absDiffBlurred);
|
||||
assertTrue(absDiffOriginal > absDiffBlurred, String.format("Abs difference should decrease: %s <= %s", absDiffOriginal, absDiffBlurred));
|
||||
// assertEquals("Difference should not change", diffOriginal, diffDefault);
|
||||
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffDefault);
|
||||
assertTrue(absDiffOriginal > absDiffDefault, "Abs difference should decrease");
|
||||
// assertEquals("Difference should not change", diffOriginal, diffMore);
|
||||
assertTrue("Abs difference should decrease", absDiffOriginal > absDiffMore);
|
||||
assertTrue(absDiffOriginal > absDiffMore, "Abs difference should decrease");
|
||||
// assertEquals("Difference should not change", diffBlurred, diffMore);
|
||||
assertTrue("Abs difference should decrease", absDiffBlurred > absDiffMore);
|
||||
assertTrue(absDiffBlurred > absDiffMore, "Abs difference should decrease");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -528,7 +528,7 @@ public class ImageUtilTest {
|
||||
assertNotNull(sunflower);
|
||||
|
||||
BufferedImage image = ImageUtil.createIndexed(sunflower);
|
||||
assertNotNull("Image was null", image);
|
||||
assertTrue(image.getColorModel() instanceof IndexColorModel);
|
||||
assertNotNull(image, "Image was null");
|
||||
assertInstanceOf(IndexColorModel.class, image.getColorModel());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.image;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -40,7 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ResampleOpTestCase
|
||||
@@ -124,7 +124,7 @@ public class ResampleOpTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Filter threw exceptions: ", Collections.EMPTY_LIST, exceptions);
|
||||
assertEquals(Collections.EMPTY_LIST, exceptions, "Filter threw exceptions: ");
|
||||
}
|
||||
|
||||
// 1x1
|
||||
@@ -358,7 +358,7 @@ public class ResampleOpTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Not for general unit testing")
|
||||
@Disabled("Not for general unit testing")
|
||||
@Test
|
||||
public void testTime() {
|
||||
int iterations = 1000;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
TODO:
|
||||
Remove compile-time dependency on JMagick:
|
||||
- Extract interface for MagickAccelerator
|
||||
- Move implementation to separate module
|
||||
- Instantiate impl via reflection
|
||||
DONE:
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.common</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>common-io</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class DecoderStream extends FilterInputStream {
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public DecoderStream(final InputStream stream, final Decoder decoder) {
|
||||
// TODO: Let the decoder decide preferred buffer size
|
||||
// TODO: Let the decoder decide preferred buffer size
|
||||
this(stream, decoder, 1024);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class DecoderStream extends FilterInputStream {
|
||||
super(stream);
|
||||
|
||||
this.decoder = decoder;
|
||||
buffer = ByteBuffer.allocate(bufferSize);
|
||||
buffer = ByteBuffer.allocate(bufferSize); // TODO: Allow decoder to specify minimum buffer size
|
||||
buffer.flip();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
import com.twelvemonkeys.util.CollectionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@@ -40,7 +39,8 @@ import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CompoundReaderTestCase
|
||||
|
||||
+2
-3
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* FastByteArrayOutputStreamTestCase
|
||||
|
||||
@@ -30,11 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* MemoryCacheSeekableStreamTestCase
|
||||
@@ -92,13 +91,13 @@ public class FileSeekableStreamTest extends SeekableInputStreamAbstractTest {
|
||||
try {
|
||||
FileUtil.read(stream); // Read until EOF
|
||||
|
||||
assertEquals("EOF not reached (test case broken)", -1, stream.read());
|
||||
assertFalse("Underlying stream closed before close", closed[0]);
|
||||
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
|
||||
assertFalse(closed[0], "Underlying stream closed before close");
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
assertTrue("Underlying stream not closed", closed[0]);
|
||||
assertTrue(closed[0], "Underlying stream not closed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* InputStreamAbstractTestCase
|
||||
@@ -104,15 +104,15 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
int size = 5;
|
||||
InputStream input = makeInputStream(makeOrderedArray(size));
|
||||
for (int i = 0; i < size; i++) {
|
||||
assertTrue("Check Size [" + i + "]", (size - i) >= input.available());
|
||||
assertEquals("Check Value [" + i + "]", i, input.read());
|
||||
assertTrue((size - i) >= input.available(), "Check Size [" + i + "]");
|
||||
assertEquals(i, input.read(), "Check Value [" + i + "]");
|
||||
}
|
||||
assertEquals("Available after contents all read", 0, input.available());
|
||||
assertEquals(0, input.available(), "Available after contents all read");
|
||||
|
||||
// Test reading after the end of file
|
||||
try {
|
||||
int result = input.read();
|
||||
assertEquals("Wrong value read after end of file", -1, result);
|
||||
assertEquals( -1, result, "Wrong value read after end of file");
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail("Should not have thrown an IOException: " + e.getMessage());
|
||||
@@ -122,12 +122,12 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testAvailable() throws Exception {
|
||||
InputStream input = makeInputStream(1);
|
||||
assertFalse("Unexpected EOF", input.read() < 0);
|
||||
assertEquals("Available after contents all read", 0, input.available());
|
||||
assertFalse(input.read() < 0, "Unexpected EOF");
|
||||
assertEquals(0, input.available(), "Available after contents all read");
|
||||
|
||||
// Check availbale is zero after End of file
|
||||
assertEquals("End of File", -1, input.read());
|
||||
assertEquals("Available after End of File", 0, input.available());
|
||||
assertEquals(-1, input.read(), "End of File");
|
||||
assertEquals( 0, input.available(), "Available after End of File");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,26 +138,26 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read into array
|
||||
int count1 = input.read(bytes);
|
||||
assertEquals("Read 1", bytes.length, count1);
|
||||
assertEquals(bytes.length, count1, "Read 1");
|
||||
for (int i = 0; i < count1; i++) {
|
||||
assertEquals("Check Bytes 1", i, bytes[i]);
|
||||
assertEquals(i, bytes[i], "Check Bytes 1");
|
||||
}
|
||||
|
||||
// Read into array
|
||||
int count2 = input.read(bytes);
|
||||
assertEquals("Read 2", 5, count2);
|
||||
assertEquals(5, count2, "Read 2");
|
||||
for (int i = 0; i < count2; i++) {
|
||||
assertEquals("Check Bytes 2", count1 + i, bytes[i]);
|
||||
assertEquals(count1 + i, bytes[i], "Check Bytes 2");
|
||||
}
|
||||
|
||||
// End of File
|
||||
int count3 = input.read(bytes);
|
||||
assertEquals("Read 3 (EOF)", -1, count3);
|
||||
assertEquals(-1, count3, "Read 3 (EOF)");
|
||||
|
||||
// Test reading after the end of file
|
||||
try {
|
||||
int result = input.read(bytes);
|
||||
assertEquals("Wrong value read after end of file", -1, result);
|
||||
assertEquals(-1, result, "Wrong value read after end of file");
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail("Should not have thrown an IOException: " + e.getMessage());
|
||||
@@ -170,20 +170,20 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
int offset = 2;
|
||||
int lth = 4;
|
||||
int count5 = input.read(bytes, offset, lth);
|
||||
assertEquals("Read 5", lth, count5);
|
||||
assertEquals(lth, count5, "Read 5");
|
||||
for (int i = offset; i < lth; i++) {
|
||||
assertEquals("Check Bytes 2", i - offset, bytes[i]);
|
||||
assertEquals(i - offset, bytes[i], "Check Bytes 2");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOF() throws Exception {
|
||||
InputStream input = makeInputStream(makeOrderedArray(2));
|
||||
assertEquals("Read 1", 0, input.read());
|
||||
assertEquals("Read 2", 1, input.read());
|
||||
assertEquals("Read 3", -1, input.read());
|
||||
assertEquals("Read 4", -1, input.read());
|
||||
assertEquals("Read 5", -1, input.read());
|
||||
assertEquals(0, input.read(), "Read 1");
|
||||
assertEquals(1, input.read(), "Read 2");
|
||||
assertEquals(-1, input.read(), "Read 3");
|
||||
assertEquals(-1, input.read(), "Read 4");
|
||||
assertEquals(-1, input.read(), "Read 5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,7 +205,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
fail("Should throw IOException");
|
||||
}
|
||||
catch (IOException e) {
|
||||
assertTrue("Wrong messge: " + e.getMessage(), e.getMessage().contains("reset"));
|
||||
assertTrue(e.getMessage().contains("reset"), "Wrong messge: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,10 +223,10 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
// No mark may either throw exception, or reset to beginning of stream.
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be same", 0, input.read());
|
||||
assertEquals(0, input.read(), "Re-read of reset data should be same");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong no mark IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong no mark IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read further
|
||||
for (int i = 0; i < 3; i++) {
|
||||
assertEquals("Read After Mark [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Mark [" + i + "]");
|
||||
}
|
||||
|
||||
// Reset
|
||||
@@ -257,7 +257,7 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read from marked position
|
||||
for (int i = 0; i < readlimit + 1; i++) {
|
||||
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,16 +280,16 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
// Read past marked position
|
||||
for (int i = 0; i < readlimit + 1; i++) {
|
||||
assertEquals("Read After Reset [" + i + "]", (position + i), input.read());
|
||||
assertEquals((position + i), input.read(), "Read After Reset [" + i + "]");
|
||||
}
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last mark
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be same", 1, input.read());
|
||||
assertEquals(1, input.read(), "Re-read of reset data should be same");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,29 +302,29 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
|
||||
int first = input.read();
|
||||
assertTrue("Expected to read positive value", first >= 0);
|
||||
assertTrue(first >= 0, "Expected to read positive value");
|
||||
|
||||
int readlimit = 5;
|
||||
|
||||
// Mark
|
||||
input.mark(readlimit);
|
||||
int read = input.read();
|
||||
assertTrue("Expected to read positive value", read >= 0);
|
||||
assertTrue(read >= 0, "Expected to read positive value");
|
||||
|
||||
assertTrue(input.read() >= 0);
|
||||
assertTrue(input.read() >= 0);
|
||||
|
||||
input.reset();
|
||||
assertEquals("Expected value read differs from actual", read, input.read());
|
||||
assertEquals(read, input.read(), "Expected value read differs from actual");
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last good mark
|
||||
try {
|
||||
input.reset();
|
||||
int reRead = input.read();
|
||||
assertTrue("Re-read of reset data should be same as initially marked or first", reRead == read || reRead == first);
|
||||
assertTrue(reRead == read || reRead == first, "Re-read of reset data should be same as initially marked or first");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,17 +332,17 @@ public abstract class InputStreamAbstractTest extends ObjectAbstractTest {
|
||||
public void testSkip() throws Exception {
|
||||
InputStream input = makeInputStream(makeOrderedArray(10));
|
||||
|
||||
assertEquals("Unexpected value read", 0, input.read());
|
||||
assertEquals("Unexpected value read", 1, input.read());
|
||||
assertEquals("Unexpected number of bytes skipped", 5, input.skip(5));
|
||||
assertEquals("Unexpected value read", 7, input.read());
|
||||
assertEquals(0, input.read(), "Unexpected value read");
|
||||
assertEquals(1, input.read(), "Unexpected value read");
|
||||
assertEquals(5, input.skip(5), "Unexpected number of bytes skipped");
|
||||
assertEquals(7, input.read(), "Unexpected value read");
|
||||
|
||||
assertEquals("Unexpected number of bytes skipped", 2, input.skip(5)); // only 2 left to skip
|
||||
assertEquals("Unexpected value read after EOF", -1, input.read());
|
||||
assertEquals(2, input.skip(5), "Unexpected number of bytes skipped"); // only 2 left to skip
|
||||
assertEquals(-1, input.read(), "Unexpected value read after EOF");
|
||||
|
||||
// Spec says skip might return 0 or negative after EOF...
|
||||
assertTrue("Positive value skipped after EOF", input.skip(5) <= 0); // End of file
|
||||
assertEquals("Unexpected value read after EOF", -1, input.read());
|
||||
assertTrue(input.skip(5) <= 0, "Positive value skipped after EOF"); // End of file
|
||||
assertEquals(-1, input.read(), "Unexpected value read after EOF");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-3
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* LittleEndianDataInputStreamTest
|
||||
|
||||
@@ -31,13 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* InputStreamAbstractTestCase
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ReaderAbstractTestCase
|
||||
@@ -112,7 +112,7 @@ public abstract class ReaderAbstractTest extends ObjectAbstractTest {
|
||||
int toSkip = mInput.length();
|
||||
while (toSkip > 0) {
|
||||
long skipped = reader.skip(toSkip);
|
||||
assertFalse("Skipped < 0", skipped < 0);
|
||||
assertFalse(skipped < 0, "Skipped < 0");
|
||||
toSkip -= skipped;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SeekableAbstractTestCase
|
||||
|
||||
+22
-23
@@ -30,14 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SeekableInputStreamAbstractTest
|
||||
@@ -79,25 +78,25 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
return; // Not supported, skip test
|
||||
}
|
||||
|
||||
assertTrue("Expected to read positive value", input.read() >= 0);
|
||||
assertTrue(input.read() >= 0, "Expected to read positive value");
|
||||
|
||||
int readlimit = 5;
|
||||
|
||||
// Mark
|
||||
input.mark(readlimit);
|
||||
int read = input.read();
|
||||
assertTrue("Expected to read positive value", read >= 0);
|
||||
assertTrue(read >= 0, "Expected to read positive value");
|
||||
|
||||
input.reset();
|
||||
assertEquals("Expected value read differs from actual", read, input.read());
|
||||
assertEquals(read, input.read(), "Expected value read differs from actual");
|
||||
|
||||
// Reset after read limit passed, may either throw exception, or reset to last good mark
|
||||
try {
|
||||
input.reset();
|
||||
assertEquals("Re-read of reset data should be first", 0, input.read());
|
||||
assertEquals(0, input.read(), "Re-read of reset data should be first");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue("Wrong read-limit IOException message", e.getMessage().contains("mark"));
|
||||
assertTrue(e.getMessage().contains("mark"), "Wrong read-limit IOException message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +126,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
|
||||
seekable.seek(pos);
|
||||
long streamPos = seekable.getStreamPosition();
|
||||
assertEquals("Stream positon should match seeked position", pos, streamPos);
|
||||
assertEquals(pos, streamPos, "Stream positon should match seeked position");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +136,7 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
seekable.seek(pos);
|
||||
seekable.flushBefore(pos);
|
||||
long flushedPos = seekable.getFlushedPosition();
|
||||
assertEquals("Flushed positon should match position", pos, flushedPos);
|
||||
assertEquals(pos, flushedPos, "Flushed positon should match position");
|
||||
|
||||
try {
|
||||
seekable.seek(pos - 1);
|
||||
@@ -382,13 +381,13 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
int val;
|
||||
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
val = stream.read();
|
||||
assertFalse("Unexepected EOF", val == -1);
|
||||
assertFalse(val == -1, "Unexepected EOF");
|
||||
|
||||
stream.seek(0);
|
||||
|
||||
@@ -422,19 +421,19 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
|
||||
stream.seek(0);
|
||||
for (int i = 0; i < bytes.length; i += 2) {
|
||||
assertEquals("Wrong stream position", i, stream.getStreamPosition());
|
||||
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
|
||||
int count = stream.read(buffer, 0, 2);
|
||||
assertEquals(2, count);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], buffer[0]);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i + 1], buffer[1]);
|
||||
assertEquals(bytes[i], buffer[0], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
assertEquals(bytes[i + 1], buffer[1], String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
}
|
||||
|
||||
stream.seek(0);
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
assertEquals("Wrong stream position", i, stream.getStreamPosition());
|
||||
assertEquals(i, stream.getStreamPosition(), "Wrong stream position");
|
||||
int actual = stream.read();
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i] & 0xff, actual);
|
||||
assertEquals(String.format("Wrong value read at pos %d", stream.getStreamPosition()), bytes[i], (byte) actual);
|
||||
assertEquals(bytes[i] & 0xff, actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
assertEquals(bytes[i], (byte) actual, String.format("Wrong value read at pos %d", stream.getStreamPosition()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -456,14 +455,14 @@ public abstract class SeekableInputStreamAbstractTest extends InputStreamAbstrac
|
||||
try {
|
||||
FileUtil.read(stream); // Read until EOF
|
||||
|
||||
assertEquals("EOF not reached (test case broken)", -1, stream.read());
|
||||
assertFalse("Underlying stream closed before close", closed[0]);
|
||||
assertEquals(-1, stream.read(), "EOF not reached (test case broken)");
|
||||
assertFalse(closed[0], "Underlying stream closed before close");
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
assertTrue("Underlying stream not closed", closed[0]);
|
||||
assertTrue(closed[0], "Underlying stream not closed");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* StringArrayReaderTestCase
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.twelvemonkeys.io;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SubStreamTest.
|
||||
@@ -23,14 +22,18 @@ public class SubStreamTest {
|
||||
private final Random rng = new Random(2918475687L);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullStream() {
|
||||
new SubStream(null, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubStream(null, 42);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNegativeLength() {
|
||||
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new SubStream(new ByteArrayInputStream(new byte[1]), -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,15 +103,17 @@ public class SubStreamTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("EmptyTryBlock")
|
||||
@Test(timeout = 500L)
|
||||
@Test
|
||||
public void testCloseConsumesAllShortStream() throws IOException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
|
||||
assertTimeoutPreemptively(Duration.ofMillis(500), () -> {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(new byte[13]);
|
||||
|
||||
try (InputStream ignore = new SubStream(stream, 42)) {
|
||||
// Nothing here...
|
||||
}
|
||||
try (InputStream ignore = new SubStream(stream, 42)) {
|
||||
// Nothing here...
|
||||
}
|
||||
|
||||
assertEquals(0, stream.available());
|
||||
assertEquals(-1, stream.read());
|
||||
assertEquals(0, stream.available());
|
||||
assertEquals(-1, stream.read());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,15 +31,13 @@
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* Base64DecoderTest
|
||||
* <p/>
|
||||
@@ -66,7 +64,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
|
||||
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +76,7 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match", "test", new String(bytes.toByteArray()));
|
||||
assertEquals("test", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,11 +91,12 @@ public class Base64DecoderTest extends DecoderAbstractTest {
|
||||
|
||||
FileUtil.copy(in, bytes);
|
||||
|
||||
assertEquals("Strings does not match",
|
||||
assertEquals(
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing " +
|
||||
"elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " +
|
||||
"dapibus laoreet purus. Nunc viverra dictum nisl. Integer " +
|
||||
"ullamcorper, nisi in dictum amet.",
|
||||
new String(bytes.toByteArray()));
|
||||
new String(bytes.toByteArray()),
|
||||
"Strings does not match");
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,12 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Base64EncoderTest
|
||||
@@ -63,7 +62,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
|
||||
assertEquals("", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,7 +73,7 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match", "dGVzdA==", new String(bytes.toByteArray()));
|
||||
assertEquals("dGVzdA==", new String(bytes.toByteArray()), "Strings does not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,11 +87,12 @@ public class Base64EncoderTest extends EncoderAbstractTest {
|
||||
OutputStream out = new EncoderStream(bytes, createEncoder(), true);
|
||||
out.write(data.getBytes());
|
||||
|
||||
assertEquals("Strings does not match",
|
||||
assertEquals(
|
||||
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" +
|
||||
"c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" +
|
||||
"b3JlZXQgcHVydXMuIE51bmMgdml2ZXJyYSBkaWN0dW0gbmlzbC4gSW50ZWdlciB1bGxhbWNvcnBlciwg" +
|
||||
"bmlzaSBpbiBkaWN0dW0gYW1ldC4=",
|
||||
new String(bytes.toByteArray()));
|
||||
new String(bytes.toByteArray()),
|
||||
"Strings does not match");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,13 @@ package com.twelvemonkeys.io.enc;
|
||||
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractDecoderTest
|
||||
@@ -55,13 +56,13 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
return createDecoder();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public final void testNullDecode() throws IOException {
|
||||
Decoder decoder = createDecoder();
|
||||
ByteArrayInputStream bytes = new ByteArrayInputStream(new byte[20]);
|
||||
|
||||
decoder.decode(bytes, null);
|
||||
fail("null should throw NullPointerException");
|
||||
assertThrows(NullPointerException.class, () -> {
|
||||
decoder.decode(bytes, null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +72,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
try {
|
||||
int count = decoder.decode(bytes, ByteBuffer.allocate(128));
|
||||
assertEquals("Should not be able to read any bytes", 0, count);
|
||||
assertEquals( 0, count, "Should not be able to read any bytes");
|
||||
}
|
||||
catch (EOFException allowed) {
|
||||
// Okay
|
||||
@@ -94,7 +95,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
byte[] encoded = outBytes.toByteArray();
|
||||
|
||||
byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createDecoder()));
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
|
||||
|
||||
InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createDecoder());
|
||||
outBytes = new ByteArrayOutputStream();
|
||||
@@ -103,7 +104,7 @@ public abstract class DecoderAbstractTest extends ObjectAbstractTest {
|
||||
in.close();
|
||||
|
||||
decoded = outBytes.toByteArray();
|
||||
assertArrayEquals(String.format("Data %d", pLength), data, decoded);
|
||||
assertArrayEquals(data, decoded, String.format("Data %d", pLength));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -39,7 +38,8 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DecoderStreamTest {
|
||||
|
||||
|
||||
@@ -33,13 +33,12 @@ package com.twelvemonkeys.io.enc;
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractEncoderTest
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.io.enc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -39,7 +37,8 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class EncoderStreamTest {
|
||||
|
||||
|
||||
+17
-16
@@ -31,9 +31,9 @@
|
||||
package com.twelvemonkeys.io.ole2;
|
||||
|
||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -43,8 +43,8 @@ import java.nio.ByteOrder;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* CompoundDocumentTestCase
|
||||
*
|
||||
@@ -59,8 +59,8 @@ public class CompoundDocumentTest {
|
||||
protected final CompoundDocument createTestDocument() throws IOException {
|
||||
URL input = getClass().getResource(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertEquals("Test resource not a file:// resource", "file", input.getProtocol());
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
assertEquals( "file", input.getProtocol(), "Test resource not a file:// resource");
|
||||
|
||||
try {
|
||||
return new CompoundDocument(new File(input.toURI()));
|
||||
@@ -103,7 +103,7 @@ public class CompoundDocumentTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void testChildEntriesUnmodifiable() throws IOException {
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -111,9 +111,10 @@ public class CompoundDocumentTest {
|
||||
assertNotNull(root);
|
||||
|
||||
SortedSet<Entry> children = root.getChildEntries();
|
||||
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ public class CompoundDocumentTest {
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ public class CompoundDocumentTest {
|
||||
public void testReadCatalogInputStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
CompoundDocument document = new CompoundDocument(input);
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -145,14 +146,14 @@ public class CompoundDocumentTest {
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadCatalogSeekableStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
CompoundDocument document = new CompoundDocument(new MemoryCacheSeekableStream(input));
|
||||
Entry root = document.getRootEntry();
|
||||
@@ -161,14 +162,14 @@ public class CompoundDocumentTest {
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadCatalogImageInputStream() throws IOException {
|
||||
InputStream input = getClass().getResourceAsStream(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertNotNull(input, "Missing test resource!");
|
||||
|
||||
MemoryCacheImageInputStream stream = new MemoryCacheImageInputStream(input);
|
||||
stream.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -183,6 +184,6 @@ public class CompoundDocumentTest {
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog.getInputStream(), "Input stream may not be null");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
package com.twelvemonkeys.io.ole2;
|
||||
|
||||
import com.twelvemonkeys.io.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
|
||||
+4
-4
@@ -33,7 +33,6 @@ package com.twelvemonkeys.io.ole2;
|
||||
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
||||
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
|
||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -42,7 +41,8 @@ import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CompoundDocument_StreamTestCase
|
||||
@@ -165,8 +165,8 @@ public class CompoundDocument_StreamTest extends InputStreamAbstractTest {
|
||||
count++;
|
||||
}
|
||||
|
||||
assertFalse("Short stream", count < 32);
|
||||
assertFalse("Stream overrun", count > 32);
|
||||
assertFalse(count < 32, "Short stream");
|
||||
assertFalse(count > 32, "Stream overrun");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,9 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.net;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* HTTPUtilTest
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.common</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>common-lang</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -1765,12 +1765,11 @@ public final class StringUtil {
|
||||
* expression.
|
||||
* <p>
|
||||
* An invocation of this method of the form
|
||||
* <tt>matches(<i>str</i>, <i>regex</i>)</tt> yields exactly the
|
||||
* {@code matches(str, regex)} yields exactly the
|
||||
* same result as the expression
|
||||
* </p>
|
||||
* <blockquote><tt> {@link Pattern}.
|
||||
* {@link Pattern#matches(String, CharSequence) matches}
|
||||
* (<i>regex</i>, <i>str</i>)</tt></blockquote>
|
||||
* <blockquote>{@link Pattern}.
|
||||
* {@link Pattern#matches(String, CharSequence) matches(regex, str)}</blockquote>
|
||||
*
|
||||
* @param pString the string
|
||||
* @param pRegex the regular expression to which this string is to be matched
|
||||
@@ -1789,16 +1788,14 @@ public final class StringUtil {
|
||||
* regular expression with the given pReplacement.
|
||||
* <p>
|
||||
* An invocation of this method of the form
|
||||
* <tt>
|
||||
* replaceFirst(<i>str</i>, <i>regex</i>, <i>repl</i>)
|
||||
* </tt>
|
||||
* {@code replaceFirst(str, regex, repl)}
|
||||
* yields exactly the same result as the expression:
|
||||
* </p>
|
||||
* <blockquote><tt>
|
||||
* {@link Pattern}.{@link Pattern#compile(String) compile}(<i>regex</i>).
|
||||
* {@link Pattern#matcher matcher}(<i>str</i>).
|
||||
* {@link java.util.regex.Matcher#replaceFirst replaceFirst}(<i>repl</i>)
|
||||
* </tt></blockquote>
|
||||
* <blockquote>
|
||||
* {@link Pattern#compile(String) Pattern.compile(regex)}
|
||||
* {@link Pattern#matcher .matcher(str)}
|
||||
* {@link java.util.regex.Matcher#replaceFirst .replaceFirst(repl)}
|
||||
* </blockquote>
|
||||
*
|
||||
* @param pString the string
|
||||
* @param pRegex the regular expression to which this string is to be matched
|
||||
@@ -1817,14 +1814,14 @@ public final class StringUtil {
|
||||
* regular expression with the given pReplacement.
|
||||
* <p>
|
||||
* An invocation of this method of the form
|
||||
* <tt>replaceAll(<i>str</i>, <i>pRegex</i>, <i>repl</i>)</tt>
|
||||
* {@code replaceAll(str, pRegex, repl)}
|
||||
* yields exactly the same result as the expression
|
||||
* </p>
|
||||
* <blockquote><tt>
|
||||
* {@link Pattern}.{@link Pattern#compile(String) compile}(<i>pRegex</i>).
|
||||
* {@link Pattern#matcher matcher}(<i>str</i>{@code ).
|
||||
* {@link java.util.regex.Matcher#replaceAll replaceAll}(}<i>repl</i>{@code )}
|
||||
* </tt></blockquote>
|
||||
* <blockquote>
|
||||
* {@link Pattern#compile(String) Pattern.compile(pRegex)}
|
||||
* {@link Pattern#matcher .matcher(str)}
|
||||
* {@link java.util.regex.Matcher#replaceAll .replaceAll(repl)}
|
||||
* </blockquote>
|
||||
*
|
||||
* @param pString the string
|
||||
* @param pRegex the regular expression to which this string is to be matched
|
||||
@@ -1862,12 +1859,12 @@ public final class StringUtil {
|
||||
* </p>
|
||||
* <p>
|
||||
* An invocation of this method of the form
|
||||
* <tt>split(<i>str</i>, <i>regex</i>, <i>n</i>)</tt>
|
||||
* {@code split(str, regex, n)}
|
||||
* yields the same result as the expression:
|
||||
* </p>
|
||||
* <blockquote>{@link Pattern}.
|
||||
* {@link Pattern#compile(String) compile}<tt>(<i>regex</i>).
|
||||
* {@link Pattern#split(CharSequence,int) split}(<i>str</i>, <i>n</i>)</tt>
|
||||
* {@link Pattern#compile(String) compile(regex)}.
|
||||
* {@link Pattern#split(CharSequence,int) split(str, n)}
|
||||
* </blockquote>
|
||||
*
|
||||
* @param pString the string
|
||||
|
||||
@@ -30,14 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BeanUtilTestCase
|
||||
@@ -161,10 +160,8 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
"one", bean.getAmbiguous());
|
||||
assertSame("String converted rather than invoking setAmbiguous(String), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals("one", bean.getAmbiguous(), "String converted rather than invoking setAmbiguous(String), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(), "String converted rather than invoking setAmbiguous(String), ordering not predictable");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,10 +181,10 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
2, bean.getAmbiguous());
|
||||
assertSame("Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals(2, bean.getAmbiguous(),
|
||||
"Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(),
|
||||
"Integer converted rather than invoking setAmbiguous(Integer), ordering not predictable");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,10 +204,8 @@ public class BeanUtilTest {
|
||||
}
|
||||
|
||||
assertNotNull(bean.getAmbiguous());
|
||||
assertEquals("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value.getClass(), bean.getAmbiguous().getClass());
|
||||
assertSame("Object converted rather than invoking setAmbiguous(Object), ordering not predictable",
|
||||
value, bean.getAmbiguous());
|
||||
assertEquals(value.getClass(), bean.getAmbiguous().getClass(), "Object converted rather than invoking setAmbiguous(Object), ordering not predictable");
|
||||
assertSame(value, bean.getAmbiguous(), "Object converted rather than invoking setAmbiguous(Object), ordering not predictable");
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
|
||||
@@ -30,16 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* DateUtilTest
|
||||
@@ -48,12 +48,9 @@ import static org.junit.Assert.assertEquals;
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: DateUtilTest.java,v 1.0 11.04.12 16:21 haraldk Exp$
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
|
||||
public class DateUtilTest {
|
||||
|
||||
private final TimeZone timeZone;
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static List<Object[]> timeZones() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{TimeZone.getTimeZone("UTC")},
|
||||
@@ -62,10 +59,6 @@ public class DateUtilTest {
|
||||
});
|
||||
}
|
||||
|
||||
public DateUtilTest(final TimeZone timeZone) {
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
private Calendar getCalendar(long time) {
|
||||
return getCalendar(time, TimeZone.getDefault());
|
||||
}
|
||||
@@ -101,8 +94,9 @@ public class DateUtilTest {
|
||||
assertEquals(0, calendar.get(Calendar.MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundToHourTZ() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("timeZones")
|
||||
public void testRoundToHourTZ(TimeZone timeZone) {
|
||||
Calendar calendar = getCalendar(DateUtil.roundToHour(System.currentTimeMillis(), timeZone), timeZone);
|
||||
|
||||
assertEquals(0, calendar.get(Calendar.MILLISECOND));
|
||||
@@ -120,8 +114,9 @@ public class DateUtilTest {
|
||||
assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundToDayTZ() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("timeZones")
|
||||
public void testRoundToDayTZ(TimeZone timeZone) {
|
||||
Calendar calendar = getCalendar(DateUtil.roundToDay(System.currentTimeMillis(), timeZone), timeZone);
|
||||
|
||||
assertEquals(0, calendar.get(Calendar.MILLISECOND));
|
||||
|
||||
@@ -30,12 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AbstractObjectTestCase
|
||||
@@ -79,10 +78,10 @@ public abstract class ObjectAbstractTest {
|
||||
|
||||
Class cl = obj.getClass();
|
||||
if (isEqualsOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements equals but not hashCode", isHashCodeOverriden(cl));
|
||||
assertTrue(isHashCodeOverriden(cl), "Class " + cl.getName() + " implements equals but not hashCode");
|
||||
}
|
||||
else if (isHashCodeOverriden(cl)) {
|
||||
assertTrue("Class " + cl.getName() + " implements hashCode but not equals", isEqualsOverriden(cl));
|
||||
assertTrue(isEqualsOverriden(cl), "Class " + cl.getName() + " implements hashCode but not equals");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("An Object should equal itself", obj, obj);
|
||||
assertEquals(obj, obj, "An Object should equal itself");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,32 +114,26 @@ public abstract class ObjectAbstractTest {
|
||||
Object obj = makeObject();
|
||||
// NOTE: Makes sure this doesn't throw NPE either
|
||||
//noinspection ObjectEqualsNull
|
||||
assertFalse("An object should never equal null", obj.equals(null));
|
||||
assertFalse(obj.equals(null), "An object should never equal null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
assertEquals(obj.hashCode(), obj.hashCode(), "hashCode should be repeatable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
assertEquals(obj1.hashCode(), obj1.hashCode(), "[1] When two objects are equal, their hashCodes should be also.");
|
||||
}
|
||||
// TODO: Make sure we create at least one equal object, and one different object
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
assertEquals(obj1.hashCode(), obj2.hashCode(), "[2] When two objects are equal, their hashCodes should be also.");
|
||||
assertTrue(obj2.equals(obj1), "When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,14 +162,14 @@ public abstract class ObjectAbstractTest {
|
||||
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
assertNotNull(cloned, "Cloned object should never be null");
|
||||
|
||||
// TODO: This can only be asserted if equals() test is based on
|
||||
// value equality, not reference (identity) equality
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isHashCodeOverriden(cl)) {
|
||||
assertEquals("Cloned object not equal", obj, cloned);
|
||||
assertEquals(obj, cloned, "Cloned object not equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +228,7 @@ public abstract class ObjectAbstractTest {
|
||||
// Maybe it's possible to do a reflective introspection of
|
||||
// the objects fields?
|
||||
if (isEqualsOverriden(obj.getClass())) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
assertEquals(obj, dest, "obj != deserialize(serialize(obj))");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PlatformTest
|
||||
@@ -121,7 +119,7 @@ public class PlatformTest {
|
||||
assertEquals(Platform.Architecture.X86, platform.getArchitecture());
|
||||
}
|
||||
|
||||
@Ignore("Known issue, needs resolve")
|
||||
@Disabled("Known issue, needs resolve")
|
||||
@Test
|
||||
public void testCreateWindows686() {
|
||||
Platform platform = new Platform(createProperties("Windows", "5.1", "686"));
|
||||
@@ -129,7 +127,7 @@ public class PlatformTest {
|
||||
assertEquals(Platform.Architecture.X86, platform.getArchitecture());
|
||||
}
|
||||
|
||||
@Ignore("Known issue, needs resolve")
|
||||
@Disabled("Known issue, needs resolve")
|
||||
@Test
|
||||
public void testCreateLinuxX86() {
|
||||
Platform platform = new Platform(createProperties("Linux", "3.0.18", "x86"));
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
@@ -41,8 +39,8 @@ import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* StringUtilTestCase
|
||||
*
|
||||
@@ -165,10 +163,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if (TEST_STRING.indexOf(i) < 0) {
|
||||
assertFalse(TEST_STRING + " seems to contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.contains(TEST_STRING, i));
|
||||
assertFalse(StringUtil.contains(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.contains(TEST_STRING, i));
|
||||
assertTrue(StringUtil.contains(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,10 +197,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertFalse(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), StringUtil.containsIgnoreCase(TEST_STRING, i));
|
||||
assertFalse(StringUtil.containsIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), StringUtil.containsIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(StringUtil.containsIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,10 +348,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.indexOfIgnoreCase(TEST_STRING, i));
|
||||
assertEquals(-1, StringUtil.indexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,10 +383,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0));
|
||||
assertEquals(-1, StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0));
|
||||
assertTrue(0 <= StringUtil.indexOfIgnoreCase(TEST_STRING, i, 0), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,10 +418,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i));
|
||||
assertEquals(-1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i));
|
||||
assertTrue(0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,10 +453,10 @@ public class StringUtilTest {
|
||||
// Test all alpha-chars
|
||||
for (int i = 'a'; i < 'z'; i++) {
|
||||
if ((TEST_STRING.indexOf(i) < 0) && (TEST_STRING.indexOf(Character.toUpperCase((char) i)) < 0)) {
|
||||
assertEquals(TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))), -1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()));
|
||||
assertEquals(-1, StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()), TEST_STRING + " seems to contain '" + (char) i + "', at index " + Math.max(TEST_STRING.indexOf(i), TEST_STRING.indexOf(Character.toUpperCase((char) i))));
|
||||
}
|
||||
else {
|
||||
assertTrue(TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i), 0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()));
|
||||
assertTrue(0 <= StringUtil.lastIndexOfIgnoreCase(TEST_STRING, i, TEST_STRING.length()), TEST_STRING + " seems to not contain '" + (char) i + "', at index " + TEST_STRING.indexOf(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
package com.twelvemonkeys.lang;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
|
||||
/**
|
||||
* SystemUtilTest
|
||||
@@ -39,6 +39,6 @@ import org.junit.Ignore;
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: SystemUtilTest.java,v 1.0 11.04.12 16:21 haraldk Exp$
|
||||
*/
|
||||
@Ignore
|
||||
@Disabled
|
||||
public class SystemUtilTest {
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+91
-137
@@ -45,12 +45,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link java.util.Collection} methods and contracts.
|
||||
@@ -251,11 +250,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
*/
|
||||
public void verifyAll() {
|
||||
int confirmedSize = confirmed.size();
|
||||
assertEquals("Collection size should match confirmed collection's",
|
||||
confirmedSize, collection.size());
|
||||
assertEquals("Collection isEmpty() result should match confirmed " +
|
||||
" collection's",
|
||||
confirmed.isEmpty(), collection.isEmpty());
|
||||
assertEquals(confirmedSize, collection.size(), "Collection size should match confirmed collection's");
|
||||
assertEquals(confirmed.isEmpty(), collection.isEmpty(), "Collection isEmpty() result should match confirmed collection's");
|
||||
|
||||
// verify the collections are the same by attempting to match each
|
||||
// object in the collection and confirmed collection. To account for
|
||||
@@ -521,8 +517,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
boolean r = collection.add(elements[i]);
|
||||
confirmed.add(elements[i]);
|
||||
verifyAll();
|
||||
assertTrue("Empty collection changed after add", r);
|
||||
assertEquals("Collection size is 1 after first add", 1, collection.size());
|
||||
assertTrue(r, "Empty collection changed after add");
|
||||
assertEquals(1, collection.size(), "Collection size is 1 after first add");
|
||||
}
|
||||
|
||||
resetEmpty();
|
||||
@@ -532,10 +528,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.add(elements[i]);
|
||||
verifyAll();
|
||||
if (r) size++;
|
||||
assertEquals("Collection size should grow after add",
|
||||
size, collection.size());
|
||||
assertTrue("Collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertEquals(size, collection.size(), "Collection size should grow after add");
|
||||
assertTrue(collection.contains(elements[i]), "Collection should contain added element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,10 +546,9 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
boolean r = collection.addAll(Arrays.asList(elements));
|
||||
confirmed.addAll(Arrays.asList(elements));
|
||||
verifyAll();
|
||||
assertTrue("Empty collection should change after addAll", r);
|
||||
assertTrue(r, "Empty collection should change after addAll");
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Collection should contain added element");
|
||||
}
|
||||
|
||||
resetFull();
|
||||
@@ -564,13 +557,11 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
r = collection.addAll(Arrays.asList(elements));
|
||||
confirmed.addAll(Arrays.asList(elements));
|
||||
verifyAll();
|
||||
assertTrue("Full collection should change after addAll", r);
|
||||
assertTrue(r, "Full collection should change after addAll");
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection should contain added element",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Full collection should contain added element");
|
||||
}
|
||||
assertEquals("Size should increase after addAll",
|
||||
size + elements.length, collection.size());
|
||||
assertEquals(size + elements.length, collection.size(), "Size should increase after addAll");
|
||||
|
||||
resetFull();
|
||||
size = collection.size();
|
||||
@@ -578,11 +569,9 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.addAll(Arrays.asList(getFullElements()));
|
||||
verifyAll();
|
||||
if (r) {
|
||||
assertTrue("Size should increase if addAll returns true",
|
||||
size < collection.size());
|
||||
assertTrue(size < collection.size(), "Size should increase if addAll returns true");
|
||||
} else {
|
||||
assertEquals("Size should not change if addAll returns false",
|
||||
size, collection.size());
|
||||
assertEquals(size, collection.size(), "Size should not change if addAll returns false");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,16 +655,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
elements = getFullElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Empty collection shouldn't contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
|
||||
elements = getOtherElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Empty collection shouldn't contain element[" + i + "]",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Empty collection shouldn't contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
@@ -683,8 +670,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
elements = getFullElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection should contain element[" + i + "]",
|
||||
collection.contains(elements[i]));
|
||||
assertTrue(collection.contains(elements[i]), "Full collection should contain element[" + i + "]");
|
||||
}
|
||||
// make sure calls to "contains" don't change anything
|
||||
verifyAll();
|
||||
@@ -692,8 +678,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
elements = getOtherElements();
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Full collection shouldn't contain element",
|
||||
!collection.contains(elements[i]));
|
||||
assertTrue(!collection.contains(elements[i]), "Full collection shouldn't contain element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,22 +690,22 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
public void testCollectionContainsAll() {
|
||||
resetEmpty();
|
||||
Collection col = new HashSet();
|
||||
assertTrue("Every Collection should contain all elements of an " +
|
||||
"empty Collection.", collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col),
|
||||
"Every Collection should contain all elements of an " +
|
||||
"empty Collection.");
|
||||
col.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Empty Collection shouldn't contain all elements of " +
|
||||
"a non-empty Collection.", !collection.containsAll(col));
|
||||
assertTrue(!collection.containsAll(col),
|
||||
"Empty Collection shouldn't contain all elements of " +
|
||||
"a non-empty Collection.");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full collection shouldn't contain other elements",
|
||||
!collection.containsAll(col));
|
||||
assertTrue(!collection.containsAll(col), "Full collection shouldn't contain other elements");
|
||||
|
||||
col.clear();
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
assertTrue("Full collection should containAll full elements",
|
||||
collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll full elements");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
@@ -728,18 +713,17 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
int max = (getFullElements().length == 1 ? 1 :
|
||||
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
||||
col = Arrays.asList(getFullElements()).subList(min, max);
|
||||
assertTrue("Full collection should containAll partial full " +
|
||||
"elements", collection.containsAll(col));
|
||||
assertTrue("Full collection should containAll itself",
|
||||
collection.containsAll(collection));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll partial full " +
|
||||
"elements");
|
||||
assertTrue(collection.containsAll(collection), "Full collection should containAll itself");
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
|
||||
col = new ArrayList();
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
col.addAll(Arrays.asList(getFullElements()));
|
||||
assertTrue("Full collection should containAll duplicate full " +
|
||||
"elements", collection.containsAll(col));
|
||||
assertTrue(collection.containsAll(col), "Full collection should containAll duplicate full " +
|
||||
"elements");
|
||||
|
||||
// make sure calls to "containsAll" don't change anything
|
||||
verifyAll();
|
||||
@@ -751,14 +735,12 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("New Collection should be empty.",
|
||||
true, collection.isEmpty());
|
||||
assertEquals(true, collection.isEmpty(), "New Collection should be empty.");
|
||||
// make sure calls to "isEmpty() don't change anything
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full collection shouldn't be empty",
|
||||
false, collection.isEmpty());
|
||||
assertEquals(false, collection.isEmpty(), "Full collection shouldn't be empty");
|
||||
// make sure calls to "isEmpty() don't change anything
|
||||
verifyAll();
|
||||
}
|
||||
@@ -771,8 +753,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
public void testCollectionIterator() {
|
||||
resetEmpty();
|
||||
Iterator it1 = collection.iterator();
|
||||
assertEquals("Iterator for empty Collection shouldn't have next.",
|
||||
false, it1.hasNext());
|
||||
assertEquals(false, it1.hasNext(), "Iterator for empty Collection shouldn't have next.");
|
||||
try {
|
||||
it1.next();
|
||||
fail("Iterator at end of Collection should throw " +
|
||||
@@ -786,18 +767,17 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetFull();
|
||||
it1 = collection.iterator();
|
||||
for (int i = 0; i < collection.size(); i++) {
|
||||
assertTrue("Iterator for full collection should haveNext",
|
||||
it1.hasNext());
|
||||
assertTrue(it1.hasNext(), "Iterator for full collection should haveNext");
|
||||
it1.next();
|
||||
}
|
||||
assertTrue("Iterator should be finished", !it1.hasNext());
|
||||
assertTrue(!it1.hasNext(), "Iterator should be finished");
|
||||
|
||||
ArrayList list = new ArrayList();
|
||||
it1 = collection.iterator();
|
||||
for (int i = 0; i < collection.size(); i++) {
|
||||
Object next = it1.next();
|
||||
assertTrue("Collection should contain element returned by " +
|
||||
"its iterator", collection.contains(next));
|
||||
assertTrue(collection.contains(next), "Collection should contain element returned by " +
|
||||
"its iterator");
|
||||
list.add(next);
|
||||
}
|
||||
try {
|
||||
@@ -865,11 +845,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
|
||||
size--;
|
||||
assertEquals("Collection should shrink by one after " +
|
||||
"iterator.remove", size, collection.size());
|
||||
assertEquals(size, collection.size(), "Collection should shrink by one after " +
|
||||
"iterator.remove");
|
||||
}
|
||||
assertTrue("Collection should be empty after iterator purge",
|
||||
collection.isEmpty());
|
||||
assertTrue(collection.isEmpty(), "Collection should be empty after iterator purge");
|
||||
|
||||
resetFull();
|
||||
iter = collection.iterator();
|
||||
@@ -894,8 +873,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
Object[] elements = getFullElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
assertTrue("Shouldn't remove nonexistent element",
|
||||
!collection.remove(elements[i]));
|
||||
assertTrue(!collection.remove(elements[i]), "Shouldn't remove nonexistent element");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -903,16 +881,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetFull();
|
||||
for (int i = 0; i < other.length; i++) {
|
||||
assertTrue("Shouldn't remove nonexistent other element",
|
||||
!collection.remove(other[i]));
|
||||
assertTrue(!collection.remove(other[i]), "Shouldn't remove nonexistent other element");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
int size = collection.size();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
resetFull();
|
||||
assertTrue("Collection should remove extant element: " + elements[i],
|
||||
collection.remove(elements[i]));
|
||||
assertTrue(collection.remove(elements[i]), "Collection should remove extant element: " + elements[i]);
|
||||
|
||||
// if the elements aren't distinguishable, we can just remove a
|
||||
// matching element from the confirmed collection and verify
|
||||
@@ -927,8 +903,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
assertEquals("Collection should shrink after remove",
|
||||
size - 1, collection.size());
|
||||
assertEquals(size - 1, collection.size(), "Collection should shrink after remove");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,28 +916,28 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
if (!isRemoveSupported()) return;
|
||||
|
||||
resetEmpty();
|
||||
assertTrue("Emtpy collection removeAll should return false for " +
|
||||
"empty input",
|
||||
!collection.removeAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.removeAll(Collections.EMPTY_SET),
|
||||
"Emtpy collection removeAll should return false for " +
|
||||
"empty input");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Emtpy collection removeAll should return false for " +
|
||||
"nonempty input",
|
||||
!collection.removeAll(new ArrayList(collection)));
|
||||
assertTrue(!collection.removeAll(new ArrayList(collection)),
|
||||
"Emtpy collection removeAll should return false for " +
|
||||
"nonempty input");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full collection removeAll should return false for " +
|
||||
"empty input",
|
||||
!collection.removeAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.removeAll(Collections.EMPTY_SET),
|
||||
"Full collection removeAll should return false for " +
|
||||
"empty input");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Full collection removeAll should return false for other elements",
|
||||
!collection.removeAll(Arrays.asList(getOtherElements())));
|
||||
assertTrue(!collection.removeAll(Arrays.asList(getOtherElements())),
|
||||
"Full collection removeAll should return false for other elements");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Full collection removeAll should return true for full elements",
|
||||
collection.removeAll(new HashSet(collection)));
|
||||
assertTrue(collection.removeAll(new HashSet(collection)),
|
||||
"Full collection removeAll should return true for full elements");
|
||||
confirmed.removeAll(new HashSet(confirmed));
|
||||
verifyAll();
|
||||
|
||||
@@ -972,17 +947,14 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
int max = (getFullElements().length == 1 ? 1 :
|
||||
(getFullElements().length <= 5 ? getFullElements().length - 1 : 5));
|
||||
Collection all = Arrays.asList(getFullElements()).subList(min, max);
|
||||
assertTrue("Full collection removeAll should work",
|
||||
collection.removeAll(all));
|
||||
assertTrue(collection.removeAll(all), "Full collection removeAll should work");
|
||||
confirmed.removeAll(all);
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Collection should shrink after removeAll",
|
||||
collection.size() < size);
|
||||
assertTrue(collection.size() < size, "Collection should shrink after removeAll");
|
||||
Iterator iter = all.iterator();
|
||||
while (iter.hasNext()) {
|
||||
assertTrue("Collection shouldn't contain removed element",
|
||||
!collection.contains(iter.next()));
|
||||
assertTrue(!collection.contains(iter.next()), "Collection shouldn't contain removed element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -998,59 +970,51 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
List elements = Arrays.asList(getFullElements());
|
||||
List other = Arrays.asList(getOtherElements());
|
||||
|
||||
assertTrue("Empty retainAll() should return false",
|
||||
!collection.retainAll(Collections.EMPTY_SET));
|
||||
assertTrue(!collection.retainAll(Collections.EMPTY_SET), "Empty retainAll() should return false");
|
||||
verifyAll();
|
||||
|
||||
assertTrue("Empty retainAll() should return false",
|
||||
!collection.retainAll(elements));
|
||||
assertTrue(!collection.retainAll(elements), "Empty retainAll() should return false");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Collection should change from retainAll empty",
|
||||
collection.retainAll(Collections.EMPTY_SET));
|
||||
assertTrue(collection.retainAll(Collections.EMPTY_SET), "Collection should change from retainAll empty");
|
||||
confirmed.retainAll(Collections.EMPTY_SET);
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Collection changed from retainAll other",
|
||||
collection.retainAll(other));
|
||||
assertTrue(collection.retainAll(other), "Collection changed from retainAll other");
|
||||
confirmed.retainAll(other);
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
int size = collection.size();
|
||||
assertTrue("Collection shouldn't change from retainAll elements",
|
||||
!collection.retainAll(elements));
|
||||
assertTrue(!collection.retainAll(elements), "Collection shouldn't change from retainAll elements");
|
||||
verifyAll();
|
||||
assertEquals("Collection size shouldn't change", size,
|
||||
collection.size());
|
||||
assertEquals(size, collection.size(), "Collection size shouldn't change");
|
||||
|
||||
if (getFullElements().length > 1) {
|
||||
resetFull();
|
||||
size = collection.size();
|
||||
int min = (getFullElements().length < 2 ? 0 : 2);
|
||||
int max = (getFullElements().length <= 5 ? getFullElements().length - 1 : 5);
|
||||
assertTrue("Collection should changed by partial retainAll",
|
||||
collection.retainAll(elements.subList(min, max)));
|
||||
assertTrue(collection.retainAll(elements.subList(min, max)), "Collection should changed by partial retainAll");
|
||||
confirmed.retainAll(elements.subList(min, max));
|
||||
verifyAll();
|
||||
|
||||
Iterator iter = collection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
assertTrue("Collection only contains retained element",
|
||||
elements.subList(min, max).contains(iter.next()));
|
||||
assertTrue(elements.subList(min, max).contains(iter.next()), "Collection only contains retained element");
|
||||
}
|
||||
}
|
||||
|
||||
resetFull();
|
||||
HashSet set = new HashSet(elements);
|
||||
size = collection.size();
|
||||
assertTrue("Collection shouldn't change from retainAll without " +
|
||||
"duplicate elements", !collection.retainAll(set));
|
||||
assertTrue(!collection.retainAll(set),
|
||||
"Collection shouldn't change from retainAll without duplicate elements");
|
||||
verifyAll();
|
||||
assertEquals("Collection size didn't change from nonduplicate " +
|
||||
"retainAll", size, collection.size());
|
||||
assertEquals( size, collection.size(),
|
||||
"Collection size didn't change from nonduplicate retainAll");
|
||||
}
|
||||
|
||||
|
||||
@@ -1060,11 +1024,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Size of new Collection is 0.", 0, collection.size());
|
||||
assertEquals(0, collection.size(), "Size of new Collection is 0.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("Size of full collection should be greater than zero",
|
||||
collection.size() > 0);
|
||||
assertTrue(collection.size() > 0, "Size of full collection should be greater than zero");
|
||||
}
|
||||
|
||||
|
||||
@@ -1073,22 +1036,18 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
*/
|
||||
public void testCollectionToArray() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty Collection should return empty array for toArray",
|
||||
0, collection.toArray().length);
|
||||
assertEquals(0, collection.toArray().length, "Empty Collection should return empty array for toArray");
|
||||
|
||||
resetFull();
|
||||
Object[] array = collection.toArray();
|
||||
assertEquals("Full collection toArray should be same size as " +
|
||||
"collection", array.length, collection.size());
|
||||
assertEquals(array.length, collection.size(), "Full collection toArray should be same size as collection");
|
||||
Object[] confirmedArray = confirmed.toArray();
|
||||
assertEquals("length of array from confirmed collection should " +
|
||||
"match the length of the collection's array",
|
||||
confirmedArray.length, array.length);
|
||||
assertEquals(confirmedArray.length, array.length,
|
||||
"length of array from confirmed collection should match the length of the collection's array");
|
||||
boolean[] matched = new boolean[array.length];
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
assertTrue("Collection should contain element in toArray",
|
||||
collection.contains(array[i]));
|
||||
assertTrue(collection.contains(array[i]), "Collection should contain element in toArray");
|
||||
|
||||
boolean match = false;
|
||||
// find a match in the confirmed array
|
||||
@@ -1108,8 +1067,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < matched.length; i++) {
|
||||
assertEquals("Collection should return all its elements in " +
|
||||
"toArray", true, matched[i]);
|
||||
assertEquals(true, matched[i], "Collection should return all its elements in toArray");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1123,8 +1081,8 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
resetEmpty();
|
||||
Object[] a = new Object[] { new Object(), null, null };
|
||||
Object[] array = collection.toArray(a);
|
||||
assertArrayEquals("Given array shouldn't shrink", array, a);
|
||||
assertNull("Last element should be set to null", a[0]);
|
||||
assertArrayEquals(array, a, "Given array shouldn't shrink");
|
||||
assertNull(a[0], "Last element should be set to null");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
@@ -1146,8 +1104,7 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
array = collection.toArray(new Object[0]);
|
||||
a = collection.toArray();
|
||||
assertEquals("toArrays should be equal",
|
||||
Arrays.asList(array), Arrays.asList(a));
|
||||
assertEquals(Arrays.asList(array), Arrays.asList(a), "toArrays should be equal");
|
||||
|
||||
// Figure out if they're all the same class
|
||||
// TODO: It'd be nicer to detect a common superclass
|
||||
@@ -1163,11 +1120,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
a = (Object[])Array.newInstance(cl, 0);
|
||||
array = collection.toArray(a);
|
||||
assertEquals("toArray(Object[]) should return correct array type",
|
||||
a.getClass(), array.getClass());
|
||||
assertEquals("type-specific toArrays should be equal",
|
||||
Arrays.asList(array),
|
||||
Arrays.asList(collection.toArray()));
|
||||
assertEquals(a.getClass(), array.getClass(), "toArray(Object[]) should return correct array type");
|
||||
assertEquals(Arrays.asList(array),
|
||||
Arrays.asList(collection.toArray()),
|
||||
"type-specific toArrays should be equal");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -1178,12 +1134,10 @@ public abstract class CollectionAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testCollectionToString() {
|
||||
resetEmpty();
|
||||
assertTrue("toString shouldn't return null",
|
||||
collection.toString() != null);
|
||||
assertTrue(collection.toString() != null, "toString shouldn't return null");
|
||||
|
||||
resetFull();
|
||||
assertTrue("toString shouldn't return null",
|
||||
collection.toString() != null);
|
||||
assertTrue(collection.toString() != null, "toString shouldn't return null");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* CollectionUtilTest
|
||||
*
|
||||
@@ -61,44 +59,60 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new Object[] {"bar", "baz", 3}, merged);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 4, 2, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 4, 2, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadSecondOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 4, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 4, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 4, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 4, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectBadSecondLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, 2);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, 2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, -1, 2, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, -1, 2, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeSecondOffset() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, -1, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, -1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, -1, integerObjects, 2, 1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, -1, integerObjects, 2, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectNegativeSecondLength() {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, -1);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
CollectionUtil.mergeArrays(stringObjects, 1, 2, integerObjects, 2, -1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,20 +123,24 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new Object[] {"foo", "bar", "baz", 1, 2, 3}, merged);
|
||||
}
|
||||
|
||||
@Test(expected = ArrayStoreException.class)
|
||||
@Test
|
||||
public void testMergeArraysObjectIllegalType() {
|
||||
String[] strings = {"foo", "bar", "baz"};
|
||||
Integer[] integers = {1, 2, 3}; // Integer not assignable to String
|
||||
|
||||
CollectionUtil.mergeArrays(strings, integers);
|
||||
assertThrows(ArrayStoreException.class, () -> {
|
||||
CollectionUtil.mergeArrays(strings, integers);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ArrayStoreException.class)
|
||||
@Test
|
||||
public void testMergeArraysNativeIllegalType() {
|
||||
char[] chars = {'a', 'b', 'c'};
|
||||
int[] integers = {1, 2, 3}; // Integer not assignable to String
|
||||
|
||||
CollectionUtil.mergeArrays(chars, integers);
|
||||
assertThrows(ArrayStoreException.class, () -> {
|
||||
CollectionUtil.mergeArrays(chars, integers);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -147,9 +165,11 @@ public class CollectionUtilTest {
|
||||
assertArrayEquals(new int[] {2, 3, 4}, numbers);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testEnumIteratorNull() {
|
||||
CollectionUtil.iterator((Enumeration<Object>) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator((Enumeration<Object>) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,9 +203,11 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorNull() {
|
||||
CollectionUtil.iterator((Object[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator((Object[]) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -262,7 +284,7 @@ public class CollectionUtilTest {
|
||||
|
||||
int count = 0;
|
||||
for (Object element : elements) {
|
||||
assertTrue("No next element for element '" + element + "' at index: " + count, iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "No next element for element '" + element + "' at index: " + count);
|
||||
assertEquals(count > 0, iterator.hasPrevious());
|
||||
assertEquals(count, iterator.nextIndex());
|
||||
assertEquals(count - 1, iterator.previousIndex());
|
||||
@@ -318,7 +340,7 @@ public class CollectionUtilTest {
|
||||
assertEquals(elements.length, iterator.nextIndex());
|
||||
|
||||
for (int i = count; i > 0; i--) {
|
||||
assertTrue("No previous element for element '" + elements[i - 1] + "' at index: " + (i - 1), iterator.hasPrevious());
|
||||
assertTrue(iterator.hasPrevious(), "No previous element for element '" + elements[i - 1] + "' at index: " + (i - 1));
|
||||
assertEquals(i < elements.length, iterator.hasNext());
|
||||
assertEquals(i - 1, iterator.previousIndex());
|
||||
assertEquals(i, iterator.nextIndex());
|
||||
@@ -339,18 +361,24 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeNull() {
|
||||
CollectionUtil.iterator(null, 0, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(null, 0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeBadStart() {
|
||||
CollectionUtil.iterator(stringObjects, stringObjects.length + 1, 2);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(stringObjects, stringObjects.length + 1, 2);
|
||||
});
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testArrayIteratorRangeBadLength() {
|
||||
CollectionUtil.iterator(stringObjects, 1, stringObjects.length);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.iterator(stringObjects, 1, stringObjects.length);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,9 +407,11 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReverseOrderNull() {
|
||||
CollectionUtil.reverseOrder(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CollectionUtil.reverseOrder(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,7 +461,7 @@ public class CollectionUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("For development only")
|
||||
@Disabled("For development only")
|
||||
@Test
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void testGenerify() {
|
||||
|
||||
@@ -45,11 +45,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests LRUMap.
|
||||
@@ -81,8 +80,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map2.put(4,"foo"); // removes 1 since max size exceeded
|
||||
map2.removeLRU(); // should be Integer(2)
|
||||
|
||||
assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo"));
|
||||
assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null);
|
||||
assertTrue(map2.get(new Integer(3)).equals("foo"), "Second to last value should exist");
|
||||
assertTrue(map2.get(new Integer(1)) == null, "First value inserted should not exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,8 +92,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"bar");
|
||||
|
||||
assertTrue("last value should exist",map2.get(new Integer(4)).equals("bar"));
|
||||
assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
|
||||
assertTrue(map2.get(new Integer(4)).equals("bar"), "last value should exist");
|
||||
assertTrue(map2.get(new Integer(1)) == null, "LRU should not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,10 +112,8 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
assertTrue("max size is 3, but actual size is " + map2.size(),
|
||||
map2.size() == 3);
|
||||
assertTrue("map should contain the Integer(4) object",
|
||||
map2.containsKey(new Integer(4)));
|
||||
assertTrue(map2.size() == 3, "max size is 3, but actual size is " + map2.size());
|
||||
assertTrue(map2.containsKey(new Integer(4)), "map should contain the Integer(4) object");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,8 +131,7 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
map.put("6","6");
|
||||
map.setMaxSize(3);
|
||||
|
||||
assertTrue("map should have size = 3, but actually = " + map.size(),
|
||||
map.size() == 3);
|
||||
assertTrue(map.size() == 3, "map should have size = 3, but actually = " + map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,9 +156,9 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
keys[i] = keyIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("first evicted should be 3, was " + keys[0], keys[0].equals("3"));
|
||||
assertTrue("second evicted should be 1, was " + keys[1], keys[1].equals("1"));
|
||||
assertTrue("third evicted should be 4, was " + keys[2], keys[2].equals("4"));
|
||||
assertTrue(keys[0].equals("3"), "first evicted should be 3, was " + keys[0]);
|
||||
assertTrue(keys[1].equals("1"), "second evicted should be 1, was " + keys[1]);
|
||||
assertTrue(keys[2].equals("4"), "third evicted should be 4, was " + keys[2]);
|
||||
|
||||
}
|
||||
|
||||
@@ -192,13 +188,12 @@ public class LRUMapTest extends LinkedMapTest {
|
||||
// 4 2
|
||||
counter.remove("5");
|
||||
|
||||
assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2);
|
||||
assertTrue("removedCount should be 3 but was " + counter.removedCount,
|
||||
counter.removedCount == 3);
|
||||
assertTrue(counter.size() == 2, "size should be 2, but was " + counter.size());
|
||||
assertTrue(counter.removedCount == 3, "removedCount should be 3 but was " + counter.removedCount);
|
||||
|
||||
assertTrue("first removed was '2'",counter.list.get(0).equals("2"));
|
||||
assertTrue("second removed was '3'",counter.list.get(1).equals("3"));
|
||||
assertTrue("third removed was '1'",counter.list.get(2).equals("1"));
|
||||
assertTrue(counter.list.get(0).equals("2"), "first removed was '2'");
|
||||
assertTrue(counter.list.get(1).equals("3"), "second removed was '3'");
|
||||
assertTrue(counter.list.get(2).equals("1"), "third removed was '1'");
|
||||
|
||||
//assertTrue("oldest key is '4'",counter.get(0).equals("4"));
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
|
||||
@@ -45,15 +45,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
@@ -74,7 +70,7 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
*/
|
||||
protected LinkedMap labRat;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
// use makeMap and cast the result to a SeqHashMap
|
||||
// so that subclasses of SeqHashMap can share these tests
|
||||
@@ -103,27 +99,21 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
}
|
||||
|
||||
// Test size().
|
||||
assertEquals("size() does not match expected size",
|
||||
expectedSize, labRat.size());
|
||||
assertEquals(expectedSize, labRat.size(), "size() does not match expected size");
|
||||
|
||||
// Test clone(), iterator(), and get(Object).
|
||||
LinkedMap clone = (LinkedMap) labRat.clone();
|
||||
assertEquals("Size of clone does not match original",
|
||||
labRat.size(), clone.size());
|
||||
assertEquals(labRat.size(), clone.size(), "Size of clone does not match original");
|
||||
Iterator origEntries = labRat.entrySet().iterator();
|
||||
Iterator copiedEntries = clone.entrySet().iterator();
|
||||
while (origEntries.hasNext()) {
|
||||
Map.Entry origEntry = (Map.Entry)origEntries.next();
|
||||
Map.Entry copiedEntry = (Map.Entry)copiedEntries.next();
|
||||
assertEquals("Cloned key does not match original",
|
||||
origEntry.getKey(), copiedEntry.getKey());
|
||||
assertEquals("Cloned value does not match original",
|
||||
origEntry.getValue(), copiedEntry.getValue());
|
||||
assertEquals("Cloned entry does not match original",
|
||||
origEntry, copiedEntry);
|
||||
assertEquals(origEntry.getKey(), copiedEntry.getKey(), "Cloned key does not match original");
|
||||
assertEquals(origEntry.getValue(), copiedEntry.getValue(), "Cloned value does not match original");
|
||||
assertEquals(origEntry, copiedEntry, "Cloned entry does not match original");
|
||||
}
|
||||
assertTrue("iterator() returned different number of elements than keys()",
|
||||
!copiedEntries.hasNext());
|
||||
assertTrue(!copiedEntries.hasNext(), "iterator() returned different number of elements than keys()");
|
||||
|
||||
// Test sequence()
|
||||
/*
|
||||
@@ -207,7 +197,7 @@ public class LinkedMapTest extends MapAbstractTest {
|
||||
}
|
||||
*/
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
labRat = null;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link java.util.Map} methods and contracts.
|
||||
@@ -390,19 +388,19 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
m.put(keys[i], values[i]);
|
||||
}
|
||||
catch (NullPointerException exception) {
|
||||
assertTrue("NullPointerException only allowed to be thrown if either the key or value is null.",
|
||||
keys[i] == null || values[i] == null);
|
||||
assertTrue(keys[i] == null || values[i] == null,
|
||||
"NullPointerException only allowed to be thrown if either the key or value is null.");
|
||||
|
||||
assertTrue("NullPointerException on null key, but isAllowNullKey is not overridden to return false.",
|
||||
keys[i] == null || !isAllowNullKey());
|
||||
assertTrue(keys[i] == null || !isAllowNullKey(),
|
||||
"NullPointerException on null key, but isAllowNullKey is not overridden to return false.");
|
||||
|
||||
assertTrue("NullPointerException on null value, but isAllowNullValue is not overridden to return false.",
|
||||
values[i] == null || !isAllowNullValue());
|
||||
assertTrue(values[i] == null || !isAllowNullValue(),
|
||||
"NullPointerException on null value, but isAllowNullValue is not overridden to return false.");
|
||||
|
||||
assertTrue("Unknown reason for NullPointer.", false);
|
||||
fail("Unknown reason for NullPointer.");
|
||||
}
|
||||
}
|
||||
assertEquals("size must reflect number of mappings added.", keys.length, m.size());
|
||||
assertEquals(keys.length, m.size(), "size must reflect number of mappings added.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -481,27 +479,26 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
Object[] newValues = getNewSampleValues();
|
||||
|
||||
assertTrue("failure in test: Must have keys returned from getSampleKeys.", keys != null);
|
||||
assertTrue("failure in test: Must have values returned from getSampleValues.", values != null);
|
||||
assertTrue(keys != null, "failure in test: Must have keys returned from getSampleKeys.");
|
||||
assertTrue(values != null, "failure in test: Must have values returned from getSampleValues.");
|
||||
|
||||
// verify keys and values have equivalent lengths (in case getSampleX are
|
||||
// overridden)
|
||||
assertEquals("failure in test: not the same number of sample keys and values.", keys.length, values.length);
|
||||
assertEquals("failure in test: not the same number of values and new values.", values.length, newValues.length);
|
||||
assertEquals(keys.length, values.length, "failure in test: not the same number of sample keys and values.");
|
||||
assertEquals(values.length, newValues.length, "failure in test: not the same number of values and new values.");
|
||||
|
||||
// verify there aren't duplicate keys, and check values
|
||||
for (int i = 0; i < keys.length - 1; i++) {
|
||||
for (int j = i + 1; j < keys.length; j++) {
|
||||
assertTrue("failure in test: duplicate null keys.", (keys[i] != null || keys[j] != null));
|
||||
assertTrue("failure in test: duplicate non-null key.",
|
||||
(keys[i] == null || keys[j] == null || (!keys[i].equals(keys[j]) && !keys[j].equals(keys[i]))));
|
||||
assertTrue((keys[i] != null || keys[j] != null), "failure in test: duplicate null keys.");
|
||||
assertTrue((keys[i] == null || keys[j] == null || (!keys[i].equals(keys[j]) && !keys[j].equals(keys[i]))),
|
||||
"failure in test: duplicate non-null key.");
|
||||
}
|
||||
|
||||
assertTrue("failure in test: found null key, but isNullKeySupported is false.", keys[i] != null || isAllowNullKey());
|
||||
assertTrue("failure in test: found null value, but isNullValueSupported is false.", values[i] != null || isAllowNullValue());
|
||||
assertTrue("failure in test: found null new value, but isNullValueSupported is false.", newValues[i] != null || isAllowNullValue());
|
||||
assertTrue("failure in test: values should not be the same as new value",
|
||||
values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])));
|
||||
assertTrue(keys[i] != null || isAllowNullKey(),"failure in test: found null key, but isNullKeySupported is false.");
|
||||
assertTrue(values[i] != null || isAllowNullValue(),"failure in test: found null value, but isNullValueSupported is false.");
|
||||
assertTrue(newValues[i] != null || isAllowNullValue(), "failure in test: found null new value, but isNullValueSupported is false.");
|
||||
assertTrue(values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])), "failure in test: values should not be the same as new value");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,18 +514,18 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMakeMap() {
|
||||
Map em = makeEmptyMap();
|
||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em != null);
|
||||
assertTrue(em != null, "failure in test: makeEmptyMap must return a non-null map.");
|
||||
|
||||
Map em2 = makeEmptyMap();
|
||||
assertTrue("failure in test: makeEmptyMap must return a non-null map.", em2 != null);
|
||||
assertTrue("failure in test: makeEmptyMap must return a new map with each invocation.", em != em2);
|
||||
assertTrue(em2 != null, "failure in test: makeEmptyMap must return a non-null map.");
|
||||
assertTrue(em != em2, "failure in test: makeEmptyMap must return a new map with each invocation.");
|
||||
|
||||
Map fm = makeFullMap();
|
||||
assertTrue("failure in test: makeFullMap must return a non-null map.", fm != null);
|
||||
assertTrue(fm != null, "failure in test: makeFullMap must return a non-null map.");
|
||||
|
||||
Map fm2 = makeFullMap();
|
||||
assertTrue("failure in test: makeFullMap must return a non-null map.", fm2 != null);
|
||||
assertTrue("failure in test: makeFullMap must return a new map with each invocation.", fm != fm2);
|
||||
assertTrue(fm2 != null, "failure in test: makeFullMap must return a non-null map.");
|
||||
assertTrue(fm != fm2, "failure in test: makeFullMap must return a new map with each invocation.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,11 +534,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map", true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(), "Map.isEmpty() should return true with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return false with a non-empty map", false, map.isEmpty());
|
||||
assertEquals(false, map.isEmpty(), "Map.isEmpty() should return false with a non-empty map");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -551,11 +548,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map", 0, map.size());
|
||||
assertEquals(0, map.size(), "Map.size() should be 0 with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries in the map", getSampleKeys().length, map.size());
|
||||
assertEquals(getSampleKeys().length, map.size(), "Map.size() should equal the number of entries in the map");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -602,13 +599,13 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||
assertTrue(!map.containsKey(key), "Map must not contain key when map is empty");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must contain key for a mapping in the map. Missing: " + key, map.containsKey(key));
|
||||
assertTrue(map.containsKey(key), "Map must contain key for a mapping in the map. Missing: " + key);
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -624,13 +621,13 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object value : values) {
|
||||
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||
assertTrue(!map.containsValue(value), "Empty map must not contain value");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (Object value : values) {
|
||||
assertTrue("Map must contain value for a mapping in the map.", map.containsValue(value));
|
||||
assertTrue(map.containsValue(value), "Map must contain value for a mapping in the map.");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -641,11 +638,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Empty maps unequal.");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Full maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Full maps unequal.");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
@@ -654,11 +651,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Iterator iter = confirmed.keySet().iterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
assertTrue("Different maps equal.", !map.equals(confirmed));
|
||||
assertTrue(!map.equals(confirmed), "Different maps equal.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("equals(null) returned true.", !map.equals(null));
|
||||
assertTrue("equals(new Object()) returned true.", !map.equals(new Object()));
|
||||
assertTrue(!map.equals(null), "equals(null) returned true.");
|
||||
assertTrue(!map.equals(new Object()), "equals(new Object()) returned true.");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -673,14 +670,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
|
||||
for (Object key : keys) {
|
||||
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||
assertTrue(map.get(key) == null, "Empty map.get() should return null.");
|
||||
}
|
||||
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
assertEquals("Full map.get() should return value from mapping.", values[i], map.get(keys[i]));
|
||||
assertEquals(values[i], map.get(keys[i]), "Full map.get() should return value from mapping.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,10 +687,10 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Empty maps have different hashCodes.");
|
||||
|
||||
resetFull();
|
||||
assertTrue("Equal maps have different hashCodes.", map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Equal maps have different hashCodes.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -708,11 +705,11 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
@Test
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||
assertTrue(map.toString() != null, "Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertTrue("Empty map toString() should not return null", map.toString() != null);
|
||||
assertTrue(map.toString() != null, "Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -776,29 +773,23 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
assertTrue("Map should contain key after put",
|
||||
map.containsKey(keys[i]));
|
||||
assertTrue("Map should contain value after put",
|
||||
map.containsValue(values[i]));
|
||||
assertTrue(o == null, "First map.put should return null");
|
||||
assertTrue(map.containsKey(keys[i]), "Map should contain key after put");
|
||||
assertTrue(map.containsValue(values[i]), "Map should contain value after put");
|
||||
}
|
||||
if (isPutChangeSupported()) {
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.put(keys[i], newValues[i]);
|
||||
confirmed.put(keys[i], newValues[i]);
|
||||
verifyAll();
|
||||
assertEquals("Map.put should return previous value when changed",
|
||||
values[i], o);
|
||||
assertTrue("Map should still contain key after put when changed",
|
||||
map.containsKey(keys[i]));
|
||||
assertTrue("Map should contain new value after put when changed",
|
||||
map.containsValue(newValues[i]));
|
||||
assertEquals(values[i], o, "Map.put should return previous value when changed");
|
||||
assertTrue(map.containsKey(keys[i]), "Map should still contain key after put when changed");
|
||||
assertTrue(map.containsValue(newValues[i]), "Map should contain new value after put when changed");
|
||||
|
||||
// if duplicates are allowed, we're not guaranteed that the value
|
||||
// no longer exists, so don't try checking that.
|
||||
if (!isAllowDuplicateValues()) {
|
||||
assertTrue("Map should not contain old value after put when changed",
|
||||
!map.containsValue(values[i]));
|
||||
assertTrue(!map.containsValue(values[i]), "Map should not contain old value after put when changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -832,18 +823,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object o = map.put(key, newValues[i]);
|
||||
Object value = confirmed.put(key, newValues[i]);
|
||||
verifyAll();
|
||||
assertEquals("Map.put should return previous value when changed",
|
||||
value, o);
|
||||
assertTrue("Map should still contain key after put when changed",
|
||||
map.containsKey(key));
|
||||
assertTrue("Map should contain new value after put when changed",
|
||||
map.containsValue(newValues[i]));
|
||||
assertEquals(value, o, "Map.put should return previous value when changed");
|
||||
assertTrue(map.containsKey(key), "Map should still contain key after put when changed");
|
||||
assertTrue(map.containsValue(newValues[i]), "Map should contain new value after put when changed");
|
||||
|
||||
// if duplicates are allowed, we're not guaranteed that the value
|
||||
// no longer exists, so don't try checking that.
|
||||
if (!isAllowDuplicateValues()) {
|
||||
assertTrue("Map should not contain old value after put when changed",
|
||||
!map.containsValue(values[i]));
|
||||
assertTrue(!map.containsValue(values[i]), "Map should not contain old value after put when changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -970,7 +957,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
Object[] values = getSampleValues();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
assertTrue(o == null, "First map.remove should return null");
|
||||
}
|
||||
verifyAll();
|
||||
|
||||
@@ -981,8 +968,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
confirmed.remove(keys[i]);
|
||||
verifyAll();
|
||||
|
||||
assertEquals("map.remove with valid key should return value",
|
||||
values[i], o);
|
||||
assertEquals(values[i], o, "map.remove with valid key should return value");
|
||||
}
|
||||
|
||||
Object[] other = getOtherKeys();
|
||||
@@ -991,10 +977,8 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
int size = map.size();
|
||||
for (int i = 0; i < other.length; i++) {
|
||||
Object o = map.remove(other[i]);
|
||||
assertEquals("map.remove for nonexistent key should return null",
|
||||
o, null);
|
||||
assertEquals("map.remove for nonexistent key should not " +
|
||||
"shrink map", size, map.size());
|
||||
assertEquals(o, null, "map.remove for nonexistent key should return null");
|
||||
assertEquals(size, map.size(), "map.remove for nonexistent key should not shrink map");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -1204,10 +1188,9 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
}
|
||||
j++;
|
||||
}
|
||||
assertTrue("values().remove(obj) is broken", j < 10000);
|
||||
assertTrue(
|
||||
"Value should have been removed from the underlying map.",
|
||||
!map.containsValue(sampleValues[i]));
|
||||
assertTrue(j < 10000, "values().remove(obj) is broken");
|
||||
assertTrue(!map.containsValue(sampleValues[i]),
|
||||
"Value should have been removed from the underlying map.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1230,9 +1213,8 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
// if key.remove is unsupported, just skip this test
|
||||
return;
|
||||
}
|
||||
assertTrue(
|
||||
"Key should have been removed from the underlying map.",
|
||||
!map.containsKey(sampleKeys[i]));
|
||||
assertTrue(!map.containsKey(sampleKeys[i]),
|
||||
"Key should have been removed from the underlying map.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1413,7 +1395,7 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull("No matching entry in map for key '" + key + "'", entry);
|
||||
assertNotNull(entry, "No matching entry in map for key '" + key + "'");
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -1638,14 +1620,14 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
public void verifyMap() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("Map should be same size as HashMap", size, map.size());
|
||||
assertEquals("Map should be empty if HashMap is", empty, map.isEmpty());
|
||||
assertEquals("hashCodes should be the same", confirmed.hashCode(), map.hashCode());
|
||||
assertEquals(size, map.size(), "Map should be same size as HashMap");
|
||||
assertEquals(empty, map.isEmpty(), "Map should be empty if HashMap is");
|
||||
assertEquals(confirmed.hashCode(), map.hashCode(), "hashCodes should be the same");
|
||||
// this fails for LRUMap because confirmed.equals() somehow modifies
|
||||
// map, causing concurrent modification exceptions.
|
||||
//assertEquals("Map should still equal HashMap", confirmed, map);
|
||||
// this works though and performs the same verification:
|
||||
assertTrue("Map should still equal HashMap", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Map should still equal HashMap");
|
||||
// TODO: this should really be reexamined to figure out why LRU map
|
||||
// behaves like it does (the equals shouldn't modify since all accesses
|
||||
// by the confirmed collection should be through an iterator, thus not
|
||||
@@ -1655,29 +1637,29 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
public void verifyEntrySet() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("entrySet should be same size as HashMap's\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
size, entrySet.size());
|
||||
assertEquals("entrySet should be empty if HashMap is\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
empty, entrySet.isEmpty());
|
||||
assertTrue("entrySet should contain all HashMap's elements\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
entrySet.containsAll(confirmed.entrySet()));
|
||||
assertEquals("entrySet hashCodes should be the same\nTest: " + entrySet + "\nReal: " + confirmed.entrySet(),
|
||||
confirmed.entrySet().hashCode(), entrySet.hashCode());
|
||||
assertEquals("Map's entry set should still equal HashMap's", confirmed.entrySet(), entrySet);
|
||||
assertEquals(size, entrySet.size(),
|
||||
"entrySet should be same size as HashMap's\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(empty, entrySet.isEmpty(),
|
||||
"entrySet should be empty if HashMap is\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertTrue(entrySet.containsAll(confirmed.entrySet()),
|
||||
"entrySet should contain all HashMap's elements\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(confirmed.entrySet().hashCode(), entrySet.hashCode(),
|
||||
"entrySet hashCodes should be the same\nTest: " + entrySet + "\nReal: " + confirmed.entrySet());
|
||||
assertEquals(confirmed.entrySet(), entrySet,"Map's entry set should still equal HashMap's");
|
||||
}
|
||||
|
||||
public void verifyKeySet() {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
assertEquals("keySet should be same size as HashMap's\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
size, keySet.size());
|
||||
assertEquals("keySet should be empty if HashMap is\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
empty, keySet.isEmpty());
|
||||
assertTrue("keySet should contain all HashMap's elements\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
keySet.containsAll(confirmed.keySet()));
|
||||
assertEquals("keySet hashCodes should be the same\nTest: " + keySet + "\nReal: " + confirmed.keySet(),
|
||||
confirmed.keySet().hashCode(), keySet.hashCode());
|
||||
assertEquals("Map's key set should still equal HashMap's", confirmed.keySet(), keySet);
|
||||
assertEquals(size, keySet.size(),
|
||||
"keySet should be same size as HashMap's\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(empty, keySet.isEmpty(),
|
||||
"keySet should be empty if HashMap is\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertTrue(keySet.containsAll(confirmed.keySet()),
|
||||
"keySet should contain all HashMap's elements\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(confirmed.keySet().hashCode(), keySet.hashCode(),
|
||||
"keySet hashCodes should be the same\nTest: " + keySet + "\nReal: " + confirmed.keySet());
|
||||
assertEquals(confirmed.keySet(), keySet, "Map's key set should still equal HashMap's");
|
||||
}
|
||||
|
||||
public void verifyValues() {
|
||||
@@ -1687,23 +1669,23 @@ public abstract class MapAbstractTest extends ObjectAbstractTest {
|
||||
int size = confirmed.size();
|
||||
boolean empty = confirmed.isEmpty();
|
||||
|
||||
assertEquals("values should be same size as HashMap's\nTest: " + test + "\nReal: " + known, size, values.size());
|
||||
assertEquals("values should be empty if HashMap is\nTest: " + test + "\nReal: " + known, empty, values.isEmpty());
|
||||
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, test.containsAll(known));
|
||||
assertTrue("values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known, known.containsAll(test));
|
||||
assertEquals(size, values.size(), "values should be same size as HashMap's\nTest: " + test + "\nReal: " + known);
|
||||
assertEquals(empty, values.isEmpty(), "values should be empty if HashMap is\nTest: " + test + "\nReal: " + known);
|
||||
assertTrue(test.containsAll(known), "values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known);
|
||||
assertTrue(known.containsAll(test), "values should contain all HashMap's elements\nTest: " + test + "\nReal: " + known);
|
||||
|
||||
for (Object aKnown : known) {
|
||||
boolean removed = test.remove(aKnown);
|
||||
assertTrue("Map's values should still equal HashMap's", removed);
|
||||
assertTrue(removed, "Map's values should still equal HashMap's");
|
||||
}
|
||||
|
||||
assertTrue("Map's values should still equal HashMap's", test.isEmpty());
|
||||
assertTrue(test.isEmpty(), "Map's values should still equal HashMap's");
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases any leftover instance variables by setting them to null.
|
||||
*/
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
map = null;
|
||||
keySet = null;
|
||||
|
||||
@@ -30,13 +30,11 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* NOTE: This TestCase is written especially for NullMap, and is full of dirty
|
||||
@@ -83,12 +81,12 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapIsEmpty() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.isEmpty() should return true with an empty map",
|
||||
true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(),
|
||||
"Map.isEmpty() should return true with an empty map");
|
||||
verifyAll();
|
||||
resetFull();
|
||||
assertEquals("Map.isEmpty() should return true with a full map",
|
||||
true, map.isEmpty());
|
||||
assertEquals(true, map.isEmpty(),
|
||||
"Map.isEmpty() should return true with a full map");
|
||||
}
|
||||
|
||||
// Overriden, as this map is always empty
|
||||
@@ -96,13 +94,13 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapSize() {
|
||||
resetEmpty();
|
||||
assertEquals("Map.size() should be 0 with an empty map",
|
||||
0, map.size());
|
||||
assertEquals(0, map.size(),
|
||||
"Map.size() should be 0 with an empty map");
|
||||
verifyAll();
|
||||
|
||||
resetFull();
|
||||
assertEquals("Map.size() should equal the number of entries " +
|
||||
"in the map", 0, map.size());
|
||||
assertEquals(0, map.size(),
|
||||
"Map.size() should equal the number of entries in the map");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +110,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object key : keys) {
|
||||
assertTrue("Map must not contain key when map is empty", !map.containsKey(key));
|
||||
assertTrue(!map.containsKey(key),"Map must not contain key when map is empty");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -124,7 +122,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
|
||||
resetEmpty();
|
||||
for (Object value : values) {
|
||||
assertTrue("Empty map must not contain value", !map.containsValue(value));
|
||||
assertTrue(!map.containsValue(value), "Empty map must not contain value");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -133,7 +131,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapEquals() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps unequal.", map.equals(confirmed));
|
||||
assertTrue(map.equals(confirmed), "Empty maps unequal.");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -141,8 +139,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapHashCode() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty maps have different hashCodes.",
|
||||
map.hashCode() == confirmed.hashCode());
|
||||
assertTrue(map.hashCode() == confirmed.hashCode(), "Empty maps have different hashCodes.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +150,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object[] keys = getSampleKeys();
|
||||
|
||||
for (Object key : keys) {
|
||||
assertTrue("Empty map.get() should return null.", map.get(key) == null);
|
||||
assertTrue(map.get(key) == null, "Empty map.get() should return null.");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
@@ -170,7 +167,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object o = map.put(keys[i], values[i]);
|
||||
//confirmed.put(keys[i], values[i]);
|
||||
verifyAll();
|
||||
assertTrue("First map.put should return null", o == null);
|
||||
assertTrue(o == null, "First map.put should return null");
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
map.put(keys[i], newValues[i]);
|
||||
@@ -183,8 +180,8 @@ public class NullMapTest extends MapAbstractTest {
|
||||
@Override
|
||||
public void testMapToString() {
|
||||
resetEmpty();
|
||||
assertTrue("Empty map toString() should not return null",
|
||||
map.toString() != null);
|
||||
assertTrue(map.toString() != null,
|
||||
"Empty map toString() should not return null");
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -202,7 +199,7 @@ public class NullMapTest extends MapAbstractTest {
|
||||
Object[] keys = getSampleKeys();
|
||||
for(int i = 0; i < keys.length; i++) {
|
||||
Object o = map.remove(keys[i]);
|
||||
assertTrue("First map.remove should return null", o == null);
|
||||
assertTrue(o == null, "First map.remove should return null");
|
||||
}
|
||||
verifyAll();
|
||||
}
|
||||
|
||||
@@ -44,12 +44,10 @@
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Object} methods and contracts.
|
||||
@@ -119,7 +117,7 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectEqualsSelf() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("A Object should equal itself", obj, obj);
|
||||
assertEquals(obj, obj, "A Object should equal itself");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,25 +129,24 @@ public abstract class ObjectAbstractTest {
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsSelfHashCode() {
|
||||
Object obj = makeObject();
|
||||
assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
|
||||
assertEquals(obj.hashCode(), obj.hashCode(), "hashCode should be repeatable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectHashCodeEqualsContract() {
|
||||
Object obj1 = makeObject();
|
||||
if (obj1.equals(obj1)) {
|
||||
assertEquals(
|
||||
"[1] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj1.hashCode());
|
||||
assertEquals(obj1.hashCode(), obj1.hashCode(),
|
||||
"[1] When two objects are equal, their hashCodes should be also.");
|
||||
}
|
||||
Object obj2 = makeObject();
|
||||
if (obj1.equals(obj2)) {
|
||||
assertEquals(
|
||||
"[2] When two objects are equal, their hashCodes should be also.",
|
||||
obj1.hashCode(), obj2.hashCode());
|
||||
obj1.hashCode(), obj2.hashCode(),
|
||||
"[2] When two objects are equal, their hashCodes should be also.");
|
||||
assertTrue(
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true",
|
||||
obj2.equals(obj1));
|
||||
obj2.equals(obj1),
|
||||
"When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +163,7 @@ public abstract class ObjectAbstractTest {
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
if (isEqualsCheckable()) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
assertEquals(obj, dest, "obj != deserialize(serialize(obj))");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,8 +196,8 @@ public abstract class ObjectAbstractTest {
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalEmptyCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical empty collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
new File(name).exists(),
|
||||
"Canonical empty collection (" + name + ") is not in CVS");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,8 +213,8 @@ public abstract class ObjectAbstractTest {
|
||||
if (object instanceof Serializable) {
|
||||
String name = getCanonicalFullCollectionName(object);
|
||||
assertTrue(
|
||||
"Canonical full collection (" + name + ") is not in CVS",
|
||||
new File(name).exists());
|
||||
new File(name).exists(),
|
||||
"Canonical full collection (" + name + ") is not in CVS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,10 @@
|
||||
*/
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Abstract test class for {@link Set} methods and contracts.
|
||||
@@ -79,14 +77,12 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
public void verifyAll() {
|
||||
super.verifyAll();
|
||||
|
||||
assertEquals("Sets should be equal", confirmed, collection);
|
||||
assertEquals("Sets should have equal hashCodes",
|
||||
confirmed.hashCode(), collection.hashCode());
|
||||
assertEquals(confirmed, collection, "Sets should be equal");
|
||||
assertEquals(confirmed.hashCode(), collection.hashCode(), "Sets should have equal hashCodes");
|
||||
Collection set = makeConfirmedCollection();
|
||||
Iterator iterator = collection.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
assertTrue("Set.iterator should only return unique elements",
|
||||
set.add(iterator.next()));
|
||||
assertTrue(set.add(iterator.next()), "Set.iterator should only return unique elements");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,23 +176,20 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
@Test
|
||||
public void testSetEquals() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets should be equal",
|
||||
getSet(), getConfirmedSet());
|
||||
assertEquals(getSet(), getConfirmedSet(), "Empty sets should be equal");
|
||||
verifyAll();
|
||||
|
||||
Collection set2 = makeConfirmedCollection();
|
||||
set2.add("foo");
|
||||
assertTrue("Empty set shouldn't equal nonempty set",
|
||||
!getSet().equals(set2));
|
||||
assertTrue(!getSet().equals(set2), "Empty set shouldn't equal nonempty set");
|
||||
|
||||
resetFull();
|
||||
assertEquals("Full sets should be equal", getSet(), getConfirmedSet());
|
||||
assertEquals(getSet(), getConfirmedSet(), "Full sets should be equal");
|
||||
verifyAll();
|
||||
|
||||
set2.clear();
|
||||
set2.addAll(Arrays.asList(getOtherElements()));
|
||||
assertTrue("Sets with different contents shouldn't be equal",
|
||||
!getSet().equals(set2));
|
||||
assertTrue(!getSet().equals(set2), "Sets with different contents shouldn't be equal");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,11 +198,9 @@ public abstract class SetAbstractTest extends CollectionAbstractTest {
|
||||
@Test
|
||||
public void testSetHashCode() {
|
||||
resetEmpty();
|
||||
assertEquals("Empty sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
assertEquals(getSet().hashCode(), getConfirmedSet().hashCode(), "Empty sets have equal hashCodes");
|
||||
|
||||
resetFull();
|
||||
assertEquals("Equal sets have equal hashCodes",
|
||||
getSet().hashCode(), getConfirmedSet().hashCode());
|
||||
assertEquals(getSet().hashCode(), getConfirmedSet().hashCode(), "Equal sets have equal hashCodes");
|
||||
}
|
||||
}
|
||||
|
||||
+30
-32
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
@@ -56,88 +54,88 @@ public class StringTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("", "");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "Empty string has elements");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenEmptyDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", ",");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", " ,.;:");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* TimeoutMapTest
|
||||
* <p/>
|
||||
@@ -541,7 +539,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -573,7 +571,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -613,7 +611,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Elements expired too early, test did not run as expected.", count > 0);
|
||||
assertTrue(count > 0, "Elements expired too early, test did not run as expected.");
|
||||
//assertEquals("Elements did not expire as expected.", 1, count);
|
||||
}
|
||||
|
||||
@@ -630,7 +628,7 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
Object removedKey = null;
|
||||
Object otherKey = null;
|
||||
Iterator iterator = map.entrySet().iterator();
|
||||
assertTrue("Iterator was empty", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "Iterator was empty");
|
||||
try {
|
||||
Map.Entry entry = (Map.Entry) iterator.next();
|
||||
assertNotNull(entry);
|
||||
@@ -648,8 +646,8 @@ public class TimeoutMapTest extends MapAbstractTest {
|
||||
fail("Elements expired between Interator.hasNext() and Iterator.remove()");
|
||||
}
|
||||
|
||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", !map.containsKey(removedKey));
|
||||
assertTrue("Wrong entry removed, keySet().iterator() is broken.", map.containsKey(otherKey));
|
||||
assertTrue(!map.containsKey(removedKey), "Wrong entry removed, keySet().iterator() is broken.");
|
||||
assertTrue(map.containsKey(otherKey), "Wrong entry removed, keySet().iterator() is broken.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-5
@@ -30,12 +30,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* TokenIteratorAbstractTestCase
|
||||
@@ -80,7 +78,7 @@ public abstract class TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testEmptyString() {
|
||||
Iterator iterator = createTokenIterator("");
|
||||
assertFalse("Empty string has elements", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "Empty string has elements");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ConverterTest
|
||||
@@ -43,7 +43,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class ConverterTest {
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@Disabled("Not implemented")
|
||||
@Test
|
||||
public void testMe() {
|
||||
// TODO: Implement tests
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.DateUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
+4
-4
@@ -31,13 +31,13 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* DefaultConverterTest
|
||||
@@ -138,7 +138,7 @@ public class DefaultConverterTest extends PropertyConverterAbstractTest {
|
||||
assertEquals(-2.3456, (Double) converter.toObject("-2.3456", Double.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Ignore("Known issue. Why would anyone do something like this?")
|
||||
@Disabled("Known issue. Why would anyone do something like this?")
|
||||
@Test
|
||||
public void testConvertCharPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
|
||||
+16
-16
@@ -32,11 +32,11 @@ package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.ObjectAbstractTest;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PropertyConverterAbstractTest
|
||||
@@ -66,26 +66,26 @@ public abstract class PropertyConverterAbstractTest extends ObjectAbstractTest {
|
||||
try {
|
||||
obj = converter.toObject(test.original(), test.type(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
assertEquals(test.type(), obj.getClass(), String.format("'%s' converted to incorrect type", test.original()));
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' not converted", test.original()), test.value(), obj);
|
||||
assertEquals(test.value(), obj, String.format("'%s' not converted", test.original()));
|
||||
}
|
||||
|
||||
String result = converter.toString(test.value(), test.format());
|
||||
|
||||
assertEquals(String.format("'%s' does not match", test.converted()), test.converted(), result);
|
||||
assertEquals(test.converted(), result, String.format("'%s' does not match", test.converted()));
|
||||
|
||||
obj = converter.toObject(result, test.type(), test.format());
|
||||
assertEquals(String.format("'%s' converted to incorrect type", test.original()), test.type(), obj.getClass());
|
||||
assertEquals(test.type(), obj.getClass(), String.format("'%s' converted to incorrect type", test.original()));
|
||||
|
||||
if (test.type().isArray()) {
|
||||
assertArrayEquals0(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
}
|
||||
else {
|
||||
assertEquals(String.format("'%s' did not survive round trip conversion", test.original()), test.value(), obj);
|
||||
assertEquals(test.value(), obj, String.format("'%s' did not survive round trip conversion", test.original()));
|
||||
}
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
@@ -98,35 +98,35 @@ public abstract class PropertyConverterAbstractTest extends ObjectAbstractTest {
|
||||
Class<?> componentType = left.getClass().getComponentType();
|
||||
if (componentType.isPrimitive()) {
|
||||
if (int.class == componentType) {
|
||||
assertArrayEquals(message, (int[]) left, (int[]) right);
|
||||
assertArrayEquals((int[]) left, (int[]) right, message);
|
||||
}
|
||||
else if (short.class == componentType) {
|
||||
assertArrayEquals(message, (short[]) left, (short[]) right);
|
||||
assertArrayEquals((short[]) left, (short[]) right, message);
|
||||
}
|
||||
else if (long.class == componentType) {
|
||||
assertArrayEquals(message, (long[]) left, (long[]) right);
|
||||
assertArrayEquals((long[]) left, (long[]) right, message);
|
||||
}
|
||||
else if (float.class == componentType) {
|
||||
assertArrayEquals(message, (float[]) left, (float[]) right, 0f);
|
||||
assertArrayEquals((float[]) left, (float[]) right, 0f, message);
|
||||
}
|
||||
else if (double.class == componentType) {
|
||||
assertArrayEquals(message, (double[]) left, (double[]) right, 0d);
|
||||
assertArrayEquals((double[]) left, (double[]) right, 0d, message);
|
||||
}
|
||||
else if (boolean.class == componentType) {
|
||||
assertTrue(message, Arrays.equals((boolean[]) left, (boolean[]) right));
|
||||
assertTrue(Arrays.equals((boolean[]) left, (boolean[]) right), message);
|
||||
}
|
||||
else if (byte.class == componentType) {
|
||||
assertArrayEquals(message, (byte[]) left, (byte[]) right);
|
||||
assertArrayEquals((byte[]) left, (byte[]) right, message);
|
||||
}
|
||||
else if (char.class == componentType) {
|
||||
assertArrayEquals(message, (char[]) left, (char[]) right);
|
||||
assertArrayEquals((char[]) left, (char[]) right, message);
|
||||
}
|
||||
else {
|
||||
fail(String.format("Unknown primitive type: %s", componentType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
assertArrayEquals(message, (Object[]) left, (Object[]) right);
|
||||
assertArrayEquals((Object[]) left, (Object[]) right, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-28
@@ -32,12 +32,11 @@ package com.twelvemonkeys.util.regex;
|
||||
|
||||
import com.twelvemonkeys.util.TokenIterator;
|
||||
import com.twelvemonkeys.util.TokenIteratorAbstractTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
/**
|
||||
* StringTokenIteratorTestCase
|
||||
* <p/>
|
||||
@@ -68,9 +67,9 @@ public class RegExTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testSingleToken() {
|
||||
Iterator iterator = createTokenIterator("A");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,67 +86,67 @@ public class RegExTokenIteratorTest extends TokenIteratorAbstractTest {
|
||||
@Test
|
||||
public void testSingleTokenSingleDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C D");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,C", "[^,]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparatorDefaultDelimiter() {
|
||||
Iterator iterator = createTokenIterator("A B C\nD\t\t \nE");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("A", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSeparator() {
|
||||
Iterator iterator = createTokenIterator("A,B,;,C...D, ., ,E", "[^ ,.;:]+");
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
Object o = iterator.next();
|
||||
assertEquals("A", o);
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("B", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("C", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("D", iterator.next());
|
||||
assertTrue("String has no elements", iterator.hasNext());
|
||||
assertTrue(iterator.hasNext(), "String has no elements");
|
||||
assertEquals("E", iterator.next());
|
||||
assertFalse("String has more than one element", iterator.hasNext());
|
||||
assertFalse(iterator.hasNext(), "String has more than one element");
|
||||
}
|
||||
}
|
||||
|
||||
+12
-8
@@ -30,12 +30,13 @@
|
||||
|
||||
package com.twelvemonkeys.util.service;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import com.twelvemonkeys.util.CollectionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* ServiceRegistryTest
|
||||
@@ -48,9 +49,11 @@ public class ServiceRegistryTest {
|
||||
|
||||
private final TestRegistry registry = new TestRegistry();
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new ServiceRegistry(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new ServiceRegistry(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,11 +67,12 @@ public class ServiceRegistryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ServiceConfigurationError.class)
|
||||
@Test
|
||||
public void testCreateBadConfig() {
|
||||
@SuppressWarnings("unchecked")
|
||||
ServiceRegistry registry = new ServiceRegistry(Arrays.asList(BadSPI.class).iterator());
|
||||
registry.registerApplicationClasspathSPIs();
|
||||
assertThrows(ServiceConfigurationError.class, () -> {
|
||||
ServiceRegistry registry = new ServiceRegistry(Arrays.asList(BadSPI.class).iterator());
|
||||
registry.registerApplicationClasspathSPIs();
|
||||
});
|
||||
|
||||
// DONE: Test non-class
|
||||
|
||||
|
||||
+15
-4
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys</groupId>
|
||||
<artifactId>twelvemonkeys</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.twelvemonkeys.common</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
@@ -20,6 +20,10 @@
|
||||
<module>common-image</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<junit.jupiter.version>5.14.2</junit.jupiter.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -43,11 +47,18 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+15
-5
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys</groupId>
|
||||
<artifactId>twelvemonkeys</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.twelvemonkeys.contrib</groupId>
|
||||
<artifactId>contrib</artifactId>
|
||||
@@ -13,6 +13,11 @@
|
||||
Contributions to TwelveMonkeys and code that doesn't fit anywhere else.
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<junit.jupiter.version>5.14.2</junit.jupiter.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.common</groupId>
|
||||
@@ -61,11 +66,16 @@
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.twelvemonkeys.contrib.exif;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.twelvemonkeys.contrib.exif.Orientation.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* OrientationTest.
|
||||
|
||||
@@ -34,8 +34,6 @@ import com.twelvemonkeys.contrib.tiff.TIFFUtilities.TIFFExtension;
|
||||
import com.twelvemonkeys.imageio.plugins.tiff.TIFFImageMetadataFormat;
|
||||
import com.twelvemonkeys.io.FileUtil;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -54,6 +52,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* TIFFUtilitiesTest
|
||||
*
|
||||
@@ -95,7 +96,7 @@ public class TIFFUtilitiesTest {
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(output);
|
||||
ImageReader reader = ImageIO.getImageReaders(iis).next();
|
||||
reader.setInput(iis);
|
||||
Assert.assertEquals(3, reader.getNumImages(true));
|
||||
assertEquals(3, reader.getNumImages(true));
|
||||
|
||||
iis.close();
|
||||
output.delete();
|
||||
@@ -119,11 +120,11 @@ public class TIFFUtilitiesTest {
|
||||
ImageReader reader = ImageIO.getImageReadersByFormatName("TIF").next();
|
||||
|
||||
File[] outputFiles = outputDirectory.listFiles();
|
||||
Assert.assertEquals(3, outputFiles.length);
|
||||
assertEquals(3, outputFiles.length);
|
||||
for (File outputFile : outputFiles) {
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(outputFile);
|
||||
reader.setInput(iis);
|
||||
Assert.assertEquals(1, reader.getNumImages(true));
|
||||
assertEquals(1, reader.getNumImages(true));
|
||||
iis.close();
|
||||
outputFile.delete();
|
||||
}
|
||||
@@ -157,7 +158,7 @@ public class TIFFUtilitiesTest {
|
||||
Node metaData = reader.getImageMetadata(i)
|
||||
.getAsTree(TIFFImageMetadataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
||||
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
||||
Assert.assertEquals(orientation, TIFFExtension.ORIENTATION_RIGHTTOP);
|
||||
assertEquals(orientation, TIFFExtension.ORIENTATION_RIGHTTOP);
|
||||
}
|
||||
checkTest1.close();
|
||||
|
||||
@@ -174,7 +175,7 @@ public class TIFFUtilitiesTest {
|
||||
Node metaData = reader.getImageMetadata(i)
|
||||
.getAsTree(TIFFImageMetadataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME);
|
||||
short orientation = ((Number) expression.evaluate(metaData, XPathConstants.NUMBER)).shortValue();
|
||||
Assert.assertEquals(orientation, i == 1
|
||||
assertEquals(orientation, i == 1
|
||||
? TIFFExtension.ORIENTATION_BOTRIGHT
|
||||
: TIFFExtension.ORIENTATION_RIGHTTOP);
|
||||
}
|
||||
@@ -199,7 +200,7 @@ public class TIFFUtilitiesTest {
|
||||
byte[] original = ((DataBufferByte) image.getData().getDataBuffer()).getData();
|
||||
byte[] rotated = ((DataBufferByte) image360.getData().getDataBuffer()).getData();
|
||||
|
||||
Assert.assertArrayEquals(original, rotated);
|
||||
assertArrayEquals(original, rotated);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>imageio-batik</artifactId>
|
||||
<name>TwelveMonkeys :: ImageIO :: Batik Plugin</name>
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
<properties>
|
||||
<project.jpms.module.name>com.twelvemonkeys.imageio.batik</project.jpms.module.name>
|
||||
<batik.version>1.17</batik.version>
|
||||
<batik.version>1.19</batik.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.15.0</version>
|
||||
<version>2.21.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
+46
-1
@@ -36,9 +36,11 @@ import com.twelvemonkeys.lang.SystemUtil;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.twelvemonkeys.imageio.util.IIOUtil.deregisterProvider;
|
||||
|
||||
@@ -134,10 +136,42 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
|
||||
if (buffer[0] == 's' && buffer[1] == 'v' && buffer[2] == 'g'
|
||||
&& (Character.isWhitespace((char) buffer[3]) || buffer[3] == ':')) {
|
||||
// It's SVG, identified by root tag
|
||||
// TODO: Support svg with prefix + recognize namespace (http://www.w3.org/2000/svg)!
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read the full tag name (may contain a prefix of any length)
|
||||
final int MAX_TAG_NAME = 256;
|
||||
ByteArrayOutputStream nameBuf = new ByteArrayOutputStream(MAX_TAG_NAME);
|
||||
|
||||
// We already have 4 bytes in 'buffer' (from input.readFully(buffer))
|
||||
int consumedFromBuffer = 0;
|
||||
for (; consumedFromBuffer < buffer.length; consumedFromBuffer++) {
|
||||
byte bb = buffer[consumedFromBuffer];
|
||||
if (bb == '>' || Character.isWhitespace((char) bb) || bb == '/') {
|
||||
break;
|
||||
}
|
||||
nameBuf.write(bb);
|
||||
}
|
||||
|
||||
// If tag name not terminated yet, keep reading bytes (within limit)
|
||||
final boolean incompleteTagName = consumedFromBuffer == buffer.length;
|
||||
readBuffer(input, nameBuf, output -> incompleteTagName && output.size() < MAX_TAG_NAME,
|
||||
bb -> bb == '>' || Character.isWhitespace(bb) || bb == '/');
|
||||
|
||||
final String name = nameBuf.toString("US-ASCII");
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(":svg")) {
|
||||
// Scan the rest of the tag attributes until '>' to find the SVG namespace URI
|
||||
ByteArrayOutputStream attrBuf = new ByteArrayOutputStream();
|
||||
final int MAX_ATTR_SCAN = 1024; // safe upper bound to keep it fast
|
||||
readBuffer(input, attrBuf, output -> output.size() < MAX_ATTR_SCAN, bb -> bb == '>');
|
||||
|
||||
// If the tag contains the SVG namespace, it's SVG.
|
||||
if (attrBuf.toString("US-ASCII").matches(
|
||||
".*xmlns:" + name.split(":")[0] + "\\s*=\\s*\"http://www.w3.org/2000/svg\".*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the tag is not "svg", this isn't SVG
|
||||
return false;
|
||||
}
|
||||
@@ -157,6 +191,17 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void readBuffer(final ImageInputStream input, final ByteArrayOutputStream buffer,
|
||||
final Predicate<ByteArrayOutputStream> loopCondition, Predicate<Byte> breakCondition) throws IOException {
|
||||
while (loopCondition.test(buffer)) {
|
||||
byte bb = input.readByte();
|
||||
if (breakCondition.test(bb)) {
|
||||
break;
|
||||
}
|
||||
buffer.write(bb);
|
||||
}
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(final Object extension) throws IOException {
|
||||
return new SVGImageReader(this);
|
||||
}
|
||||
|
||||
+15
-10
@@ -32,16 +32,16 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* SVGImageReaderSpiTest.
|
||||
@@ -56,7 +56,7 @@ public class SVGImageReaderSpiTest {
|
||||
"/svg/Android_robot.svg", // Minimal, no xml dec, no namespace
|
||||
"/svg/batikLogo.svg", // xml dec, comments, namespace
|
||||
"/svg/blue-square.svg", // xml dec, namespace
|
||||
"/svg/red-square.svg",
|
||||
"/svg/red-square.svg", // prefixed namespace
|
||||
};
|
||||
|
||||
private static final String[] INVALID_INPUTS = {
|
||||
@@ -70,6 +70,9 @@ public class SVGImageReaderSpiTest {
|
||||
"<!-- ", // #275 Infinite loop issue
|
||||
"<?123?>", // #275 Infinite loop issue
|
||||
"<svg",
|
||||
"<ns0:svg>", // namespace prefix undefined
|
||||
"<ns0:svg xmlns:ns0=\"foo\">", // not the official svg namespace
|
||||
"<ns0:svg xmlns:ns1=\"http://www.w3.org/2000/svg\">", // mismatching prefix
|
||||
};
|
||||
|
||||
static {
|
||||
@@ -83,18 +86,20 @@ public class SVGImageReaderSpiTest {
|
||||
public void canDecodeInput() throws Exception {
|
||||
for (String validInput : VALID_INPUTS) {
|
||||
try (ImageInputStream input = ImageIO.createImageInputStream(getClass().getResource(validInput))) {
|
||||
assertTrue("Can't read valid input: " + validInput, provider.canDecodeInput(input));
|
||||
assertTrue(provider.canDecodeInput(input), "Can't read valid input: " + validInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test will time out, if EOFs are not properly detected, see #275
|
||||
@Test(timeout = 5000)
|
||||
@Test
|
||||
public void canDecodeInputInvalid() throws Exception {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse("Claims to read invalid input:" + invalidInput, provider.canDecodeInput(input));
|
||||
assertTimeoutPreemptively(Duration.ofMillis(5000), () -> {
|
||||
for (String invalidInput : INVALID_INPUTS) {
|
||||
try (ImageInputStream input = new ByteArrayImageInputStream(invalidInput.getBytes(StandardCharsets.UTF_8))) {
|
||||
assertFalse(provider.canDecodeInput(input), "Claims to read invalid input:" + invalidInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+13
-15
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
@@ -52,10 +49,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@@ -128,18 +124,18 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
int current = image.getRGB(x, y);
|
||||
if (x < quadPoint) {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF0000FF, current);
|
||||
assertEquals( 0xFF0000FF, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFFFF0000, current);
|
||||
assertEquals(0xFFFF0000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (y < quadPoint) {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF00FF00, current);
|
||||
assertEquals(0xFF00FF00, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
else {
|
||||
assertEquals("x=" + x + " y=" + y + " q=" + quadPoint, 0xFF000000, current);
|
||||
assertEquals(0xFF000000, current, "x=" + x + " y=" + y + " q=" + quadPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,14 +167,14 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
@@ -316,7 +312,7 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SecurityException.class)
|
||||
@Test
|
||||
public void testDisallowedExternalResources() throws URISyntaxException, IOException {
|
||||
// system-property set to true in surefire-plugin-settings in the pom
|
||||
URL resource = getClassLoaderResource("/svg/barChart.svg");
|
||||
@@ -333,7 +329,9 @@ public class SVGImageReaderTest extends ImageReaderAbstractTest<SVGImageReader>
|
||||
// `reader.read` for `/svg/barChart.svg` should raise
|
||||
// a SecurityException when External Resources are blocked
|
||||
// because the API invocation gets preference
|
||||
reader.read(0, param);
|
||||
assertThrows(SecurityException.class, () -> {
|
||||
reader.read(0, param);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
|
||||
+4
-5
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.wmf;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
@@ -42,6 +39,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* WMFImageReaderTest
|
||||
*
|
||||
@@ -77,14 +76,14 @@ public class WMFImageReaderTest extends ImageReaderAbstractTest<WMFImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Source region reading not supported")
|
||||
@Disabled("Known issue: Source region reading not supported")
|
||||
@Override
|
||||
public void testReadWithSourceRegionParamEqualImage() throws IOException {
|
||||
super.testReadWithSourceRegionParamEqualImage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading not supported")
|
||||
@Disabled("Known issue: Subsampled reading not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" id="red-square" version="1.1">
|
||||
<g id="layer1">
|
||||
<rect id="rect2985" width="100" height="100" x="0" y="0"
|
||||
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg" width="100" height="100" id="red-square" version="1.1">
|
||||
<ns0:g id="layer1">
|
||||
<ns0:rect id="rect2985" width="100" height="100" x="0" y="0"
|
||||
style="color:#000000;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
|
||||
</g>
|
||||
</svg>
|
||||
</ns0:g>
|
||||
</ns0:svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 441 B After Width: | Height: | Size: 465 B |
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>imageio-bmp</artifactId>
|
||||
<name>TwelveMonkeys :: ImageIO :: BMP plugin</name>
|
||||
|
||||
+19
-17
@@ -33,8 +33,8 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
import com.twelvemonkeys.xml.XMLSerializer;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.mockito.InOrder;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -59,8 +59,8 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -204,11 +204,11 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes", rawFound);
|
||||
assertTrue(rawFound, "ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes");
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Known issue: Subsampled reading is currently broken")
|
||||
@Disabled("Known issue: Subsampled reading is currently broken")
|
||||
@Test
|
||||
public void testReadWithSubsampleParamPixelsIndexed8() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
@@ -235,7 +235,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
// TODO: 1. Subsampling is currently broken, should fix it.
|
||||
// 2. BMPs are (normally) stored bottom/up, meaning y subsampling offsets will differ from normal
|
||||
// subsampling of the same data with an offset... Should we deal with this in the reader? Yes?
|
||||
@Ignore("Known issue: Subsampled reading is currently broken")
|
||||
@Disabled("Known issue: Subsampled reading is currently broken")
|
||||
@Test
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
@@ -260,7 +260,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
assertSubsampledImageDataEquals("Subsampled image data does not match expected", image, subsampled, param);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testReadCorruptCausesIIOException() throws IOException {
|
||||
// See https://bugs.openjdk.java.net/browse/JDK-8066904
|
||||
// NullPointerException when calling ImageIO.read(InputStream) with corrupt BMP
|
||||
@@ -268,7 +268,9 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
|
||||
try {
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/broken-bmp/corrupted-bmp.bmp")));
|
||||
reader.read(0);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
reader.read(0);
|
||||
});
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
@@ -331,7 +333,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Ignore this test if not on an Oracle JRE (com.sun...BMPImageReader not available)
|
||||
assumeNoException(e);
|
||||
assumeTrue(false, "Skipping test: BMPImageReaderSpi not available on non-Oracle JREs");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -383,7 +385,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
new XMLSerializer(expected, "UTF-8").serialize(expectedTree, false);
|
||||
new XMLSerializer(actual, "UTF-8").serialize(actualTree, false);
|
||||
|
||||
assertEquals(e.getMessage(), new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8));
|
||||
assertEquals(new String(expected.toByteArray(), StandardCharsets.UTF_8), new String(actual.toByteArray(), StandardCharsets.UTF_8), e.getMessage());
|
||||
|
||||
throw e;
|
||||
}
|
||||
@@ -392,24 +394,24 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
|
||||
private void assertNodeEquals(final String message, final Node expected, final Node actual) {
|
||||
assertEquals(message + " class differs", expected.getClass(), actual.getClass());
|
||||
assertEquals(expected.getClass(), actual.getClass(), message + " class differs");
|
||||
|
||||
if (!excludeEqualValueTest(expected)) {
|
||||
assertEquals(message, expected.getNodeValue(), actual.getNodeValue());
|
||||
assertEquals(expected.getNodeValue(), actual.getNodeValue(), message);
|
||||
|
||||
if (expected instanceof IIOMetadataNode) {
|
||||
IIOMetadataNode expectedIIO = (IIOMetadataNode) expected;
|
||||
IIOMetadataNode actualIIO = (IIOMetadataNode) actual;
|
||||
|
||||
assertEquals(message, expectedIIO.getUserObject(), actualIIO.getUserObject());
|
||||
assertEquals(expectedIIO.getUserObject(), actualIIO.getUserObject(), message);
|
||||
}
|
||||
}
|
||||
|
||||
NodeList expectedChildNodes = expected.getChildNodes();
|
||||
NodeList actualChildNodes = actual.getChildNodes();
|
||||
|
||||
assertTrue(message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes),
|
||||
expectedChildNodes.getLength() <= actualChildNodes.getLength());
|
||||
assertTrue(expectedChildNodes.getLength() <= actualChildNodes.getLength(),
|
||||
message + " child length differs: " + toString(expectedChildNodes) + " != " + toString(actualChildNodes));
|
||||
|
||||
for (int i = 0; i < expectedChildNodes.getLength(); i++) {
|
||||
Node expectedChild = expectedChildNodes.item(i);
|
||||
@@ -423,7 +425,7 @@ public class BMPImageReaderTest extends ImageReaderAbstractTest<BMPImageReader>
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(message + " node name differs", expectedChild.getLocalName(), actualChild.getLocalName());
|
||||
assertEquals(expectedChild.getLocalName(), actualChild.getLocalName(), message + " node name differs");
|
||||
assertNodeEquals(message + "/" + expectedChild.getLocalName(), expectedChild, actualChild);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
@@ -44,7 +41,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CURImageReaderTest
|
||||
@@ -93,16 +92,16 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
||||
if (hotspot != Image.UndefinedProperty || pParam == null) {
|
||||
|
||||
// Typically never happens, because of weirdness with UndefinedProperty
|
||||
assertNotNull("Hotspot for cursor not present", hotspot);
|
||||
assertNotNull(hotspot, "Hotspot for cursor not present");
|
||||
|
||||
// Image weirdness
|
||||
assertNotSame("Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)", Image.UndefinedProperty, hotspot);
|
||||
assertNotSame(Image.UndefinedProperty, hotspot, "Hotspot for cursor undefined (java.awt.Image.UndefinedProperty)");
|
||||
|
||||
assertTrue(String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()), hotspot instanceof Point);
|
||||
assertTrue(hotspot instanceof Point, String.format("Hotspot not a java.awt.Point: %s", hotspot.getClass()));
|
||||
assertEquals(pExpected, hotspot);
|
||||
}
|
||||
|
||||
assertNotNull("Hotspot for cursor not present", reader.getHotSpot(0));
|
||||
assertNotNull(reader.getHotSpot(0), "Hotspot for cursor not present");
|
||||
assertEquals(pExpected, reader.getHotSpot(0));
|
||||
}
|
||||
|
||||
@@ -141,14 +140,14 @@ public class CURImageReaderTest extends ImageReaderAbstractTest<CURImageReader>
|
||||
// TODO: Test cursor is transparent
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue")
|
||||
@Disabled("Known issue")
|
||||
@Override
|
||||
public void testNotBadCaching() throws IOException {
|
||||
super.testNotBadCaching();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading currently not supported")
|
||||
@Disabled("Known issue: Subsampled reading currently not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
+5
-5
@@ -32,9 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
@@ -42,6 +39,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ICOImageReaderTest
|
||||
*
|
||||
@@ -98,14 +98,14 @@ public class ICOImageReaderTest extends ImageReaderAbstractTest<ICOImageReader>
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue")
|
||||
@Disabled("Known issue")
|
||||
@Override
|
||||
public void testNotBadCaching() throws IOException {
|
||||
super.testNotBadCaching();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Known issue: Subsampled reading currently not supported")
|
||||
@Disabled("Known issue: Subsampled reading currently not supported")
|
||||
@Override
|
||||
public void testReadWithSubsampleParamPixels() throws IOException {
|
||||
super.testReadWithSubsampleParamPixels();
|
||||
|
||||
+5
-6
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RLE4DecoderTest {
|
||||
|
||||
@@ -82,8 +81,8 @@ public class RLE4DecoderTest {
|
||||
int r = channel.read(plain);
|
||||
plain.rewind();
|
||||
|
||||
assertEquals("Difference at line " + i, r, d);
|
||||
assertArrayEquals("Difference at line " + i, plain.array(), decoded.array());
|
||||
assertEquals(r, d, "Difference at line " + i);
|
||||
assertArrayEquals(plain.array(), decoded.array(), "Difference at line " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +103,7 @@ public class RLE4DecoderTest {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int expected = plainSream.read();
|
||||
assertEquals("Differs at " + pos, expected, decoded.read());
|
||||
assertEquals(expected, decoded.read(), "Differs at " + pos);
|
||||
|
||||
if (expected < 0) {
|
||||
break;
|
||||
|
||||
+3
-4
@@ -32,7 +32,6 @@ package com.twelvemonkeys.imageio.plugins.bmp;
|
||||
|
||||
import com.twelvemonkeys.io.enc.Decoder;
|
||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -42,8 +41,8 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RLE8DecoderTest {
|
||||
|
||||
@@ -108,7 +107,7 @@ public class RLE8DecoderTest {
|
||||
while (true) {
|
||||
int expected = plainSream.read();
|
||||
|
||||
assertEquals("Differs at " + pos, expected, decoded.read());
|
||||
assertEquals(expected, decoded.read(), "Differs at " + pos);
|
||||
|
||||
if (expected < 0) {
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>imageio-clippath</artifactId>
|
||||
<name>TwelveMonkeys :: ImageIO :: Photoshop Path Support</name>
|
||||
|
||||
+34
-25
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.geom.Path2D;
|
||||
@@ -39,36 +37,39 @@ import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.readExpectedPath;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdobePathBuilderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullBytes() {
|
||||
new AdobePathBuilder((byte[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder((byte[]) null));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new AdobePathBuilder((DataInput) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder((DataInput) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEmpty() {
|
||||
new AdobePathBuilder(new byte[0]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[0]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateShortPath() {
|
||||
new AdobePathBuilder(new byte[3]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[3]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateImpossiblePath() {
|
||||
new AdobePathBuilder(new byte[7]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathBuilder(new byte[7]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,18 +83,20 @@ public class AdobePathBuilderTest {
|
||||
assertNotNull(path);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPath() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD);
|
||||
buffer.putShort((short) 1);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPathToo() throws IOException {
|
||||
byte[] data = new byte[52];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -102,11 +105,13 @@ public class AdobePathBuilderTest {
|
||||
buffer.position(buffer.position() + 22);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testLongPath() throws IOException {
|
||||
byte[] data = new byte[78];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -117,18 +122,22 @@ public class AdobePathBuilderTest {
|
||||
buffer.position(buffer.position() + 24);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testPathMissingLength() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathBuilder(data).path();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+32
-24
@@ -31,7 +31,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -39,36 +38,37 @@ import java.awt.geom.Path2D;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.readExpectedPath;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class AdobePathReaderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNullBytes() {
|
||||
new AdobePathReader((byte[]) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader((byte[]) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new AdobePathReader((DataInput) null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader((DataInput) null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateEmpty() {
|
||||
new AdobePathReader(new byte[0]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[0]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateShortPath() {
|
||||
new AdobePathReader(new byte[3]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[3]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateImpossiblePath() {
|
||||
new AdobePathReader(new byte[7]);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathReader(new byte[7]));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,18 +82,20 @@ public class AdobePathReaderTest {
|
||||
assertNotNull(path);
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPath() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD);
|
||||
buffer.putShort((short) 1);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testShortPathToo() throws IOException {
|
||||
byte[] data = new byte[52];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -102,11 +104,13 @@ public class AdobePathReaderTest {
|
||||
buffer.position(buffer.position() + 22);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testLongPath() throws IOException {
|
||||
byte[] data = new byte[78];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
@@ -117,18 +121,22 @@ public class AdobePathReaderTest {
|
||||
buffer.position(buffer.position() + 24);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testPathMissingLength() throws IOException {
|
||||
byte[] data = new byte[26];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.putShort((short) AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED);
|
||||
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
assertThrows(IIOException.class, () -> {
|
||||
Path2D path = new AdobePathReader(data).readPath();
|
||||
assertNotNull(path);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+54
-55
@@ -30,9 +30,9 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AdobePathSegmentTest.
|
||||
@@ -42,20 +42,19 @@ import static org.junit.Assert.*;
|
||||
* @version $Id: AdobePathSegmentTest.java,v 1.0 13/12/14 harald.kuhr Exp$
|
||||
*/
|
||||
public class AdobePathSegmentTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateBadSelectorNegative() {
|
||||
new AdobePathSegment(-1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(-1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateBadSelector() {
|
||||
new AdobePathSegment(9, 2);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(9, 2));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLengthRecordNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, -1);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,9 +71,9 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(-1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLengthRecordNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, -42);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, -42));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,19 +106,19 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 44));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, -16.1, -16.1, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, -16.1, -16.1, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenLinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 16.1, 16.1, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 16.1, 16.1, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,20 +135,20 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 44));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, -16.5, 0, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, -16.5, 0, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateOpenUnlinkedRecorOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 0, -17, 0, 0, 16.5, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_UNLINKED, 0, -17, 0, 0, 16.5, 1));
|
||||
}
|
||||
|
||||
/// Closed subpath
|
||||
@@ -168,19 +167,19 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 44));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, -16.5, -.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, -16.5, -.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedLinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, .5, 16.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, .5, 16.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,59 +196,59 @@ public class AdobePathSegmentTest {
|
||||
assertEquals(1, segment.cply, 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordBad() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 44);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 44));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordOutOfRangeNegative() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, -.5, -16.5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, -.5, -16.5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateClosedUnlinkedRecordOutOfRangePositive() {
|
||||
new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 16.5, .5, 0, 0, 1, 1);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_UNLINKED, 16.5, .5, 0, 0, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringRule() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.INITIAL_FILL_RULE_RECORD, 0).toString();
|
||||
assertTrue(string, string.startsWith("Rule"));
|
||||
assertTrue(string, string.contains("Initial"));
|
||||
assertTrue(string, string.contains("fill"));
|
||||
assertTrue(string, string.contains("rule=0"));
|
||||
assertTrue(string.startsWith("Rule"), string);
|
||||
assertTrue(string.contains("Initial"), string);
|
||||
assertTrue(string.contains("fill"), string);
|
||||
assertTrue(string.contains("rule=0"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringLength() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_LENGTH_RECORD, 2).toString();
|
||||
assertTrue(string, string.startsWith("Len"));
|
||||
assertTrue(string, string.contains("Closed"));
|
||||
assertTrue(string, string.contains("subpath"));
|
||||
assertTrue(string, string.contains("length=2"));
|
||||
assertTrue(string.startsWith("Len"), string);
|
||||
assertTrue(string.contains("Closed"), string);
|
||||
assertTrue(string.contains("subpath"), string);
|
||||
assertTrue(string.contains("length=2"), string);
|
||||
|
||||
string = new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_LENGTH_RECORD, 42).toString();
|
||||
assertTrue(string, string.startsWith("Len"));
|
||||
assertTrue(string, string.contains("Open"));
|
||||
assertTrue(string, string.contains("subpath"));
|
||||
assertTrue(string, string.contains("length=42"));
|
||||
assertTrue(string.startsWith("Len"), string);
|
||||
assertTrue(string.contains("Open"), string);
|
||||
assertTrue(string.contains("subpath"), string);
|
||||
assertTrue(string.contains("length=42"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringOther() {
|
||||
String string = new AdobePathSegment(AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED, 0, 0, 1, 1, 0, 0).toString();
|
||||
assertTrue(string, string.startsWith("Pt"));
|
||||
assertTrue(string, string.contains("Open"));
|
||||
assertTrue(string, string.contains("Bezier"));
|
||||
assertTrue(string, string.contains("linked"));
|
||||
assertTrue(string.startsWith("Pt"), string);
|
||||
assertTrue(string.contains("Open"), string);
|
||||
assertTrue(string.contains("Bezier"), string);
|
||||
assertTrue(string.contains("linked"), string);
|
||||
|
||||
string = new AdobePathSegment(AdobePathSegment.CLOSED_SUBPATH_BEZIER_LINKED, 0, 0, 1, 1, 0, 0).toString();
|
||||
assertTrue(string, string.startsWith("Pt"));
|
||||
assertTrue(string, string.contains("Closed"));
|
||||
assertTrue(string, string.contains("Bezier"));
|
||||
assertTrue(string, string.contains("linked"));
|
||||
assertTrue(string.startsWith("Pt"), string);
|
||||
assertTrue(string.contains("Closed"), string);
|
||||
assertTrue(string.contains("Bezier"), string);
|
||||
assertTrue(string.contains("linked"), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
-11
@@ -31,7 +31,6 @@
|
||||
package com.twelvemonkeys.imageio.path;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@@ -41,11 +40,11 @@ import java.awt.geom.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.twelvemonkeys.imageio.path.AdobePathSegment.*;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* AdobePathWriterTest.
|
||||
@@ -56,22 +55,22 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class AdobePathWriterTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterNull() {
|
||||
new AdobePathWriter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterInvalid() {
|
||||
new AdobePathWriter(new Path2D.Double(Path2D.WIND_NON_ZERO));
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(new Path2D.Double(Path2D.WIND_NON_ZERO)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateWriterOutOfBounds() {
|
||||
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
|
||||
path.append(new Ellipse2D.Double(.5, 0.5, 2, 2), false);
|
||||
|
||||
new AdobePathWriter(path);
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(path));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,14 +92,14 @@ public class AdobePathWriterTest {
|
||||
new AdobePathWriter(path);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNotClosed() {
|
||||
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
path.moveTo(.5, .5);
|
||||
path.lineTo(1, .5);
|
||||
path.curveTo(1, 1, 1, 1, .5, 1);
|
||||
|
||||
new AdobePathWriter(path).writePath();
|
||||
assertThrows(IllegalArgumentException.class, () -> new AdobePathWriter(path).writePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+18
-18
@@ -33,7 +33,6 @@ package com.twelvemonkeys.imageio.path;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
@@ -48,8 +47,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* PathsTest.
|
||||
@@ -63,9 +63,9 @@ public class PathsTest {
|
||||
IIORegistry.getDefaultInstance().registerServiceProvider(new URLImageInputStreamSpi());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadPathNull() throws IOException {
|
||||
Paths.readPath(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.readPath(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,14 +127,14 @@ public class PathsTest {
|
||||
assertPathEquals(readExpectedPath("/ser/grape-path.ser"), path);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullPath() {
|
||||
Paths.applyClippingPath(null, new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY));
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(null, new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullSource() {
|
||||
Paths.applyClippingPath(new GeneralPath(), null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(new GeneralPath(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,9 +165,9 @@ public class PathsTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testApplyClippingPathNullDestination() {
|
||||
Paths.applyClippingPath(new GeneralPath(), new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY), null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.applyClippingPath(new GeneralPath(), new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,9 +199,9 @@ public class PathsTest {
|
||||
// TODO: Mor sophisticated test that tests all pixels outside path...
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadClippedNull() throws IOException {
|
||||
Paths.readClipped(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> Paths.readClipped(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,7 +243,7 @@ public class PathsTest {
|
||||
}
|
||||
|
||||
static void assertPathEquals(final Path2D expectedPath, final Path2D actualPath) {
|
||||
assertNotNull("Expected path is null, check your tests...", expectedPath);
|
||||
assertNotNull(expectedPath, "Expected path is null, check your tests...");
|
||||
assertNotNull(actualPath);
|
||||
|
||||
PathIterator expectedIterator = expectedPath.getPathIterator(null);
|
||||
@@ -253,19 +253,19 @@ public class PathsTest {
|
||||
float[] actualCoords = new float[6];
|
||||
|
||||
while(!expectedIterator.isDone()) {
|
||||
assertFalse("Less points than expected", actualIterator.isDone());
|
||||
assertFalse(actualIterator.isDone(), "Less points than expected");
|
||||
|
||||
int expectedType = expectedIterator.currentSegment(expectedCoords);
|
||||
int actualType = actualIterator.currentSegment(actualCoords);
|
||||
|
||||
assertEquals("Unexpected segment type", expectedType, actualType);
|
||||
assertArrayEquals("Unexpected coordinates", expectedCoords, actualCoords, 0);
|
||||
assertEquals( expectedType, actualType, "Unexpected segment type");
|
||||
assertArrayEquals(expectedCoords, actualCoords, 0, "Unexpected coordinates");
|
||||
|
||||
actualIterator.next();
|
||||
expectedIterator.next();
|
||||
}
|
||||
|
||||
assertTrue("More points than expected", actualIterator.isDone());
|
||||
assertTrue( actualIterator.isDone(), "More points than expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio</artifactId>
|
||||
<version>3.11.0-SNAPSHOT</version>
|
||||
<version>3.13.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>imageio-core</artifactId>
|
||||
<name>TwelveMonkeys :: ImageIO :: Core</name>
|
||||
|
||||
+2
-2
@@ -37,14 +37,14 @@ import java.io.IOException;
|
||||
import static com.twelvemonkeys.lang.Validate.notNull;
|
||||
|
||||
/**
|
||||
* ImageInputStream that writes through a delegate, but keeps local position and bit offset.
|
||||
* ImageOutputStream that writes through a delegate, but keeps local position and bit offset.
|
||||
* Note: Flushing or closing this stream will *not* have an effect on the delegate.
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: harald.kuhr$
|
||||
* @version $Id: SubImageOutputStream.java,v 1.0 30/03/15 harald.kuhr Exp$
|
||||
*/
|
||||
public class SubImageOutputStream extends ImageOutputStreamImpl {
|
||||
public final class SubImageOutputStream extends ImageOutputStreamImpl {
|
||||
private final ImageOutputStream stream;
|
||||
private final long startPos;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import javax.imageio.spi.ServiceRegistry;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -232,6 +232,10 @@ public final class IIOUtil {
|
||||
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
|
||||
// Period == 1 is a no-op...
|
||||
if (samplePeriod == 1) {
|
||||
if (srcRow != destRow) {
|
||||
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,6 +279,10 @@ public final class IIOUtil {
|
||||
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
|
||||
// Period == 1 is a no-op...
|
||||
if (samplePeriod == 1) {
|
||||
if (srcRow != destRow) {
|
||||
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -283,7 +291,7 @@ public final class IIOUtil {
|
||||
"bitsPerSample must be > 0 and <= 16 and a power of 2");
|
||||
Validate.isTrue(samplesPerPixel > 0, "samplesPerPixel must be > 0");
|
||||
Validate.isTrue(samplesPerPixel * bitsPerSample <= 16 || samplesPerPixel * bitsPerSample % 16 == 0,
|
||||
"samplesPerPixel * bitsPerSample must be < 16 or a multiple of 16 ");
|
||||
"samplesPerPixel * bitsPerSample must be < 16 or a multiple of 16");
|
||||
|
||||
int pixelStride = bitsPerSample * samplesPerPixel / 16;
|
||||
for (int x = 0; x < srcWidth * pixelStride; x += samplePeriod * pixelStride) {
|
||||
@@ -297,6 +305,10 @@ public final class IIOUtil {
|
||||
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
|
||||
// Period == 1 is a no-op...
|
||||
if (samplePeriod == 1) {
|
||||
if (srcRow != destRow) {
|
||||
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -305,7 +317,7 @@ public final class IIOUtil {
|
||||
"bitsPerSample must be > 0 and <= 32 and a power of 2");
|
||||
Validate.isTrue(samplesPerPixel > 0, "samplesPerPixel must be > 0");
|
||||
Validate.isTrue(samplesPerPixel * bitsPerSample <= 32 || samplesPerPixel * bitsPerSample % 32 == 0,
|
||||
"samplesPerPixel * bitsPerSample must be < 32 or a multiple of 32 ");
|
||||
"samplesPerPixel * bitsPerSample must be < 32 or a multiple of 32");
|
||||
|
||||
int pixelStride = bitsPerSample * samplesPerPixel / 32;
|
||||
for (int x = 0; x < srcWidth * pixelStride; x += samplePeriod * pixelStride) {
|
||||
@@ -322,7 +334,7 @@ public final class IIOUtil {
|
||||
"bitsPerSample must be > 0 and <= 32 and a power of 2");
|
||||
Validate.isTrue(samplesPerPixel > 0, "samplesPerPixel must be > 0");
|
||||
Validate.isTrue(samplesPerPixel * bitsPerSample <= 32 || samplesPerPixel * bitsPerSample % 32 == 0,
|
||||
"samplesPerPixel * bitsPerSample must be < 32 or a multiple of 32 ");
|
||||
"samplesPerPixel * bitsPerSample must be < 32 or a multiple of 32");
|
||||
|
||||
int pixelStride = bitsPerSample * samplesPerPixel / 32;
|
||||
for (int x = 0; x < srcWidth * pixelStride; x += samplePeriod * pixelStride) {
|
||||
@@ -330,4 +342,21 @@ public final class IIOUtil {
|
||||
System.arraycopy(srcRow, srcPos + x, destRow, destPos + x / samplePeriod, pixelStride);
|
||||
}
|
||||
}
|
||||
|
||||
public static void subsampleRow(double[] srcRow, int srcPos, int srcWidth,
|
||||
double[] destRow, int destPos,
|
||||
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
|
||||
Validate.isTrue(samplePeriod > 1, "samplePeriod must be > 1"); // Period == 1 could be a no-op...
|
||||
Validate.isTrue(bitsPerSample > 0 && bitsPerSample <= 64 && (bitsPerSample == 1 || bitsPerSample % 2 == 0),
|
||||
"bitsPerSample must be > 0 and <= 64 and a power of 2");
|
||||
Validate.isTrue(samplesPerPixel > 0, "samplesPerPixel must be > 0");
|
||||
Validate.isTrue(samplesPerPixel * bitsPerSample <= 64 || samplesPerPixel * bitsPerSample % 64 == 0,
|
||||
"samplesPerPixel * bitsPerSample must be < 64 or a multiple of 64");
|
||||
|
||||
int pixelStride = bitsPerSample * samplesPerPixel / 64;
|
||||
for (int x = 0; x < srcWidth * pixelStride; x += samplePeriod * pixelStride) {
|
||||
// System.arraycopy should be intrinsic, but consider using direct array access for pixelStride == 1
|
||||
System.arraycopy(srcRow, srcPos + x, destRow, destPos + x / samplePeriod, pixelStride);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-29
@@ -30,11 +30,9 @@
|
||||
|
||||
package com.twelvemonkeys.imageio;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.awt.*;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -48,7 +46,7 @@ import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ImageReaderBaseTest
|
||||
@@ -64,36 +62,36 @@ public class ImageReaderBaseTest {
|
||||
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB)
|
||||
);
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationZeroWidth() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 0, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 0, 42));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNegativeWidth() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), -1, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), -1, 42));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationZeroHeight() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 42, 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 42, 0));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNegativeHeight() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 42, -1);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 42, -1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNullTypes() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, null, 42, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, null, 42, 42));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetDestinationNoTypes() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, Collections.<ImageTypeSpecifier>emptyList().iterator(), 42, 42);
|
||||
assertThrows(IllegalArgumentException.class, () -> ImageReaderBase.getDestination(null, Collections.<ImageTypeSpecifier>emptyList().iterator(), 42, 42));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,11 +160,11 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(1, destination.getHeight());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestination() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestination(new BufferedImage(21, 1, BufferedImage.TYPE_USHORT_565_RGB));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 42, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,18 +189,18 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(7, destination.getHeight());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestinationType() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7));
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamIllegalDestinationTypeAlt() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_BGR));
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7);
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,22 +213,22 @@ public class ImageReaderBaseTest {
|
||||
assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType());
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationParamDestinationExceedsIntegerMax() throws IIOException {
|
||||
ImageReadParam param = new ImageReadParam();
|
||||
param.setSourceRegion(new Rectangle(3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE)); // 6 442 057 734 pixels
|
||||
ImageReaderBase.getDestination(param, TYPES.iterator(), 6 * Short.MAX_VALUE, 4 * Short.MAX_VALUE); // 25 768 230 936 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(param, TYPES.iterator(), 6 * Short.MAX_VALUE, 4 * Short.MAX_VALUE)); // 25 768 230 936 pixels
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationDimensionExceedsIntegerMax() throws IIOException {
|
||||
ImageReaderBase.getDestination(null, TYPES.iterator(), 3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE); // 6 442 057 734 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(null, TYPES.iterator(), 3 * Short.MAX_VALUE, 2 * Short.MAX_VALUE)); // 6 442 057 734 pixels
|
||||
}
|
||||
|
||||
@Test(expected = IIOException.class)
|
||||
@Test
|
||||
public void testGetDestinationStorageExceedsIntegerMax() throws IIOException {
|
||||
Set<ImageTypeSpecifier> byteTypes = singleton(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR));
|
||||
ImageReaderBase.getDestination(null, byteTypes.iterator(), Short.MAX_VALUE, Short.MAX_VALUE); // 1 073 676 289 pixels
|
||||
assertThrows(IIOException.class, () -> ImageReaderBase.getDestination(null, byteTypes.iterator(), Short.MAX_VALUE, Short.MAX_VALUE)); // 1 073 676 289 pixels
|
||||
// => 3 221 028 867 bytes needed in continuous array, not possible
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -7,9 +7,9 @@ import com.twelvemonkeys.imageio.StandardImageMetadataSupport.SubimageInterpreta
|
||||
import com.twelvemonkeys.imageio.StandardImageMetadataSupport.TextEntry;
|
||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import java.awt.image.*;
|
||||
@@ -23,22 +23,23 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.twelvemonkeys.imageio.StandardImageMetadataSupport.builder;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class StandardImageMetadataSupportTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNullBuilder() {
|
||||
new StandardImageMetadataSupport(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new StandardImageMetadataSupport(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void createNullType() {
|
||||
new StandardImageMetadataSupport(builder(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> new StandardImageMetadataSupport(builder(null)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void builderNullType() {
|
||||
builder(null).build();
|
||||
assertThrows(IllegalArgumentException.class, () -> builder(null).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,10 +90,10 @@ public class StandardImageMetadataSupportTest {
|
||||
assertEquals("TRUE", compressionLossless.getAttribute("value"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void withCompressionLossyIllegal() {
|
||||
builder(ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY))
|
||||
.withCompressionLossless(false);
|
||||
assertThrows(IllegalArgumentException.class, () -> builder(ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY))
|
||||
.withCompressionLossless(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -31,9 +31,9 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import com.twelvemonkeys.imageio.color.CIELabColorConverter.Illuminant;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* CIELabColorConverterTest.
|
||||
@@ -43,9 +43,9 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
* @version $Id: CIELabColorConverterTest.java,v 1.0 22/10/15 harald.kuhr Exp$
|
||||
*/
|
||||
public class CIELabColorConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNoIllumninant() {
|
||||
new CIELabColorConverter(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new CIELabColorConverter(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+38
-39
@@ -1,7 +1,5 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
@@ -9,7 +7,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ColorProfilesTest {
|
||||
@Test
|
||||
@@ -53,9 +52,9 @@ public class ColorProfilesTest {
|
||||
assertFalse(ColorProfiles.isCS_sRGB(ICC_Profile.getInstance(ColorSpace.CS_PYCC)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_sRGBNull() {
|
||||
ColorProfiles.isCS_sRGB(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.isCS_sRGB(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,29 +70,29 @@ public class ColorProfilesTest {
|
||||
assertFalse(ColorProfiles.isCS_GRAY(ICC_Profile.getInstance(ColorSpace.CS_PYCC)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_GRAYNull() {
|
||||
ColorProfiles.isCS_GRAY(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.isCS_GRAY(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileNull() {
|
||||
ColorProfiles.createProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileNull() throws IOException {
|
||||
ColorProfiles.readProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawNull() {
|
||||
ColorProfiles.createProfileRaw(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawNull() throws IOException {
|
||||
ColorProfiles.readProfileRaw(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,74 +109,74 @@ public class ColorProfilesTest {
|
||||
assertArrayEquals(data, profileRaw.getData());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawBadData() {
|
||||
ColorProfiles.createProfileRaw(new byte[5]);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(new byte[5]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawBadData() throws IOException {
|
||||
// NOTE: The array here is larger, as there's a bug in OpenJDK 15 & 16, that throws
|
||||
// ArrayIndexOutOfBoundsException if the stream is shorter than the profile signature...
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(new byte[40]));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(new byte[40])));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileBadData() {
|
||||
ColorProfiles.createProfile(new byte[5]);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(new byte[5]));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileBadData() throws IOException {
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(new byte[5]));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(new byte[5])));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfileRaw(Arrays.copyOf(data, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(Arrays.copyOf(data, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfile(Arrays.copyOf(data, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(Arrays.copyOf(data, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileTruncated() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 200));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 200)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileRawTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfileRaw(Arrays.copyOf(data, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfileRaw(Arrays.copyOf(data, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileRawTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfileRaw(new ByteArrayInputStream(data, 0, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateProfileTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.createProfile(Arrays.copyOf(data, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.createProfile(Arrays.copyOf(data, 125)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testReadProfileTruncatedHeader() throws IOException {
|
||||
byte[] data = ICC_Profile.getInstance(getClass().getResourceAsStream("/profiles/adobe_rgb_1998.icc")).getData();
|
||||
ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 125));
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorProfiles.readProfile(new ByteArrayInputStream(data, 0, 125)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-7
@@ -30,15 +30,16 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
/**
|
||||
* ColorSpacesTest
|
||||
@@ -154,9 +155,9 @@ public class ColorSpacesTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_sRGBNull() {
|
||||
ColorSpaces.isCS_sRGB(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorSpaces.isCS_sRGB(null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -175,9 +176,9 @@ public class ColorSpacesTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testIsCS_GRAYNull() {
|
||||
ColorSpaces.isCS_GRAY(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> ColorSpaces.isCS_GRAY(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-7
@@ -31,21 +31,20 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.image.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class DiscreteAlphaIndexColorModelTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateNull() {
|
||||
new DiscreteAlphaIndexColorModel(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new DiscreteAlphaIndexColorModel(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,7 +201,7 @@ public class DiscreteAlphaIndexColorModelTest {
|
||||
assertEquals(2, raster.getHeight());
|
||||
|
||||
assertTrue(colorModel.isCompatibleRaster(raster));
|
||||
assertThat(raster, CoreMatchers.is(WritableRaster.class)); // Specific subclasses are in sun.awt package
|
||||
assertThat(raster, instanceOf(WritableRaster.class)); // Checks if raster is an instance of WritableRaster or its subclass
|
||||
assertThat(raster.getTransferType(), CoreMatchers.equalTo(DataBuffer.TYPE_BYTE));
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -30,8 +30,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
@@ -39,16 +37,18 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class KCMSSanitizerStrategyTest {
|
||||
private static final byte[] XYZ = new byte[] {'X', 'Y', 'Z', ' '};
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testFixProfileNullProfile() throws Exception {
|
||||
new KCMSSanitizerStrategy().fixProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new KCMSSanitizerStrategy().fixProfile(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +77,7 @@ public class KCMSSanitizerStrategyTest {
|
||||
try {
|
||||
Method isSealed = Class.class.getMethod("isSealed");
|
||||
Boolean result = (Boolean) isSealed.invoke(ICC_Profile.class);
|
||||
assumeFalse("Can't mock ICC_Profile, class is sealed (as of JDK 19).", result);
|
||||
assumeFalse(result, "Can't mock ICC_Profile, class is sealed (as of JDK 19).");
|
||||
}
|
||||
catch (ReflectiveOperationException ignore) {
|
||||
// We can't have sealed classes if we don't have the isSealed method...
|
||||
|
||||
+4
-4
@@ -30,19 +30,19 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.awt.color.ICC_Profile;
|
||||
|
||||
import static com.twelvemonkeys.imageio.color.KCMSSanitizerStrategyTest.assumeICC_ProfileNotSealed;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
public class LCMSSanitizerStrategyTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testFixProfileNullProfile() throws Exception {
|
||||
new LCMSSanitizerStrategy().fixProfile(null);
|
||||
assertThrows(IllegalArgumentException.class, () -> new LCMSSanitizerStrategy().fixProfile(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.twelvemonkeys.imageio.color;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.imageio.spi.ImageInputStreamSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user