Skip to content

Commit

Permalink
Add testing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dlazaro66 committed Feb 11, 2017
1 parent 6d87907 commit a6be167
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions qrcodereaderview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ android {

dependencies {
compile 'com.google.zxing:core:3.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.5'
testCompile "org.robolectric:robolectric:3.2.2"
}

install {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.dlazaro66.qrcodereaderview;

import android.graphics.Point;
import android.graphics.PointF;

import com.google.zxing.ResultPoint;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
public class QRToViewPointTransformerShould {

private QRToViewPointTransformer qrToViewPointTransformer;

@Before
public void setUp() throws Exception {
qrToViewPointTransformer = new QRToViewPointTransformer();
}

@After
public void tearDown() throws Exception {

}

@Test
public void transformPortraitNotMirrorQRPointToViewPoint() throws Exception {
ResultPoint qrPoint = new ResultPoint(100, 50);
boolean isMirrorPreview = false;
Orientation orientation = Orientation.PORTRAIT;
Point viewSize = new Point(100, 200);
Point cameraPreviewSize = new Point(200, 100);

PointF result = qrToViewPointTransformer.transform(qrPoint, isMirrorPreview, orientation,
viewSize, cameraPreviewSize);

assertEquals(result.x, 50, 0.0f);
assertEquals(result.y, 100, 0.0f);
}

@Test
public void transformPortraitMirrorQRPointToViewPoint() throws Exception {
ResultPoint qrPoint = new ResultPoint(0, 0);
boolean isMirrorPreview = true;
Orientation orientation = Orientation.PORTRAIT;
Point viewSize = new Point(100, 200);
Point cameraPreviewSize = new Point(200, 100);

PointF result = qrToViewPointTransformer.transform(qrPoint, isMirrorPreview, orientation,
viewSize, cameraPreviewSize);

assertEquals(result.x, 100, 0.0f);
assertEquals(result.y, 200, 0.0f);
}

@Test
public void transformLandscapeNotMirrorQRPointToViewPoint() throws Exception {
ResultPoint qrPoint = new ResultPoint(100, 50);
boolean isMirrorPreview = false;
Orientation orientation = Orientation.LANDSCAPE;
Point viewSize = new Point(200, 100);
Point cameraPreviewSize = new Point(200, 100);

PointF result = qrToViewPointTransformer.transform(qrPoint, isMirrorPreview, orientation,
viewSize, cameraPreviewSize);

assertEquals(result.x, 100, 0.0f);
assertEquals(result.y, 50, 0.0f);
}

@Test
public void transformLandscapeMirrorQRPointToViewPoint() throws Exception {
ResultPoint qrPoint = new ResultPoint(0, 0);
boolean isMirrorPreview = true;
Orientation orientation = Orientation.LANDSCAPE;
Point viewSize = new Point(200, 100);
Point cameraPreviewSize = new Point(200, 100);

PointF result = qrToViewPointTransformer.transform(qrPoint, isMirrorPreview, orientation,
viewSize, cameraPreviewSize);

assertEquals(result.x, 0, 0.0f);
assertEquals(result.y, 100, 0.0f);
}
}

0 comments on commit a6be167

Please sign in to comment.