From 1f1d99b50321fbf7d3f1bb5cce55d31bf7c86859 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 13 Sep 2023 20:26:38 +0100 Subject: [PATCH] JAL-4274 Tests for BIS defaults and overrides --- test/jalview/util/ImageMakerTest.java | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 test/jalview/util/ImageMakerTest.java diff --git a/test/jalview/util/ImageMakerTest.java b/test/jalview/util/ImageMakerTest.java new file mode 100644 index 0000000..acb4160 --- /dev/null +++ b/test/jalview/util/ImageMakerTest.java @@ -0,0 +1,102 @@ +package jalview.util; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import jalview.bin.Cache; +import jalview.util.imagemaker.BitmapImageSizing; + +public class ImageMakerTest +{ + @Test(groups = { "Functional" }) + public void testParseScaleWidthHeightStrings() + { + Cache.setPropsAreReadOnly(true); + Cache.loadProperties("test/jalview/bin/testProps.jvprops"); + + Cache.removeProperty(BitmapImageSizing.BITMAP_SCALE); + Cache.removeProperty(BitmapImageSizing.BITMAP_HEIGHT); + Cache.removeProperty(BitmapImageSizing.BITMAP_WIDTH); + + BitmapImageSizing bis = null; + + bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4"); + Assert.assertEquals(bis.scale(), 1.2f, + "scale not parsed and set to value given"); + Assert.assertEquals(bis.width(), 3, + "width not parsed and set to value given"); + Assert.assertEquals(bis.height(), 4, + "height not parsed and set to value given"); + + bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null); + Assert.assertEquals(bis.scale(), 1.2f, + "scale not parsed and set to value given"); + Assert.assertEquals(bis.width(), 0, "width not parsed and set to 0"); + Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0"); + + bis = ImageMaker.parseScaleWidthHeightStrings(null, "1", null); + Assert.assertEquals(bis.scale(), 0f, "scale not parsed and set to 0f"); + Assert.assertEquals(bis.width(), 1, + "width not parsed and set to value given"); + Assert.assertEquals(bis.height(), 0, "height not parsed and set to 0"); + + // this should set bis to the dynamic defaultBitmapImageSizing + bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null); + Assert.assertEquals(bis.scale(), 0f, + "scale not parsed and set to undefined default 0f"); + Assert.assertEquals(bis.width(), 0, + "width not parsed and set to undefined default 0"); + Assert.assertEquals(bis.height(), 0, + "height not parsed and set to undefined default 0"); + + Cache.setProperty(BitmapImageSizing.BITMAP_HEIGHT, "1"); + Assert.assertEquals(bis.scale(), 0f, + "scale not parsed and set to undefined default 0f"); + Assert.assertEquals(bis.width(), 0, + "width not parsed and set to undefined default 0"); + Assert.assertEquals(bis.height(), 1, + "height not parsed and set to default 1"); + + Cache.setProperty(BitmapImageSizing.BITMAP_SCALE, "3.4"); + Cache.setProperty(BitmapImageSizing.BITMAP_WIDTH, "2"); + Assert.assertEquals(bis.scale(), 3.4f, + "scale not parsed and set to undefined default 3.2f"); + Assert.assertEquals(bis.width(), 2, + "width not parsed and set to undefined default 2"); + Assert.assertEquals(bis.height(), 1, + "height not parsed and set to default 1"); + + // override actual default values + bis = ImageMaker.parseScaleWidthHeightStrings("1.2", "3", "4"); + Assert.assertEquals(bis.scale(), 1.2f, + "scale not parsed and set to value given"); + Assert.assertEquals(bis.width(), 3, + "width not parsed and set to value given"); + Assert.assertEquals(bis.height(), 4, + "height not parsed and set to value given"); + + bis = ImageMaker.parseScaleWidthHeightStrings("1.2", null, null); + Assert.assertEquals(bis.scale(), 1.2f, + "scale not parsed and set to value given"); + Assert.assertEquals(bis.width(), 0, + "width not parsed and set to undefined 0"); + Assert.assertEquals(bis.height(), 0, + "height not parsed and set to undefined 0"); + + bis = ImageMaker.parseScaleWidthHeightStrings(null, null, "5"); + Assert.assertEquals(bis.scale(), 0f, + "scale not parsed and set to undefined 0f"); + Assert.assertEquals(bis.width(), 0, + "width not parsed and set to undefined 0"); + Assert.assertEquals(bis.height(), 5, + "height not parsed and set to value given"); + + bis = ImageMaker.parseScaleWidthHeightStrings(null, null, null); + Assert.assertEquals(bis.scale(), 3.4f, + "scale not parsed and set to undefined default 3.2f"); + Assert.assertEquals(bis.width(), 2, + "width not parsed and set to undefined default 2"); + Assert.assertEquals(bis.height(), 1, + "height not parsed and set to default 1"); + } +} -- 1.7.10.2